Return-Path: X-Original-To: apmail-struts-commits-archive@minotaur.apache.org Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7CBBF102C2 for ; Thu, 18 Apr 2013 09:31:47 +0000 (UTC) Received: (qmail 92410 invoked by uid 500); 18 Apr 2013 09:31:47 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 92344 invoked by uid 500); 18 Apr 2013 09:31:47 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 92328 invoked by uid 99); 18 Apr 2013 09:31:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Apr 2013 09:31:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Apr 2013 09:31:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D392B2388A29; Thu, 18 Apr 2013 09:31:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1469245 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/dispatcher/mapper/ test/java/org/apache/struts2/ test/java/org/apache/struts2/dispatcher/mapper/ Date: Thu, 18 Apr 2013 09:31:24 -0000 To: commits@struts.apache.org From: lukaszlenart@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130418093124.D392B2388A29@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lukaszlenart Date: Thu Apr 18 09:31:24 2013 New Revision: 1469245 URL: http://svn.apache.org/r1469245 Log: WW-4048 Solves problem with instating a class and adds additional test Added: struts/struts2/trunk/core/src/test/java/org/apache/struts2/ClassInstantiationTest.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapper.java struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapperTest.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapper.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapper.java?rev=1469245&r1=1469244&r2=1469245&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapper.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapper.java Thu Apr 18 09:31:24 2013 @@ -29,7 +29,7 @@ import com.opensymphony.xwork2.util.logg import org.apache.struts2.StrutsConstants; import javax.servlet.http.HttpServletRequest; -import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; /** @@ -37,42 +37,8 @@ import java.util.List; * * A composite action mapper that is capable of delegating to a series of {@link ActionMapper} if the former * failed to obtained a valid {@link ActionMapping} or uri. - *

- * It is configured through struts.properties. - *

- * For example, with the following entries in struts.properties - *

- *

- * <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts" 
- *       class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />
- * <constant name="struts.mapper.composite" 
- *       value="org.apache.struts2.dispatcher.mapper.DefaultActionMapper,org.apache.struts2.dispatcher.mapper.RestfulActionMapper,org.apache.struts2.dispatcher.mapper.Restful2ActionMapper" />
- * 
- *

- * When {@link CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager)} or - * {@link CompositeActionMapper#getUriFromActionMapping(ActionMapping)} is invoked, - * {@link CompositeActionMapper} would go through these {@link ActionMapper}s in sequence - * starting from {@link ActionMapper} identified by 'struts.mapper.composite.1', followed by - * 'struts.mapper.composite.2' and finally 'struts.mapper.composite.3' (in this case) until either - * one of the {@link ActionMapper} return a valid result (not null) or it runs out of {@link ActionMapper} - * in which case it will just return null for both - * {@link CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager)} and - * {@link CompositeActionMapper#getUriFromActionMapping(ActionMapping)} methods. - *

* - * For example with the following in struts-*.xml :- - *

- *    <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts" 
- *       class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />
- *    <constant name="struts.mapper.composite" 
- *       value="org.apache.struts2.dispatcher.mapper.DefaultActionMapper,foo.bar.MyActionMapper,foo.bar.MyAnotherActionMapper" />
- * 
- *

- * CompositeActionMapper will be configured with 3 ActionMapper, namely - * "DefaultActionMapper", "MyActionMapper" and "MyAnotherActionMapper". - * CompositeActionMapper would consult each of them in order described above. - * - * + * More details: http://struts.apache.org/2.x/docs/actionmapper.html * * @see ActionMapper * @see ActionMapping @@ -83,16 +49,11 @@ public class CompositeActionMapper imple private static final Logger LOG = LoggerFactory.getLogger(CompositeActionMapper.class); - protected Container container; - - protected List actionMappers = new ArrayList(); - - public CompositeActionMapper(@Inject Container container) { - this.container = container; - } + protected List actionMappers = new LinkedList(); - @Inject(StrutsConstants.STRUTS_MAPPER_COMPOSITE) - public void setActionMappers(String list) { + @Inject + public CompositeActionMapper(Container container, + @Inject(value = StrutsConstants.STRUTS_MAPPER_COMPOSITE) String list) { if (list != null) { String[] arr = list.split(","); for (String name : arr) { @@ -104,7 +65,6 @@ public class CompositeActionMapper imple } } - public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) { for (ActionMapper actionMapper : actionMappers) { Added: struts/struts2/trunk/core/src/test/java/org/apache/struts2/ClassInstantiationTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/ClassInstantiationTest.java?rev=1469245&view=auto ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/ClassInstantiationTest.java (added) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/ClassInstantiationTest.java Thu Apr 18 09:31:24 2013 @@ -0,0 +1,47 @@ +package org.apache.struts2; + +import com.opensymphony.xwork2.inject.Container; +import org.apache.struts2.dispatcher.Dispatcher; +import org.apache.struts2.dispatcher.mapper.ActionMapper; + +import java.util.HashMap; + +/** + * Test class instantiation with Container + */ +public class ClassInstantiationTest extends StrutsTestCase { + + public void testCompositeActionMapperInstantiationWithList() throws Exception { + // given + Dispatcher du = initDispatcher(new HashMap() {{ + put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8"); + put(StrutsConstants.STRUTS_MAPPER_COMPOSITE, "struts,restful"); + }}); + Container container = du.getContainer(); + + // when + ActionMapper instance = container.getInstance(ActionMapper.class, "composite"); + + // then + assertNotNull(instance); + } + + public void testCompositeActionMapperInstantiationWithoutList() throws Exception { + // given + Dispatcher du = initDispatcher(new HashMap() {{ + put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8"); + }}); + Container container = du.getContainer(); + + // when + try { + container.getInstance(ActionMapper.class, "composite"); + fail(); + }catch (Exception e) { + // then + // You cannot use CompositeActionMapper without defined list of "struts.mapper.composite" + assertTrue(e.getMessage().contains("No mapping found for dependency [type=java.lang.String, name='struts.mapper.composite']")); + } + } + +} Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapperTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapperTest.java?rev=1469245&r1=1469244&r2=1469245&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapperTest.java (original) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/CompositeActionMapperTest.java Thu Apr 18 09:31:24 2013 @@ -36,15 +36,12 @@ import javax.servlet.http.HttpServletReq */ public class CompositeActionMapperTest extends TestCase { - CompositeActionMapper compositeActionMapper; Mock mockContainer; public void setUp() throws Exception { mockContainer = new Mock(Container.class); - compositeActionMapper = new CompositeActionMapper((Container)mockContainer.proxy()); } - public void testGetActionMappingAndUri1() throws Exception { ActionMapper mapper1 = new InnerActionMapper1(); ActionMapper mapper2 = new InnerActionMapper2(); @@ -52,7 +49,7 @@ public class CompositeActionMapperTest e mockContainer.expectAndReturn("getInstance", C.args(C.eq(ActionMapper.class), C.eq("mapper1")), mapper1); mockContainer.expectAndReturn("getInstance", C.args(C.eq(ActionMapper.class), C.eq("mapper2")), mapper3); mockContainer.expectAndReturn("getInstance", C.args(C.eq(ActionMapper.class), C.eq("mapper3")), mapper2); - compositeActionMapper.setActionMappers("mapper1,mapper2,mapper3"); + CompositeActionMapper compositeActionMapper = new CompositeActionMapper((Container) mockContainer.proxy(), "mapper1,mapper2,mapper3"); ActionMapping actionMapping = compositeActionMapper.getMapping(new MockHttpServletRequest(), new ConfigurationManager()); String uri = compositeActionMapper.getUriFromActionMapping(new ActionMapping()); @@ -70,7 +67,7 @@ public class CompositeActionMapperTest e ActionMapper mapper2 = new InnerActionMapper2(); mockContainer.expectAndReturn("getInstance", C.args(C.eq(ActionMapper.class), C.eq("mapper1")), mapper1); mockContainer.expectAndReturn("getInstance", C.args(C.eq(ActionMapper.class), C.eq("mapper2")), mapper2); - compositeActionMapper.setActionMappers("mapper1,mapper2"); + CompositeActionMapper compositeActionMapper = new CompositeActionMapper((Container) mockContainer.proxy(), "mapper1,mapper2"); ActionMapping actionMapping = compositeActionMapper.getMapping(new MockHttpServletRequest(), new ConfigurationManager()); String uri = compositeActionMapper.getUriFromActionMapping(new ActionMapping());