Author: apetrelli Date: Wed Jan 3 04:48:35 2007 New Revision: 492128 URL: http://svn.apache.org/viewvc?view=rev&rev=492128 Log: SB-101 Added tests to check keyed definitions factory container functionality.
Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactoryTest.java (with props) struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-one.xml (with props) struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-two.xml (with props) struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/BasicTilesContainerTest.java (with props) struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/KeyedDefinitionsFactoryTilesContainerTest.java (with props) Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs.xml Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactoryTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactoryTest.java?view=auto&rev=492128 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactoryTest.java (added) +++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactoryTest.java Wed Jan 3 04:48:35 2007 @@ -0,0 +1,112 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tiles.factory; + +import junit.framework.TestCase; + +import javax.servlet.ServletContext; + +import org.easymock.EasyMock; +import org.apache.tiles.TilesContainer; +import org.apache.tiles.TilesException; +import org.apache.tiles.impl.BasicTilesContainer; +import org.apache.tiles.impl.KeyedDefinitionsFactoryTilesContainer; + +import java.util.Map; +import java.util.Vector; +import java.util.HashMap; +import java.net.URL; +import java.net.MalformedURLException; + + +/** + * @version $Rev$ $Date$ + */ +public class KeyedDefinitionsFactoryTilesContainerFactoryTest extends TestCase { + + private ServletContext context; + + private Map<String, String> defaults; + + public void setUp() { + context = EasyMock.createMock(ServletContext.class); + defaults = new HashMap<String, String>(); + defaults.put(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM, + KeyedDefinitionsFactoryTilesContainerFactory.class.getName()); + } + + public void testGetFactory() throws TilesException { + Vector<String> v = new Vector<String>(); + + EasyMock.expect(context.getInitParameterNames()).andReturn(v.elements()); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.replay(context); + TilesContainerFactory factory = TilesContainerFactory.getFactory(context, + defaults); + assertNotNull(factory); + assertEquals(KeyedDefinitionsFactoryTilesContainerFactory.class, + factory.getClass()); + } + + public void testCreateContainer() throws TilesException, MalformedURLException { + Vector enumeration = new Vector(); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTEXT_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.DEFINITIONS_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter( + KeyedDefinitionsFactoryTilesContainerFactory.CONTAINER_KEYS_INIT_PARAM)) + .andReturn("one,two").anyTimes(); + EasyMock.expect(context.getInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG + "@one")) + .andReturn("/WEB-INF/tiles-one.xml").anyTimes(); + EasyMock.expect(context.getInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG + "@two")) + .andReturn("/WEB-INF/tiles-two.xml").anyTimes(); + EasyMock.expect(context.getInitParameter(EasyMock.isA(String.class))).andReturn(null).anyTimes(); + EasyMock.expect(context.getInitParameterNames()).andReturn(enumeration.elements()).anyTimes(); + URL url = getClass().getResource("test-defs.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles.xml")).andReturn(url); + url = getClass().getResource("test-defs-key-one.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles-one.xml")).andReturn(url); + url = getClass().getResource("test-defs-key-two.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles-two.xml")).andReturn(url); + EasyMock.replay(context); + + TilesContainerFactory factory = TilesContainerFactory.getFactory(context, defaults); + TilesContainer container = factory.createContainer(context); + + assertNotNull(container); + assertTrue("The container is not an instance of KeyedDefinitionsFactoryTilesContainer", + container instanceof KeyedDefinitionsFactoryTilesContainer); + KeyedDefinitionsFactoryTilesContainer keyedContainer = + (KeyedDefinitionsFactoryTilesContainer) container; + assertNotNull(keyedContainer.getDefinitionsFactory()); + assertNotNull(keyedContainer.getDefinitionsFactory("one")); + assertNotNull(keyedContainer.getDefinitionsFactory("two")); + //now make sure it's initialized + try { + container.init(new HashMap<String, String>()); + fail("Container should have already been initialized"); + } + catch (IllegalStateException te) { + } + + } +} Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactoryTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/KeyedDefinitionsFactoryTilesContainerFactoryTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java?view=diff&rev=492128&r1=492127&r2=492128 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/TilesContainerFactoryTest.java Wed Jan 3 04:48:35 2007 @@ -49,6 +49,7 @@ public void testGetFactory() throws TilesException { Vector v = new Vector(); + Vector emptyVector = new Vector(); v.add(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM); EasyMock.expect(context.getInitParameterNames()).andReturn(v.elements()); @@ -66,6 +67,17 @@ assertNotNull(factory); assertEquals(TestFactory.class, factory.getClass()); + Map<String, String> defaults = new HashMap<String, String>(); + defaults.put(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM, + TestFactory.class.getName()); + EasyMock.reset(context); + EasyMock.expect(context.getInitParameterNames()).andReturn(emptyVector.elements()); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.replay(context); + factory = TilesContainerFactory.getFactory(context, defaults); + assertNotNull(factory); + assertEquals(TestFactory.class, factory.getClass()); + EasyMock.reset(context); EasyMock.expect(context.getInitParameterNames()).andReturn(v.elements()); EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM)).andReturn("org.missing.Class"); @@ -96,7 +108,7 @@ //now make sure it's initialized try { container.init(new HashMap<String, String>()); - fail("Container should have allready been initialized"); + fail("Container should have already been initialized"); } catch (IllegalStateException te) { } Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-one.xml URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-one.xml?view=auto&rev=492128 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-one.xml (added) +++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-one.xml Wed Jan 3 04:48:35 2007 @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!-- +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +--> + + <!DOCTYPE tiles-definitions PUBLIC + "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" + "http://struts.apache.org/dtds/tiles-config_2_0.dtd"> + +<tiles-definitions> + <definition name="test.def.one" template="/test.jsp"> + <put name="country" value="default"/> + <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> + +</tiles-definitions> Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-one.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-one.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-two.xml URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-two.xml?view=auto&rev=492128 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-two.xml (added) +++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-two.xml Wed Jan 3 04:48:35 2007 @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!-- +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +--> + + <!DOCTYPE tiles-definitions PUBLIC + "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" + "http://struts.apache.org/dtds/tiles-config_2_0.dtd"> + +<tiles-definitions> + <definition name="test.def.two" template="/test.jsp"> + <put name="country" value="default"/> + <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> + +</tiles-definitions> Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-two.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs-key-two.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs.xml URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs.xml?view=diff&rev=492128&r1=492127&r2=492128 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs.xml (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/factory/test-defs.xml Wed Jan 3 04:48:35 2007 @@ -27,7 +27,7 @@ "http://struts.apache.org/dtds/tiles-config_2_0.dtd"> <tiles-definitions> - <definition name="test.def1" path="/test.jsp"> + <definition name="test.def1" template="/test.jsp"> <put name="country" value="default"/> <put name="title" value="Tiles Library Documentation" /> <put name="header" value="/common/header.jsp" /> Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/BasicTilesContainerTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/BasicTilesContainerTest.java?view=auto&rev=492128 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/BasicTilesContainerTest.java (added) +++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/BasicTilesContainerTest.java Wed Jan 3 04:48:35 2007 @@ -0,0 +1,76 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tiles.impl; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Vector; + +import javax.servlet.ServletContext; + +import junit.framework.TestCase; + +import org.apache.tiles.TilesException; +import org.apache.tiles.factory.TilesContainerFactory; +import org.easymock.EasyMock; + + +/** + * @version $Rev$ $Date$ + */ +public class BasicTilesContainerTest extends TestCase { + + private BasicTilesContainer container; + + public void setUp() { + ServletContext context = EasyMock.createMock(ServletContext.class); + URL url = getClass().getResource("/org/apache/tiles/factory/test-defs.xml"); + + Vector<String> v = new Vector<String>(); + + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTEXT_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.DEFINITIONS_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(EasyMock.isA(String.class))).andReturn(null).anyTimes(); + EasyMock.expect(context.getInitParameterNames()).andReturn(v.elements()).anyTimes(); + try { + EasyMock.expect(context.getResource("/WEB-INF/tiles.xml")).andReturn(url); + } catch (MalformedURLException e) { + throw new RuntimeException("Error getting Tiles configuration URL", + e); + } + EasyMock.replay(context); + try { + TilesContainerFactory factory = TilesContainerFactory.getFactory(context); + container = (BasicTilesContainer) factory.createContainer(context); + } catch (TilesException e) { + throw new RuntimeException("Error initializing factory", e); + } + } + + public void testInitialization() { + assertNotNull(container); + assertNotNull(container.getContextFactory()); + assertNotNull(container.getPreparerFactory()); + assertNotNull(container.getDefinitionsFactory()); + } +} Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/BasicTilesContainerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/BasicTilesContainerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/KeyedDefinitionsFactoryTilesContainerTest.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/KeyedDefinitionsFactoryTilesContainerTest.java?view=auto&rev=492128 ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/KeyedDefinitionsFactoryTilesContainerTest.java (added) +++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/KeyedDefinitionsFactoryTilesContainerTest.java Wed Jan 3 04:48:35 2007 @@ -0,0 +1,191 @@ +/* + * $Id$ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.tiles.impl; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import junit.framework.TestCase; + +import org.apache.tiles.TilesException; +import org.apache.tiles.definition.DefinitionsFactory; +import org.apache.tiles.factory.KeyedDefinitionsFactoryTilesContainerFactory; +import org.apache.tiles.factory.TilesContainerFactory; +import org.easymock.EasyMock; + + +/** + * @version $Rev$ $Date$ + */ +public class KeyedDefinitionsFactoryTilesContainerTest extends TestCase { + + private KeyedDefinitionsFactoryTilesContainer container; + + private Map<String, String> defaults; + + public void setUp() { + defaults = new HashMap<String, String>(); + defaults.put(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM, + KeyedDefinitionsFactoryTilesContainerFactory.class.getName()); + + ServletContext context = EasyMock.createMock(ServletContext.class); + + Vector<String> v = new Vector<String>(); + + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTEXT_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.DEFINITIONS_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter( + KeyedDefinitionsFactoryTilesContainerFactory.CONTAINER_KEYS_INIT_PARAM)) + .andReturn("one,two").anyTimes(); + EasyMock.expect(context.getInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG + "@one")) + .andReturn("/WEB-INF/tiles-one.xml").anyTimes(); + EasyMock.expect(context.getInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG + "@two")) + .andReturn("/WEB-INF/tiles-two.xml").anyTimes(); + EasyMock.expect(context.getInitParameter(EasyMock.isA(String.class))).andReturn(null).anyTimes(); + EasyMock.expect(context.getInitParameterNames()).andReturn(v.elements()).anyTimes(); + try { + URL url = getClass().getResource("/org/apache/tiles/factory/test-defs.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles.xml")).andReturn(url); + url = getClass().getResource("/org/apache/tiles/factory/test-defs-key-one.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles-one.xml")).andReturn(url); + url = getClass().getResource("/org/apache/tiles/factory/test-defs-key-two.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles-two.xml")).andReturn(url); + } catch (MalformedURLException e) { + throw new RuntimeException("Error getting Tiles configuration URL", + e); + } + EasyMock.replay(context); + try { + TilesContainerFactory factory = TilesContainerFactory.getFactory(context, defaults); + container = (KeyedDefinitionsFactoryTilesContainer) factory.createContainer(context); + } catch (TilesException e) { + throw new RuntimeException("Error initializing factory", e); + } + } + + public void testInitialization() { + assertNotNull(container); + assertNotNull(container.getContextFactory()); + assertNotNull(container.getPreparerFactory()); + assertNotNull(container.getDefinitionsFactory()); + assertNotNull(container.getProperDefinitionsFactory("one")); + assertNotNull(container.getProperDefinitionsFactory("two")); + } + + public void testPostponedDefinitionsFactoryInitialization() throws MalformedURLException, TilesException { + KeyedDefinitionsFactoryTilesContainer container; + ServletContext context = EasyMock.createMock(ServletContext.class); + + Vector<String> v = new Vector<String>(); + + EasyMock.reset(context); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTEXT_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.DEFINITIONS_FACTORY_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG)).andReturn(null); + EasyMock.expect(context.getInitParameter("definitions-config")).andReturn(null); + EasyMock.expect(context.getInitParameter(TilesContainerFactory.CONTAINER_FACTORY_MUTABLE_INIT_PARAM)).andReturn(null); + EasyMock.expect(context.getInitParameter( + KeyedDefinitionsFactoryTilesContainerFactory.CONTAINER_KEYS_INIT_PARAM)) + .andReturn(null); + URL url = getClass().getResource("/org/apache/tiles/factory/test-defs.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles.xml")).andReturn(url); + url = getClass().getResource("/org/apache/tiles/factory/test-defs-key-one.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles-one.xml")).andReturn(url); + url = getClass().getResource("/org/apache/tiles/factory/test-defs-key-two.xml"); + EasyMock.expect(context.getResource("/WEB-INF/tiles-two.xml")).andReturn(url); + EasyMock.expect(context.getInitParameterNames()).andReturn(v.elements()).anyTimes(); + EasyMock.replay(context); + KeyedDefinitionsFactoryTilesContainerFactory factory = + (KeyedDefinitionsFactoryTilesContainerFactory) + TilesContainerFactory.getFactory(context, defaults); + container = (KeyedDefinitionsFactoryTilesContainer) factory.createContainer(context); + + assertNotNull(container); + assertNotNull(container.getDefinitionsFactory()); + assertNull(container.getProperDefinitionsFactory("one")); + assertNull(container.getProperDefinitionsFactory("two")); + + Map<String, String> initParams = new HashMap<String, String>(); + initParams.put(BasicTilesContainer.DEFINITIONS_CONFIG, + "/WEB-INF/tiles-one.xml"); + DefinitionsFactory defsFactory = factory.createDefinitionsFactory(context); + container.setDefinitionsFactory("one", defsFactory, initParams); + initParams.put(BasicTilesContainer.DEFINITIONS_CONFIG, + "/WEB-INF/tiles-two.xml"); + defsFactory = factory.createDefinitionsFactory(context); + container.setDefinitionsFactory("two", defsFactory, initParams); + assertNotNull(container.getProperDefinitionsFactory("one")); + assertNotNull(container.getProperDefinitionsFactory("two")); + } + + public void testDefinitionsFactoryUse() { + HttpServletRequest request = EasyMock.createMock( + HttpServletRequest.class); + HttpServletResponse response = EasyMock.createMock( + HttpServletResponse.class); + + EasyMock.reset(request); + EasyMock.reset(response); + EasyMock.expect(request.getAttribute( + KeyedDefinitionsFactoryTilesContainer.DEFINITIONS_FACTORY_KEY_ATTRIBUTE_NAME)) + .andReturn(null).anyTimes(); + EasyMock.expect(request.getLocale()).andReturn(null).anyTimes(); + EasyMock.replay(request); + EasyMock.replay(response); + assertTrue(container.isValidDefinition(request, response, "test.def1")); + assertFalse(container.isValidDefinition(request, response, "test.def.one")); + assertFalse(container.isValidDefinition(request, response, "test.def.two")); + + EasyMock.reset(request); + EasyMock.reset(response); + EasyMock.expect(request.getAttribute( + KeyedDefinitionsFactoryTilesContainer.DEFINITIONS_FACTORY_KEY_ATTRIBUTE_NAME)) + .andReturn("one").anyTimes(); + EasyMock.expect(request.getLocale()).andReturn(null).anyTimes(); + EasyMock.replay(request); + EasyMock.replay(response); + assertTrue(container.isValidDefinition(request, response, "test.def1")); + assertTrue(container.isValidDefinition(request, response, "test.def.one")); + assertFalse(container.isValidDefinition(request, response, "test.def.two")); + + EasyMock.reset(request); + EasyMock.reset(response); + EasyMock.expect(request.getAttribute( + KeyedDefinitionsFactoryTilesContainer.DEFINITIONS_FACTORY_KEY_ATTRIBUTE_NAME)) + .andReturn("two").anyTimes(); + EasyMock.expect(request.getLocale()).andReturn(null).anyTimes(); + EasyMock.replay(request); + EasyMock.replay(response); + assertTrue(container.isValidDefinition(request, response, "test.def1")); + assertFalse(container.isValidDefinition(request, response, "test.def.one")); + assertTrue(container.isValidDefinition(request, response, "test.def.two")); + } +} Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/KeyedDefinitionsFactoryTilesContainerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/impl/KeyedDefinitionsFactoryTilesContainerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL