You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2009/10/25 20:01:12 UTC
svn commit: r829630 [1/2] - in /tiles/sandbox/trunk/tiles3:
tiles-core/src/main/java/org/apache/tiles/context/
tiles-core/src/main/java/org/apache/tiles/definition/
tiles-core/src/main/java/org/apache/tiles/definition/dao/
tiles-core/src/main/java/org/...
Author: apetrelli
Date: Sun Oct 25 19:01:12 2009
New Revision: 829630
URL: http://svn.apache.org/viewvc?rev=829630&view=rev
Log:
TILESSB-10
Fixed tests to work without deprecations and init methods.
Modified:
tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesRequestContextFactory.java
tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/LocaleDefinitionsFactory.java
tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/dao/BaseLocaleUrlDefinitionDAO.java
tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java
tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesRequestContextFactoryTest.java
tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/LocaleDefinitionsFactoryTest.java
tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java
tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAOTest.java
tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java
tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/digester/TestDigesterDefinitionsReader.java
tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/renderer/impl/BasicRendererFactoryTest.java
tiles/sandbox/trunk/tiles3/tiles-el/src/test/java/org/apache/tiles/el/ELAttributeEvaluatorTest.java
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesRequestContextFactory.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesRequestContextFactory.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesRequestContextFactory.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesRequestContextFactory.java Sun Oct 25 19:01:12 2009
@@ -37,24 +37,6 @@
public class ChainedTilesRequestContextFactory implements TilesRequestContextFactory {
/**
- * Factory class names initialization parameter to use.
- *
- * @since 2.1.1
- */
- public static final String FACTORY_CLASS_NAMES =
- "org.apache.tiles.context.ChainedTilesRequestContextFactory.FACTORY_CLASS_NAMES";
-
- /**
- * The default class names to instantiate that compose the chain..
- *
- * @since 2.1.1
- */
- public static final String[] DEFAULT_FACTORY_CLASS_NAMES = {
- "org.apache.tiles.servlet.context.ServletTilesRequestContextFactory",
- "org.apache.tiles.portlet.context.PortletTilesRequestContextFactory",
- "org.apache.tiles.jsp.context.JspTilesRequestContextFactory" };
-
- /**
* The Tiles context factories composing the chain.
*/
private List<TilesRequestContextFactory> factories;
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/LocaleDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/LocaleDefinitionsFactory.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/LocaleDefinitionsFactory.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/LocaleDefinitionsFactory.java Sun Oct 25 19:01:12 2009
@@ -25,10 +25,6 @@
import org.apache.tiles.Definition;
import org.apache.tiles.context.TilesRequestContext;
-import org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO;
-import org.apache.tiles.definition.dao.DefinitionDAO;
-import org.apache.tiles.locale.LocaleResolver;
-import org.apache.tiles.locale.impl.DefaultLocaleResolver;
/**
* {@link DefinitionsFactory DefinitionsFactory} implementation that manages
@@ -76,25 +72,4 @@
return retValue;
}
-
- /**
- * Creates the default locale resolver, if it has not been specified
- * outside.
- *
- * @return The default locale resolver.
- * @since 2.1.0
- */
- protected LocaleResolver createDefaultLocaleResolver() {
- return new DefaultLocaleResolver();
- }
-
- /**
- * Creates the default definition DAO, if it has not been specified outside.
- *
- * @return The default definition DAO.
- * @since 2.1.0
- */
- protected DefinitionDAO<Locale> createDefaultDefinitionDAO() {
- return new CachingLocaleUrlDefinitionDAO();
- }
}
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/dao/BaseLocaleUrlDefinitionDAO.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/dao/BaseLocaleUrlDefinitionDAO.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/dao/BaseLocaleUrlDefinitionDAO.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/dao/BaseLocaleUrlDefinitionDAO.java Sun Oct 25 19:01:12 2009
@@ -35,7 +35,6 @@
import org.apache.tiles.Definition;
import org.apache.tiles.TilesApplicationContext;
import org.apache.tiles.awareness.TilesApplicationContextAware;
-import org.apache.tiles.definition.DefinitionsFactory;
import org.apache.tiles.definition.DefinitionsFactoryException;
import org.apache.tiles.definition.DefinitionsReader;
import org.apache.tiles.definition.RefreshMonitor;
@@ -144,87 +143,6 @@
}
/**
- * Detects the sources to load.
- *
- * @param initParameters The initialization parameters.
- * @since 2.1.0
- */
- protected void identifySources(Map<String, String> initParameters) {
- if (applicationContext == null) {
- throw new IllegalStateException(
- "The TilesApplicationContext cannot be null");
- }
-
- String resourceString = getResourceString(initParameters);
- String[] resources = getResourceNames(resourceString);
-
- try {
- for (int i = 0; i < resources.length; i++) {
- Set<URL> urls = applicationContext.getResources(resources[i]);
- if (urls != null && !urls.isEmpty()) {
- for (URL resourceUrl : urls) {
- if (resourceUrl != null) {
- if (log.isDebugEnabled()) {
- log.debug("Adding resource '" + resourceUrl
- + "' to definitions factory.");
- }
- String externalForm = resourceUrl.toExternalForm();
- if (externalForm.indexOf('_', externalForm
- .lastIndexOf("/")) < 0) {
- sourceURLs.add(resourceUrl);
- } else if (log.isDebugEnabled()) {
- log.debug("Not adding resource '" + resourceUrl
- + "' to definitions factory because it is "
- + "supposed to be an internationalization.");
- }
-
- } else {
- log.warn("Unable to find configured definition '"
- + resources[i] + "'");
- }
- }
- } else {
- log.warn("Unable to find resources under the name '"
- + resources[i] + "'");
- }
- }
- } catch (IOException e) {
- throw new DefinitionsFactoryException(
- "Unable to parse definitions from " + resourceString, e);
- }
- }
-
- /**
- * Derive the resource string from the initialization parameters. If no
- * parameter {@link DefinitionsFactory#DEFINITIONS_CONFIG} is available,
- * attempts to retrieve the deprecated
- * <code>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</code>
- * parameter and {@link #LEGACY_DEFINITIONS_CONFIG}. If neither are
- * available, returns "/WEB-INF/tiles.xml".
- *
- * @param parms The initialization parameters.
- * @return resource string to be parsed.
- */
- protected String getResourceString(Map<String, String> parms) {
- String resourceStr = parms.get(DefinitionsFactory.DEFINITIONS_CONFIG);
- if (resourceStr == null) {
- resourceStr = "/WEB-INF/tiles.xml";
- }
- return resourceStr;
- }
-
- /**
- * Parse the resourceString into a list of resource paths which can be
- * loaded by the application context.
- *
- * @param resourceString comma separated resources
- * @return parsed resources
- */
- protected String[] getResourceNames(String resourceString) {
- return resourceString.split(",");
- }
-
- /**
* Loads definitions from an URL without loading from "parent" URLs.
*
* @param url The URL to read.
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/main/java/org/apache/tiles/definition/digester/DigesterDefinitionsReader.java Sun Oct 25 19:01:12 2009
@@ -245,15 +245,7 @@
* from the source.
*/
protected Digester digester;
- /**
- * Stores Definition objects.
- */
- private Map<String, Definition> definitions;
- /**
- * Should we use a validating XML parser to read the configuration file.
- * Default is <code>true</code>.
- */
- protected boolean validating = true;
+
/**
* The set of public identifiers, and corresponding resource names for
* the versions of the configuration file DTDs we know about. There
@@ -262,6 +254,11 @@
protected String[] registrations;
/**
+ * Stores Definition objects.
+ */
+ private Map<String, Definition> definitions;
+
+ /**
* Index to be used to create unique definition names for anonymous
* (nested) definitions.
*/
@@ -272,7 +269,6 @@
*/
public DigesterDefinitionsReader() {
digester = new Digester();
- digester.setValidating(validating);
digester.setNamespaceAware(true);
digester.setUseContextClassLoader(true);
digester.setErrorHandler(new ThrowingErrorHandler());
@@ -291,6 +287,17 @@
}
/**
+ * Sets the validation of XML files.
+ *
+ * @param validating <code>true</code> means that XML validation is turned
+ * on. <code>false</code> otherwise.
+ * @since 3.3.0
+ */
+ public void setValidating(boolean validating) {
+ digester.setValidating(validating);
+ }
+
+ /**
* Reads <code>{@link Definition}</code> objects from a source.
* <p/>
* Implementations should publish what type of source object is expected.
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesRequestContextFactoryTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesRequestContextFactoryTest.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesRequestContextFactoryTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesRequestContextFactoryTest.java Sun Oct 25 19:01:12 2009
@@ -21,9 +21,7 @@
package org.apache.tiles.context;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import junit.framework.TestCase;
@@ -58,20 +56,6 @@
}
/**
- * Tests the initialization method.
- */
- public void testInit() {
- Map<String, String> config = new HashMap<String, String>();
- config.put(ChainedTilesRequestContextFactory.FACTORY_CLASS_NAMES,
- "this.is.not.a.class.Name,"
- + RepeaterTilesRequestContextFactory.class.getName());
- ChainedTilesRequestContextFactory factory = new ChainedTilesRequestContextFactory();
- TilesRequestContext context = factory.createRequestContext(appContext, requestContext);
- assertNotNull("The request context is not correct",
- context == requestContext);
- }
-
- /**
* Tests {@link ChainedTilesRequestContextFactory#setFactories(java.util.List)}.
*/
public void testSetFactories() {
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/LocaleDefinitionsFactoryTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/LocaleDefinitionsFactoryTest.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/LocaleDefinitionsFactoryTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/LocaleDefinitionsFactoryTest.java Sun Oct 25 19:01:12 2009
@@ -21,406 +21,59 @@
package org.apache.tiles.definition;
-import java.io.IOException;
-import java.net.URL;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.apache.tiles.Attribute;
import org.apache.tiles.Definition;
import org.apache.tiles.TilesApplicationContext;
import org.apache.tiles.context.TilesRequestContext;
-import org.easymock.EasyMock;
+import org.apache.tiles.definition.dao.DefinitionDAO;
+import org.apache.tiles.locale.LocaleResolver;
+import org.junit.Test;
/**
* Tests {@link LocaleDefinitionsFactory}.
*
* @version $Rev$ $Date$
*/
-public class LocaleDefinitionsFactoryTest extends TestCase {
-
- /**
- * The number of attribute names.
- */
- private static final int ATTRIBUTE_NAMES_COUNT = 6;
-
- /**
- * The definitions factory.
- */
- private LocaleDefinitionsFactory factory;
-
- /** {@inheritDoc} */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- factory = new LocaleDefinitionsFactory();
- }
-
- /**
- * Creates a new instance of TestUrlDefinitionsFactory.
- *
- * @param name The name of the test.
- */
- public LocaleDefinitionsFactoryTest(String name) {
- super(name);
- }
-
- /**
- * Start the tests.
- *
- * @param theArgs the arguments. Not used
- */
- public static void main(String[] theArgs) {
- junit.textui.TestRunner.main(
- new String[]{LocaleDefinitionsFactoryTest.class.getName()});
- }
-
- /**
- * @return a test suite (<code>TestSuite</code>) that includes all methods
- * starting with "test"
- */
- public static Test suite() {
- return new TestSuite(LocaleDefinitionsFactoryTest.class);
- }
-
- /**
- * Tests the readDefinitions method under normal conditions.
- *
- * @throws Exception If something goes wrong.
- */
- public void testReadDefinitions() throws Exception {
- // Set up multiple data sources.
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1.xml");
- assertNotNull("Could not load defs1 file.", url1);
- URL url2 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs2.xml");
- assertNotNull("Could not load defs2 file.", url2);
- URL url3 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs3.xml");
- assertNotNull("Could not load defs3 file.", url3);
-
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- factory.setApplicationContext(applicationContext);
-
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
-
- assertNotNull("test.def1 definition not found.", factory.getDefinition(
- "test.def1", (TilesRequestContext) null));
- assertNotNull("test.def2 definition not found.", factory.getDefinition(
- "test.def2", (TilesRequestContext) null));
- assertNotNull("test.def3 definition not found.", factory.getDefinition(
- "test.def3", (TilesRequestContext) null));
- }
-
- /**
- * Tests the getDefinition method.
- *
- * @throws Exception If something goes wrong.
- */
- public void testGetDefinition() throws Exception {
- // Set up multiple data sources.
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1.xml");
- assertNotNull("Could not load defs1 file.", url1);
- URL url2 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs2.xml");
- assertNotNull("Could not load defs2 file.", url2);
- URL url3 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs3.xml");
- assertNotNull("Could not load defs3 file.", url3);
-
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- factory.setApplicationContext(applicationContext);
-
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
-
- TilesRequestContext emptyContext = new MockOnlyLocaleTilesContext(null);
- TilesRequestContext usContext = new MockOnlyLocaleTilesContext(Locale.US);
- TilesRequestContext frenchContext = new MockOnlyLocaleTilesContext(Locale.FRENCH);
- TilesRequestContext chinaContext = new MockOnlyLocaleTilesContext(Locale.CHINA);
- TilesRequestContext canadaFrenchContext = new MockOnlyLocaleTilesContext(Locale.CANADA_FRENCH);
-
- assertNotNull("test.def1 definition not found.", factory.getDefinition("test.def1", emptyContext));
- assertNotNull("test.def2 definition not found.", factory.getDefinition("test.def2", emptyContext));
- assertNotNull("test.def3 definition not found.", factory.getDefinition("test.def3", emptyContext));
- assertNotNull("test.common definition not found.", factory.getDefinition("test.common", emptyContext));
- assertNotNull("test.common definition in US locale not found.", factory
- .getDefinition("test.common", usContext));
- assertNotNull("test.common definition in FRENCH locale not found.",
- factory.getDefinition("test.common", frenchContext));
- assertNotNull("test.common definition in CHINA locale not found.",
- factory.getDefinition("test.common", chinaContext));
- assertNotNull(
- "test.common.french definition in FRENCH locale not found.",
- factory.getDefinition("test.common.french", frenchContext));
- assertNotNull(
- "test.common.french definition in CANADA_FRENCH locale not found.",
- factory
- .getDefinition("test.common.french",
- canadaFrenchContext));
- assertNotNull("test.def.toextend definition not found.", factory
- .getDefinition("test.def.toextend", emptyContext));
- assertNotNull("test.def.overridden definition not found.", factory
- .getDefinition("test.def.overridden", emptyContext));
- assertNotNull(
- "test.def.overridden definition in FRENCH locale not found.",
- factory.getDefinition("test.def.overridden", frenchContext));
-
- assertEquals("Incorrect default country value", "default", factory
- .getDefinition("test.def1", emptyContext).getAttribute(
- "country").getValue());
- assertEquals("Incorrect US country value", "US", factory.getDefinition(
- "test.def1", usContext).getAttribute("country").getValue());
- assertEquals("Incorrect France country value", "France", factory
- .getDefinition("test.def1", frenchContext).getAttribute(
- "country").getValue());
- assertEquals("Incorrect Chinese country value (should be default)",
- "default", factory.getDefinition("test.def1", chinaContext)
- .getAttribute("country").getValue());
- assertEquals("Incorrect default country value", "default", factory
- .getDefinition("test.def.overridden", emptyContext)
- .getAttribute("country").getValue());
- assertEquals("Incorrect default title value",
- "Definition to be overridden", factory.getDefinition(
- "test.def.overridden", emptyContext).getAttribute(
- "title").getValue());
- assertEquals("Incorrect France country value", "France", factory
- .getDefinition("test.def.overridden", frenchContext)
- .getAttribute("country").getValue());
- assertEquals("Incorrect France title value",
- "Definition to be extended", factory.getDefinition(
- "test.def.overridden", frenchContext).getAttribute(
- "title").getValue());
- }
-
- /**
- * Tests the addDefinitions method under normal
- * circumstances.
- *
- * @throws Exception If something goes wrong.
- */
- public void testReadByLocale() throws Exception {
- // Set up multiple data sources.
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1.xml");
- assertNotNull("Could not load defs1 file.", url1);
- URL url2 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs2.xml");
- assertNotNull("Could not load defs2 file.", url2);
- URL url3 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs3.xml");
- assertNotNull("Could not load defs3 file.", url3);
-
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- factory.setApplicationContext(applicationContext);
-
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
-
- // Parse files.
- TilesRequestContext usContext = new MockOnlyLocaleTilesContext(Locale.US);
- TilesRequestContext frenchContext = new MockOnlyLocaleTilesContext(Locale.FRENCH);
- TilesRequestContext chinaContext = new MockOnlyLocaleTilesContext(Locale.CHINA);
-
- assertNotNull("test.def1 definition not found.", factory.getDefinition(
- "test.def1", null));
- assertNotNull("test.def1 US definition not found.", factory
- .getDefinition("test.def1", usContext));
- assertNotNull("test.def1 France definition not found.", factory
- .getDefinition("test.def1", frenchContext));
- assertNotNull("test.def1 China should return default.", factory
- .getDefinition("test.def1", chinaContext));
-
- assertEquals("Incorrect default country value", "default", factory
- .getDefinition("test.def1", null).getAttribute(
- "country").getValue());
- assertEquals("Incorrect US country value", "US", factory.getDefinition(
- "test.def1", usContext).getAttribute("country").getValue());
- assertEquals("Incorrect France country value", "France", factory
- .getDefinition("test.def1", frenchContext).getAttribute(
- "country").getValue());
- assertEquals("Incorrect Chinese country value (should default)",
- "default", factory.getDefinition("test.def1", chinaContext)
- .getAttribute("country").getValue());
- }
+public class LocaleDefinitionsFactoryTest {
/**
- * Tests the reader init param.
- *
- * @throws Exception If something goes wrong.
+ * Test method for {@link LocaleDefinitionsFactory#getDefinition(String, TilesRequestContext)}.
*/
- public void testReaderParam() throws Exception {
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.READER_IMPL_PROPERTY,
- "org.apache.tiles.definition.MockDefinitionsReader");
-
- int instanceCount = MockDefinitionsReader.getInstanceCount();
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetDefinition() {
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ DefinitionDAO<Locale> dao = createMock(DefinitionDAO.class);
+ LocaleResolver localeResolver = createMock(LocaleResolver.class);
+ TilesRequestContext request = createMock(TilesRequestContext.class);
+ Attribute templateAttribute = Attribute.createTemplateAttribute("/mytemplate.jsp");
+ Definition definition = new Definition("myDefinition", null, null);
+ definition.setExtends("anotherDefinition");
+ Map<String, Attribute> attributes = new HashMap<String, Attribute>();
+ attributes.put("first", new Attribute("myValue"));
+ Definition anotherDefinition = new Definition("anotherDefinition", templateAttribute, attributes);
+ Locale locale = Locale.ITALY;
+
+ expect(localeResolver.resolveLocale(request)).andReturn(locale);
+ expect(dao.getDefinition("myDefinition", locale)).andReturn(definition);
+ expect(dao.getDefinition("anotherDefinition", locale)).andReturn(anotherDefinition);
LocaleDefinitionsFactory factory = new LocaleDefinitionsFactory();
- // Set up multiple data sources.
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1.xml");
- assertNotNull("Could not load defs1 file.", url1);
-
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- factory.setApplicationContext(applicationContext);
-
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml");
-
- assertEquals("MockDefinitionsReader not used.",
- instanceCount + 1,
- MockDefinitionsReader.getInstanceCount());
- }
-
- /**
- * Tests wildcard mappings.
- *
- * @throws IOException If something goes wrong.
- */
- public void testWildcardMapping() throws IOException {
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs-wildcard.xml");
-
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs-wildcard.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ replay(applicationContext, dao, localeResolver, request);
factory.setApplicationContext(applicationContext);
-
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs-wildcard.xml");
-
- TilesRequestContext request = EasyMock.createMock(TilesRequestContext.class);
- EasyMock.expect(request.getRequestLocale()).andReturn(Locale.ITALY).anyTimes();
- EasyMock.expect(request.getSessionScope()).andReturn(null).anyTimes();
-
- EasyMock.replay(request);
-
- Definition definition = factory.getDefinition("test.defName.subLayered", request);
- assertEquals("The template is not correct", "/testName.jsp", definition
- .getTemplateAttribute().getValue());
- assertEquals("The header attribute is not correct",
- "/common/headerLayered.jsp", definition.getAttribute("header")
- .getValue());
- definition = factory.getDefinition("test.defName.subLayered", request);
- assertEquals("The template is not correct", "/testName.jsp", definition
- .getTemplateAttribute().getValue());
- assertEquals("The header attribute is not correct",
- "/common/headerLayered.jsp", definition.getAttribute("header")
- .getValue());
- definition = factory.getDefinition("test.defName.subLayered", request);
- assertEquals("The template is not correct", "/testName.jsp", definition
- .getTemplateAttribute().getValue());
- assertEquals("The header attribute is not correct",
- "/common/headerLayered.jsp", definition.getAttribute("header")
- .getValue());
- definition = factory.getDefinition("test.defName.noAttribute", request);
- assertEquals("/testName.jsp", definition.getTemplateAttribute().getValue());
- assertEquals(null, definition.getLocalAttributeNames());
- definition = factory.getDefinition("test.def3", request);
- assertNotNull("The simple definition is null", definition);
-
- definition = factory.getDefinition("test.extended.defName.subLayered", request);
- assertEquals("test.defName.subLayered", definition.getExtends());
- assertEquals(ATTRIBUTE_NAMES_COUNT, definition.getLocalAttributeNames().size());
- assertEquals("The template is not correct", "/testName.jsp", definition
- .getTemplateAttribute().getValue());
- assertEquals("Overridden Title", definition.getAttribute("title").getValue());
- assertEquals("The header attribute is not correct",
- "/common/headerLayered.jsp", definition.getAttribute("header")
- .getValue());
-
- EasyMock.verify(applicationContext, request);
+ factory.setDefinitionDAO(dao);
+ factory.setLocaleResolver(localeResolver);
+ Definition realDefinition = new Definition(definition);
+ realDefinition.inherit(anotherDefinition);
+ assertEquals(realDefinition, factory.getDefinition("myDefinition", request));
+ verify(applicationContext, dao, localeResolver, request);
}
}
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/CachingLocaleUrlDefinitionDAOTest.java Sun Oct 25 19:01:12 2009
@@ -21,6 +21,8 @@
package org.apache.tiles.definition.dao;
+import static org.easymock.EasyMock.*;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -53,7 +55,6 @@
import org.apache.tiles.definition.pattern.BasicPatternDefinitionResolver;
import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
import org.apache.tiles.definition.pattern.wildcard.WildcardDefinitionPatternMatcherFactory;
-import org.easymock.EasyMock;
/**
* Tests {@link CachingLocaleUrlDefinitionDAO}.
@@ -103,33 +104,17 @@
"org/apache/tiles/config/defs3.xml");
assertNotNull("Could not load defs3 file.", url3);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ sourceURLs.add(url2);
+ sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
assertNotNull("test.def1 definition not found.", definitionDao
.getDefinition("test.def1", null));
@@ -187,6 +172,7 @@
assertNull("Definition in French not found", definitionDao
.getDefinition("test.def.overridden", Locale.FRENCH)
.getAttribute("title"));
+ verify(applicationContext);
}
/**
@@ -206,33 +192,17 @@
"org/apache/tiles/config/defs3.xml");
assertNotNull("Could not load defs3 file.", url3);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ sourceURLs.add(url2);
+ sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
Map<String, Definition> defaultDefinitions = definitionDao
.getDefinitions(null);
@@ -242,7 +212,7 @@
.getDefinitions(Locale.FRENCH);
Map<String, Definition> chinaDefinitions = definitionDao
.getDefinitions(Locale.CHINA);
- Map<String, Definition> canadaFrendDefinitions = definitionDao
+ Map<String, Definition> canadaFrenchDefinitions = definitionDao
.getDefinitions(Locale.CANADA_FRENCH);
assertNotNull("test.def1 definition not found.", defaultDefinitions
@@ -261,10 +231,10 @@
chinaDefinitions.get("test.common"));
assertNotNull(
"test.common.french definition in FRENCH locale not found.",
- canadaFrendDefinitions.get("test.common.french"));
+ frenchDefinitions.get("test.common.french"));
assertNotNull(
"test.common.french definition in CANADA_FRENCH locale not found.",
- canadaFrendDefinitions.get("test.common.french"));
+ canadaFrenchDefinitions.get("test.common.french"));
assertNotNull("test.def.toextend definition not found.",
defaultDefinitions.get("test.def.toextend"));
assertNotNull("test.def.overridden definition not found.",
@@ -295,6 +265,7 @@
"country").getValue());
assertNull("Definition in French not found", frenchDefinitions.get(
"test.def.overridden").getAttribute("title"));
+ verify(applicationContext);
}
/**
@@ -324,7 +295,7 @@
* Tests {@link LocaleUrlDefinitionDAO#setReader(DefinitionsReader)}.
*/
public void testSetReader() {
- DefinitionsReader reader = EasyMock.createMock(DefinitionsReader.class);
+ DefinitionsReader reader = createMock(DefinitionsReader.class);
definitionDao.setReader(reader);
assertEquals("There reader has not been set correctly", reader,
definitionDao.reader);
@@ -363,8 +334,7 @@
* Tests {@link LocaleUrlDefinitionDAO#setApplicationContext(TilesApplicationContext)}.
*/
public void testSetApplicationContext() {
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
definitionDao.setApplicationContext(applicationContext);
assertEquals("The application context has not been set",
applicationContext, definitionDao.applicationContext);
@@ -382,133 +352,39 @@
"org/apache/tiles/config/defs2.xml");
URL url3 = this.getClass().getClassLoader().getResource(
"org/apache/tiles/config/defs3.xml");
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
Set<URL> urlSet = new HashSet<URL>();
urlSet.add(url1);
- EasyMock.expect(applicationContext.getResources("/WEB-INF/tiles.xml"))
+ expect(applicationContext.getResources("/WEB-INF/tiles.xml"))
.andReturn(urlSet);
- EasyMock.replay(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ definitionDao.setSourceURLs(sourceURLs);
assertEquals("The reader is not of the correct class",
DigesterDefinitionsReader.class, definitionDao.reader
.getClass());
- List<URL> sourceURLs = new ArrayList<URL>();
- sourceURLs.add(url1);
assertEquals("The source URLs are not correct", sourceURLs,
definitionDao.sourceURLs);
- EasyMock.reset(applicationContext);
+ reset(applicationContext);
- applicationContext = EasyMock.createMock(TilesApplicationContext.class);
- urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- params.clear();
- params.put(DefinitionsFactory.READER_IMPL_PROPERTY,
- MockDefinitionsReader.class.getName());
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,"
- + "org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
+ applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
- definitionDao.setSourceURLs(new ArrayList<URL>());
+ definitionDao.setReader(new MockDefinitionsReader());
assertEquals("The reader is not of the correct class",
MockDefinitionsReader.class, definitionDao.reader.getClass());
sourceURLs = new ArrayList<URL>();
sourceURLs.add(url1);
sourceURLs.add(url2);
sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
assertEquals("The source URLs are not correct", sourceURLs,
definitionDao.sourceURLs);
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#identifySources(Map)}.
- *
- * @throws IOException If something goes wrong.
- */
- public void testIdentifySources() throws IOException {
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1.xml");
- URL url2 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs2.xml");
- URL url3 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs3.xml");
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,"
- + "org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
- definitionDao.setApplicationContext(applicationContext);
- definitionDao.setSourceURLs(new ArrayList<URL>());
- definitionDao.identifySources(params);
- List<URL> sourceURLs = new ArrayList<URL>();
- sourceURLs.add(url1);
- sourceURLs.add(url2);
- sourceURLs.add(url3);
- assertEquals("The source URLs are not correct", sourceURLs,
- definitionDao.sourceURLs);
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#getResourceString(Map)}.
- */
- public void testGetResourceString() {
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG, "The string value");
- assertEquals("The resource string has not been got correctly",
- "The string value", definitionDao.getResourceString(params));
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#getResourceNames(String)}.
- */
- public void testGetResourceNames() {
- String toSplit = "This,will,be,split";
- String[] splitted = toSplit.split(",");
- String[] result = definitionDao.getResourceNames(toSplit);
- for (int i = 0; i < splitted.length; i++) {
- assertEquals("The string has not been split correctly", splitted[i],
- result[i]);
- }
+ verify(applicationContext);
}
/**
@@ -538,13 +414,8 @@
urlPath = "file:/" + url.getPath();
}
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url);
- EasyMock.expect(applicationContext.getResources(urlPath)).andReturn(
- urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
((TilesApplicationContextAware) definitionDao)
.setApplicationContext(applicationContext);
@@ -562,6 +433,12 @@
uri = new URI(urlPath.replaceAll(" ", "%20"));
}
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(uri.toURL());
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
+
String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"
+ "<!DOCTYPE tiles-definitions PUBLIC "
+ "\"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN\" "
@@ -580,12 +457,11 @@
Map<String, String> params = new HashMap<String, String>();
params.put(DefinitionsFactory.DEFINITIONS_CONFIG, urlPath);
- TilesRequestContext context = EasyMock
- .createMock(TilesRequestContext.class);
- EasyMock.expect(context.getSessionScope()).andReturn(
+ TilesRequestContext context = createMock(TilesRequestContext.class);
+ expect(context.getSessionScope()).andReturn(
new HashMap<String, Object>()).anyTimes();
- EasyMock.expect(context.getRequestLocale()).andReturn(null).anyTimes();
- EasyMock.replay(context);
+ expect(context.getRequestLocale()).andReturn(null).anyTimes();
+ replay(context);
Definition definition = definitionDao.getDefinition("rewrite.test",
null);
@@ -619,6 +495,8 @@
assertEquals("Factory should be stale.", true, reloadable
.refreshRequired());
+
+ verify(applicationContext, context);
}
/**
@@ -630,12 +508,8 @@
URL url = this.getClass().getClassLoader().getResource(
"org/apache/tiles/config/defs-wildcard.xml");
definitionDao.addSourceURL(url);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- EasyMock.expect(applicationContext
- .getResource("org/apache/tiles/config/defs-wildcard.xml"))
- .andReturn(url);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
((TilesApplicationContextAware) definitionDao)
.setApplicationContext(applicationContext);
definitionDao.setReader(new DigesterDefinitionsReader());
@@ -669,6 +543,7 @@
assertNull(definition.getTemplateAttribute().getValue());
assertEquals(1, definition.getLocalAttributeNames().size());
assertEquals("Overridden Title", definition.getAttribute("title").getValue());
+ verify(applicationContext);
}
/**
@@ -683,10 +558,9 @@
URL url = this.getClass().getClassLoader().getResource(
"org/apache/tiles/config/tiles-defs-2.1.xml");
definitionDao.addSourceURL(url);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
definitionDao.setReader(new DigesterDefinitionsReader());
- EasyMock.replay(applicationContext);
+ replay(applicationContext);
Definition definition = definitionDao.getDefinition(
"test.inherit.list", Locale.ITALIAN);
@@ -695,5 +569,6 @@
List<Attribute> attributes = (List<Attribute>) listAttribute.getValue();
// It is right not to resolve inheritance in this DAO.
assertEquals(1, attributes.size());
+ verify(applicationContext);
}
}
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAOTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAOTest.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAOTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAOTest.java Sun Oct 25 19:01:12 2009
@@ -21,6 +21,8 @@
package org.apache.tiles.definition.dao;
+import static org.easymock.EasyMock.*;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -48,7 +50,6 @@
import org.apache.tiles.definition.MockDefinitionsReader;
import org.apache.tiles.definition.RefreshMonitor;
import org.apache.tiles.definition.digester.DigesterDefinitionsReader;
-import org.easymock.EasyMock;
/**
* Tests {@link LocaleUrlDefinitionDAO}.
@@ -92,33 +93,17 @@
"org/apache/tiles/config/defs3.xml");
assertNotNull("Could not load defs3 file.", url3);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ sourceURLs.add(url2);
+ sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
assertNotNull("test.def1 definition not found.", definitionDao
.getDefinition("test.def1", null));
@@ -176,6 +161,7 @@
assertNull("Definition in French not found", definitionDao
.getDefinition("test.def.overridden", Locale.FRENCH)
.getAttribute("title"));
+ verify(applicationContext);
}
/**
@@ -195,33 +181,17 @@
"org/apache/tiles/config/defs3.xml");
assertNotNull("Could not load defs3 file.", url3);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ sourceURLs.add(url2);
+ sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
Map<String, Definition> defaultDefinitions = definitionDao
.getDefinitions(null);
@@ -284,6 +254,7 @@
"country").getValue());
assertNull("Definition in French not found", frenchDefinitions.get(
"test.def.overridden").getAttribute("title"));
+ verify(applicationContext);
}
/**
@@ -313,7 +284,7 @@
* Tests {@link LocaleUrlDefinitionDAO#setReader(DefinitionsReader)}.
*/
public void testSetReader() {
- DefinitionsReader reader = EasyMock.createMock(DefinitionsReader.class);
+ DefinitionsReader reader = createMock(DefinitionsReader.class);
definitionDao.setReader(reader);
assertEquals("There reader has not been set correctly", reader,
definitionDao.reader);
@@ -352,8 +323,7 @@
* Tests {@link LocaleUrlDefinitionDAO#setApplicationContext(TilesApplicationContext)}.
*/
public void testSetApplicationContext() {
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
definitionDao.setApplicationContext(applicationContext);
assertEquals("The application context has not been set",
applicationContext, definitionDao.applicationContext);
@@ -371,142 +341,39 @@
"org/apache/tiles/config/defs2.xml");
URL url3 = this.getClass().getClassLoader().getResource(
"org/apache/tiles/config/defs3.xml");
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
Set<URL> urlSet = new HashSet<URL>();
urlSet.add(url1);
- EasyMock.expect(applicationContext.getResources("/WEB-INF/tiles.xml"))
+ expect(applicationContext.getResources("/WEB-INF/tiles.xml"))
.andReturn(urlSet);
- EasyMock.replay(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ definitionDao.setSourceURLs(sourceURLs);
assertEquals("The reader is not of the correct class",
DigesterDefinitionsReader.class, definitionDao.reader
.getClass());
- List<URL> sourceURLs = new ArrayList<URL>();
- sourceURLs.add(url1);
assertEquals("The source URLs are not correct", sourceURLs,
definitionDao.sourceURLs);
- EasyMock.reset(applicationContext);
+ reset(applicationContext);
- applicationContext = EasyMock.createMock(TilesApplicationContext.class);
- urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- params.clear();
- params.put(DefinitionsFactory.READER_IMPL_PROPERTY,
- MockDefinitionsReader.class.getName());
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,"
- + "org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml");
+ applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
- definitionDao.setSourceURLs(new ArrayList<URL>());
+ definitionDao.setReader(new MockDefinitionsReader());
assertEquals("The reader is not of the correct class",
MockDefinitionsReader.class, definitionDao.reader.getClass());
sourceURLs = new ArrayList<URL>();
sourceURLs.add(url1);
sourceURLs.add(url2);
sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
assertEquals("The source URLs are not correct", sourceURLs,
definitionDao.sourceURLs);
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#identifySources(Map)}.
- *
- * @throws IOException If something goes wrong.
- */
- public void testIdentifySources() throws IOException {
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1.xml");
- URL url2 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs2.xml");
- URL url3 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs3.xml");
- URL url4 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1_en_US.xml");
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url4);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1_en_US.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,"
- + "org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml,"
- + "org/apache/tiles/config/defs1_en_US.xml");
- definitionDao.setApplicationContext(applicationContext);
- definitionDao.setSourceURLs(new ArrayList<URL>());
- definitionDao.identifySources(params);
- List<URL> sourceURLs = new ArrayList<URL>();
- sourceURLs.add(url1);
- sourceURLs.add(url2);
- sourceURLs.add(url3);
- assertEquals("The source URLs are not correct", sourceURLs,
- definitionDao.sourceURLs);
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#getResourceString(Map)}.
- */
- public void testGetResourceString() {
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG, "The string value");
- assertEquals("The resource string has not been got correctly",
- "The string value", definitionDao.getResourceString(params));
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#getResourceNames(String)}.
- */
- public void testGetResourceNames() {
- String toSplit = "This,will,be,split";
- String[] splitted = toSplit.split(",");
- String[] result = definitionDao.getResourceNames(toSplit);
- for (int i = 0; i < splitted.length; i++) {
- assertEquals("The string has not been split correctly", splitted[i],
- result[i]);
- }
+ verify(applicationContext);
}
/**
@@ -536,13 +403,8 @@
urlPath = "file:/" + url.getPath();
}
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url);
- EasyMock.expect(applicationContext.getResources(urlPath)).andReturn(
- urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
((TilesApplicationContextAware) definitionDao)
.setApplicationContext(applicationContext);
@@ -560,6 +422,12 @@
uri = new URI(urlPath.replaceAll(" ", "%20"));
}
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(uri.toURL());
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
+
String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"
+ "<!DOCTYPE tiles-definitions PUBLIC "
+ "\"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN\" "
@@ -578,12 +446,11 @@
Map<String, String> params = new HashMap<String, String>();
params.put(DefinitionsFactory.DEFINITIONS_CONFIG, urlPath);
- TilesRequestContext context = EasyMock
- .createMock(TilesRequestContext.class);
- EasyMock.expect(context.getSessionScope()).andReturn(
+ TilesRequestContext context = createMock(TilesRequestContext.class);
+ expect(context.getSessionScope()).andReturn(
new HashMap<String, Object>()).anyTimes();
- EasyMock.expect(context.getRequestLocale()).andReturn(null).anyTimes();
- EasyMock.replay(context);
+ expect(context.getRequestLocale()).andReturn(null).anyTimes();
+ replay(context);
Definition definition = definitionDao.getDefinition("rewrite.test",
null);
@@ -617,5 +484,7 @@
assertEquals("Factory should be stale.", true, reloadable
.refreshRequired());
+
+ verify(applicationContext, context);
}
}
Modified: tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java?rev=829630&r1=829629&r2=829630&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java (original)
+++ tiles/sandbox/trunk/tiles3/tiles-core/src/test/java/org/apache/tiles/definition/dao/ResolvingLocaleUrlDefinitionDAOTest.java Sun Oct 25 19:01:12 2009
@@ -21,6 +21,8 @@
package org.apache.tiles.definition.dao;
+import static org.easymock.EasyMock.*;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -53,7 +55,6 @@
import org.apache.tiles.definition.pattern.BasicPatternDefinitionResolver;
import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
import org.apache.tiles.definition.pattern.wildcard.WildcardDefinitionPatternMatcherFactory;
-import org.easymock.EasyMock;
/**
* Tests {@link ResolvingLocaleUrlDefinitionDAO}.
@@ -108,33 +109,21 @@
"org/apache/tiles/config/defs3.xml");
assertNotNull("Could not load defs3 file.", url3);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
Map<String, String> params = new HashMap<String, String>();
params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
"org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
+ "org/apache/tiles/config/defs3.xml");
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ sourceURLs.add(url2);
+ sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
assertNotNull("test.def1 definition not found.", definitionDao
.getDefinition("test.def1", null));
@@ -193,6 +182,7 @@
"Definition to be extended", definitionDao.getDefinition(
"test.def.overridden", Locale.FRENCH).getAttribute(
"title").getValue());
+ verify(applicationContext);
}
/**
@@ -212,27 +202,8 @@
"org/apache/tiles/config/defs3.xml");
assertNotNull("Could not load defs3 file.", url3);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
definitionDao.setApplicationContext(applicationContext);
Map<String, String> params = new HashMap<String, String>();
@@ -240,6 +211,14 @@
"org/apache/tiles/config/defs1.xml,org/apache/tiles/config/defs2.xml,"
+ "org/apache/tiles/config/defs3.xml");
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ sourceURLs.add(url2);
+ sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
+
Map<String, Definition> defaultDefinitions = definitionDao
.getDefinitions(null);
Map<String, Definition> usDefinitions = definitionDao
@@ -302,6 +281,7 @@
assertEquals("Incorrect France title value",
"Definition to be extended", frenchDefinitions.get(
"test.def.overridden").getAttribute("title").getValue());
+ verify(applicationContext);
}
/**
@@ -331,7 +311,7 @@
* Tests {@link LocaleUrlDefinitionDAO#setReader(DefinitionsReader)}.
*/
public void testSetReader() {
- DefinitionsReader reader = EasyMock.createMock(DefinitionsReader.class);
+ DefinitionsReader reader = createMock(DefinitionsReader.class);
definitionDao.setReader(reader);
assertEquals("There reader has not been set correctly", reader,
definitionDao.reader);
@@ -370,8 +350,7 @@
* Tests {@link LocaleUrlDefinitionDAO#setApplicationContext(TilesApplicationContext)}.
*/
public void testSetApplicationContext() {
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
definitionDao.setApplicationContext(applicationContext);
assertEquals("The application context has not been set",
applicationContext, definitionDao.applicationContext);
@@ -389,46 +368,28 @@
"org/apache/tiles/config/defs2.xml");
URL url3 = this.getClass().getClassLoader().getResource(
"org/apache/tiles/config/defs3.xml");
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
Set<URL> urlSet = new HashSet<URL>();
urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("/WEB-INF/tiles.xml"))
+ expect(applicationContext.getResources("/WEB-INF/tiles.xml"))
.andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ replay(applicationContext);
Map<String, String> params = new HashMap<String, String>();
definitionDao.setApplicationContext(applicationContext);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(url1);
+ definitionDao.setSourceURLs(sourceURLs);
assertEquals("The reader is not of the correct class",
DigesterDefinitionsReader.class, definitionDao.reader
.getClass());
- List<URL> sourceURLs = new ArrayList<URL>();
- sourceURLs.add(url1);
assertEquals("The source URLs are not correct", sourceURLs,
definitionDao.sourceURLs);
- EasyMock.reset(applicationContext);
+ reset(applicationContext);
- applicationContext = EasyMock.createMock(TilesApplicationContext.class);
- urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
+ applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
params.clear();
params.put(DefinitionsFactory.READER_IMPL_PROPERTY,
MockDefinitionsReader.class.getName());
@@ -437,96 +398,17 @@
+ "org/apache/tiles/config/defs2.xml,"
+ "org/apache/tiles/config/defs3.xml");
definitionDao.setApplicationContext(applicationContext);
- definitionDao.setSourceURLs(new ArrayList<URL>());
+ definitionDao.setReader(new MockDefinitionsReader());
assertEquals("The reader is not of the correct class",
MockDefinitionsReader.class, definitionDao.reader.getClass());
sourceURLs = new ArrayList<URL>();
sourceURLs.add(url1);
sourceURLs.add(url2);
sourceURLs.add(url3);
+ definitionDao.setSourceURLs(sourceURLs);
assertEquals("The source URLs are not correct", sourceURLs,
definitionDao.sourceURLs);
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#identifySources(Map)}.
- *
- * @throws IOException If something goes wrong.
- */
- public void testIdentifySources() throws IOException {
- URL url1 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1.xml");
- URL url2 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs2.xml");
- URL url3 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs3.xml");
- URL url4 = this.getClass().getClassLoader().getResource(
- "org/apache/tiles/config/defs1_en_US.xml");
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url1);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url2);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs2.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url3);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs3.xml"))
- .andReturn(urlSet);
- urlSet = new HashSet<URL>();
- urlSet.add(url4);
- EasyMock.expect(
- applicationContext
- .getResources("org/apache/tiles/config/defs1_en_US.xml"))
- .andReturn(urlSet);
- EasyMock.replay(applicationContext);
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG,
- "org/apache/tiles/config/defs1.xml,"
- + "org/apache/tiles/config/defs2.xml,"
- + "org/apache/tiles/config/defs3.xml,"
- + "org/apache/tiles/config/defs1_en_US.xml");
- definitionDao.setApplicationContext(applicationContext);
- definitionDao.setSourceURLs(new ArrayList<URL>());
- definitionDao.identifySources(params);
- List<URL> sourceURLs = new ArrayList<URL>();
- sourceURLs.add(url1);
- sourceURLs.add(url2);
- sourceURLs.add(url3);
- assertEquals("The source URLs are not correct", sourceURLs,
- definitionDao.sourceURLs);
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#getResourceString(Map)}.
- */
- public void testGetResourceString() {
- Map<String, String> params = new HashMap<String, String>();
- params.put(DefinitionsFactory.DEFINITIONS_CONFIG, "The string value");
- assertEquals("The resource string has not been got correctly",
- "The string value", definitionDao.getResourceString(params));
- }
-
- /**
- * Tests {@link LocaleUrlDefinitionDAO#getResourceNames(String)}.
- */
- public void testGetResourceNames() {
- String toSplit = "This,will,be,split";
- String[] splitted = toSplit.split(",");
- String[] result = definitionDao.getResourceNames(toSplit);
- for (int i = 0; i < splitted.length; i++) {
- assertEquals("The string has not been split correctly", splitted[i],
- result[i]);
- }
+ verify(applicationContext);
}
/**
@@ -556,13 +438,8 @@
urlPath = "file:/" + url.getPath();
}
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- Set<URL> urlSet = new HashSet<URL>();
- urlSet.add(url);
- EasyMock.expect(applicationContext.getResources(urlPath)).andReturn(
- urlSet);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
((TilesApplicationContextAware) definitionDao)
.setApplicationContext(applicationContext);
@@ -580,6 +457,12 @@
uri = new URI(urlPath.replaceAll(" ", "%20"));
}
+ List<URL> sourceURLs = new ArrayList<URL>();
+ sourceURLs.add(uri.toURL());
+ definitionDao.setSourceURLs(sourceURLs);
+ DefinitionsReader reader = new DigesterDefinitionsReader();
+ definitionDao.setReader(reader);
+
String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"
+ "<!DOCTYPE tiles-definitions PUBLIC "
+ "\"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN\" "
@@ -598,12 +481,11 @@
Map<String, String> params = new HashMap<String, String>();
params.put(DefinitionsFactory.DEFINITIONS_CONFIG, urlPath);
- TilesRequestContext context = EasyMock
- .createMock(TilesRequestContext.class);
- EasyMock.expect(context.getSessionScope()).andReturn(
+ TilesRequestContext context = createMock(TilesRequestContext.class);
+ expect(context.getSessionScope()).andReturn(
new HashMap<String, Object>()).anyTimes();
- EasyMock.expect(context.getRequestLocale()).andReturn(null).anyTimes();
- EasyMock.replay(context);
+ expect(context.getRequestLocale()).andReturn(null).anyTimes();
+ replay(context);
Definition definition = definitionDao.getDefinition("rewrite.test",
null);
@@ -637,6 +519,8 @@
assertEquals("Factory should be stale.", true, reloadable
.refreshRequired());
+
+ verify(applicationContext, context);
}
/**
@@ -648,12 +532,8 @@
URL url = this.getClass().getClassLoader().getResource(
"org/apache/tiles/config/defs-wildcard.xml");
definitionDao.addSourceURL(url);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
- EasyMock.expect(applicationContext
- .getResource("org/apache/tiles/config/defs-wildcard.xml"))
- .andReturn(url);
- EasyMock.replay(applicationContext);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
+ replay(applicationContext);
((TilesApplicationContextAware) definitionDao)
.setApplicationContext(applicationContext);
definitionDao.setReader(new DigesterDefinitionsReader());
@@ -691,6 +571,7 @@
assertEquals("The header attribute is not correct",
"/common/headerLayered.jsp", definition.getAttribute("header")
.getValue());
+ verify(applicationContext);
}
/**
@@ -705,10 +586,9 @@
URL url = this.getClass().getClassLoader().getResource(
"org/apache/tiles/config/tiles-defs-2.1.xml");
definitionDao.addSourceURL(url);
- TilesApplicationContext applicationContext = EasyMock
- .createMock(TilesApplicationContext.class);
+ TilesApplicationContext applicationContext = createMock(TilesApplicationContext.class);
definitionDao.setReader(new DigesterDefinitionsReader());
- EasyMock.replay(applicationContext);
+ replay(applicationContext);
Definition definition = definitionDao.getDefinition(
"test.inherit.list", Locale.ITALIAN);
@@ -716,5 +596,6 @@
.getAttribute("list");
List<Attribute> attributes = (List<Attribute>) listAttribute.getValue();
assertEquals(2, attributes.size());
+ verify(applicationContext);
}
}