You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ce...@apache.org on 2002/12/27 12:02:54 UTC
cvs commit: jakarta-struts/src/test/org/apache/struts/tiles/config tiles-defs.xml
cedric 2002/12/27 03:02:54
Added: src/test/org/apache/struts/tiles TestTilesPlugin.java
src/test/org/apache/struts/tiles/config tiles-defs.xml
Log:
Test suite for tiles.
Revision Changes Path
1.1 jakarta-struts/src/test/org/apache/struts/tiles/TestTilesPlugin.java
Index: TestTilesPlugin.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/tiles/TestTilesPlugin.java,v 1.1 2002/12/27 11:02:54 cedric Exp $
* $Revision: 1.1 $
* $Date: 2002/12/27 11:02:54 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.tiles;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import javax.servlet.ServletConfig;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.struts.Globals;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.RequestProcessor;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ApplicationConfig;
import org.apache.struts.mock.TestMockBase;
import org.apache.struts.mock.MockActionServlet;
import org.apache.struts.config.ModuleConfigFactory;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.PlugInConfig;
import org.apache.struts.util.RequestUtils;
import org.apache.commons.beanutils.BeanUtils;
/**
* <p>Unit tests for <code>org.apache.struts.tiles.*</code>.</p>
*
* @author Cedric Dumoulin
* @version $Revision: 1.1 $ $Date: 2002/12/27 11:02:54 $
*/
public class TestTilesPlugin extends TestMockBase {
protected ModuleConfig module1;
protected ModuleConfig module2;
protected MockActionServlet actionServlet;
// ----------------------------------------------------------------- Basics
public TestTilesPlugin(String name) {
super(name);
}
public static void main(String args[]) {
junit.awtui.TestRunner.main
(new String[] { TestTilesPlugin.class.getName() } );
}
public static Test suite() {
return (new TestSuite(TestTilesPlugin.class));
}
// ----------------------------------------------------- Instance Variables
// ----------------------------------------------------- Setup and Teardown
public void setUp()
{
super.setUp();
TilesUtil.testReset();
actionServlet = new MockActionServlet(context, config);
}
public void tearDown() {
super.tearDown();
}
// ------------------------------------------------------- Individual Tests
/**
* Create a module configuration
* @param moduleName
*/
public ModuleConfig createModuleConfig( String moduleName, String configFileName, boolean moduleAware )
{
ModuleConfig moduleConfig = ModuleConfigFactory.createFactory().createModuleConfig(moduleName);
context.setAttribute(Action.APPLICATION_KEY + moduleName, moduleConfig);
// Set tiles plugin
PlugInConfig pluginConfig = new PlugInConfig();
pluginConfig.setClassName( "org.apache.struts.tiles.TilesPlugin" );
pluginConfig.addProperty( "moduleAware", (moduleAware==true?"true":"false") );
pluginConfig.addProperty( "definitions-config", "/org/apache/struts/tiles/config/" + configFileName );
moduleConfig.addPlugInConfig( pluginConfig );
return moduleConfig;
}
/**
* Fake call to init module plugins
* @param config
*/
public void initModulePlugIns( ModuleConfig moduleConfig)
{
PlugInConfig plugInConfigs[] = moduleConfig.findPlugInConfigs();
PlugIn plugIns[] = new PlugIn[plugInConfigs.length];
context.setAttribute(Globals.PLUG_INS_KEY + moduleConfig.getPrefix(), plugIns);
for (int i = 0; i < plugIns.length; i++) {
try {
plugIns[i] =
(PlugIn)RequestUtils.applicationInstance(plugInConfigs[i].getClassName());
BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties());
// Pass the current plugIn config object to the PlugIn.
// The property is set only if the plugin declares it.
// This plugin config object is needed by Tiles
BeanUtils.copyProperty( plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]);
plugIns[i].init(actionServlet, moduleConfig);
} catch (ServletException e) {
// Lets propagate
e.printStackTrace();
//throw e;
} catch (Exception e) {
e.printStackTrace();
//throw e;
}
}
}
// ---------------------------------------------------------- absoluteURL()
/**
* Test multi factory creation when moduleAware=true.
*/
public void testMultiFactory()
{
// init TilesPlugin
module1 = createModuleConfig( "/module1", "tiles-defs.xml", true );
module2 = createModuleConfig( "/module2", "tiles-defs.xml", true );
initModulePlugIns(module1);
initModulePlugIns(module2);
// mock request context
request.setAttribute(Action.APPLICATION_KEY, module1);
request.setPathElements("/myapp", "/module1/foo.do", null, null);
// Retrieve factory for module1
DefinitionsFactory factory1 = TilesUtil.getDefinitionsFactory( request, context);
assertNotNull( "factory found", factory1);
assertEquals( "factory name", "/module1", factory1.getConfig().getFactoryName() );
// mock request context
request.setAttribute(Action.APPLICATION_KEY, module2);
request.setPathElements("/myapp", "/module2/foo.do", null, null);
// Retrieve factory for module2
DefinitionsFactory factory2 = TilesUtil.getDefinitionsFactory( request, context);
assertNotNull( "factory found", factory2);
assertEquals( "factory name", "/module2", factory2.getConfig().getFactoryName() );
// Check that factory are different
assertNotSame("Factory from different modules", factory1, factory2);
}
/**
* Test single factory creation when moduleAware=false.
*/
public void testSingleSharedFactory()
{
// init TilesPlugin
module1 = createModuleConfig( "/module1", "tiles-defs.xml", false );
module2 = createModuleConfig( "/module2", "tiles-defs.xml", false );
initModulePlugIns(module1);
initModulePlugIns(module2);
// mock request context
request.setAttribute(Action.APPLICATION_KEY, module1);
request.setPathElements("/myapp", "/module1/foo.do", null, null);
// Retrieve factory for module1
DefinitionsFactory factory1 = TilesUtil.getDefinitionsFactory( request, context);
assertNotNull( "factory found", factory1);
assertEquals( "factory name", "/module1", factory1.getConfig().getFactoryName() );
// mock request context
request.setAttribute(Action.APPLICATION_KEY, module2);
request.setPathElements("/myapp", "/module2/foo.do", null, null);
// Retrieve factory for module2
DefinitionsFactory factory2 = TilesUtil.getDefinitionsFactory( request, context);
assertNotNull( "factory found", factory2);
assertEquals( "factory name", "/module1", factory2.getConfig().getFactoryName() );
// Check that factory are different
assertEquals("Same factory", factory1, factory2);
}
}
1.1 jakarta-struts/src/test/org/apache/struts/tiles/config/tiles-defs.xml
Index: tiles-defs.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
<!-- Definitions for Tiles documentation -->
<tiles-definitions>
<!-- ======================================================= -->
<!-- Master definition -->
<!-- ======================================================= -->
<!-- Doc index page description -->
<definition name="doc.mainLayout" path="/layout/classicLayout.jsp">
<put name="title" value="Tiles Library Documentation" />
<put name="header" value="/common/header.jsp" />
<put name="menu" value="doc.menu.main" />
<put name="footer" value="/common/footer.jsp" />
<put name="body" value="doc.portal.body" />
</definition>
<!-- ======================================================= -->
<!-- Main page body definitions -->
<!-- ======================================================= -->
<definition name="doc.portal.body" path="/layout/columnsLayout.jsp">
<put name="numCols" value="2" />
<putList name="list0" >
<add value="/doc/portal/welcome.jsp" />
<add value="/doc/portal/features.jsp" />
<!--<add value="/doc/portal/todo.jsp" /> -->
<add value="/doc/portal/documentation.jsp" />
</putList>
<putList name="list1" >
<add value="/doc/portal/news.jsp" />
<add value="/doc/portal/download.jsp" />
<add value="/doc/portal/tilesCompsTemplates.jsp" />
<add value="/doc/portal/strutsIntegration.jsp" />
<add value="/doc/portal/comments.jsp" />
<add value="/doc/portal/revisions.jsp" />
</putList>
</definition>
<!-- ======================================================= -->
<!-- Menus definitions -->
<!-- ======================================================= -->
<!-- Menu bar definition -->
<definition name="doc.menu.main" path="/layout/vboxLayout.jsp" >
<putList name="componentsList" >
<add value="doc.menu.links" />
<add value="doc.menu.taglib.references" />
<add value="doc.menu.printer.friendly" />
<add value="doc.menu.old.documents" />
</putList>
</definition>
<!-- Documentation menu definition v1.1-->
<definition name="doc.menu.links" path="/layouts/menu.jsp" >
<put name="title" value="Documentation" />
<putList name="items" >
<item value="Home" link="/index.jsp" />
<item value="Live Examples (new)" link="/examples/index.jsp" />
<!--
<item> <value>Commented Examples</value>
<link>/examples/index.jsp</link>
<classtype>org.apache.struts.tiles.beans.SimpleMenuItem</classtype>
</item>
-->
<item value="Quick overview" link="/doc/quickOverview.jsp" />
<item value="Tutorial" link="/doc/tutorial.jsp" />
<item value="Tutorial Live Examples" link="/tutorial/index.jsp" />
<item value="Download" link="/doc/download.jsp" />
<item value="Installation" link="/doc/installation.jsp" />
<item value="User Guide" link="/doc/userGuide.jsp" />
<item value="Javadoc" link="/api/index.html" />
<item value="Struts Home" link="http://www.apache.org" icon="/images/struts-power.gif"
classtype="org.apache.struts.tiles.beans.SimpleMenuItem" />
</putList>
</definition>
<!-- Printer friendly menu definition -->
<definition name="doc.menu.printer.friendly" path="/layouts/menu.jsp" >
<put name="title" value="Printer Versions" />
<putList name="items" >
<item value="Quick Overview" link="/test/testAll.jsp" />
<item value="Tutorial" link="/doc/tutorialBody.html" />
<item value="User Guide" link="/doc/userGuideBody.html" />
<item value="Overview (old)" link="/doc/overviewBody.html" />
</putList>
</definition>
<!-- Taglib menu definition -->
<definition name="doc.menu.taglib.references" path="/layouts/menu.jsp" >
<put name="title" value="Tag Library Reference" />
<putList name="items" >
<item value="Tiles Tags" link="/doc/tilesTags.jsp" />
<!-- <item value="Extension Tags (old)" link="/doc/extensionsTags.jsp" /> -->
</putList>
</definition>
<!-- Oldies menu definition -->
<definition name="doc.menu.old.documents" path="/layouts/menu.jsp" >
<put name="title" value="Old Documents" />
<putList name="items" >
<item value="Overview (old)" link="/doc/overview.jsp" />
</putList>
</definition>
</tiles-definitions>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>