Index: com/opensymphony/xwork/config/ConfigurationTest.java =================================================================== RCS file: /cvs/xwork/src/test/com/opensymphony/xwork/config/ConfigurationTest.java,v retrieving revision 1.11 diff -u -r1.11 ConfigurationTest.java --- com/opensymphony/xwork/config/ConfigurationTest.java 3 Mar 2006 16:54:00 -0000 1.11 +++ com/opensymphony/xwork/config/ConfigurationTest.java 6 Mar 2006 17:06:27 -0000 @@ -8,6 +8,7 @@ import com.opensymphony.xwork.mock.MockInterceptor; import com.opensymphony.xwork.config.providers.MockConfigurationProvider; import com.opensymphony.xwork.config.providers.XmlConfigurationProvider; +import com.opensymphony.xwork.config.entities.InterceptorMapping; import java.util.HashMap; @@ -81,7 +82,7 @@ ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("/foo/bar", "TestInterceptorParamInehritanceOverride", null); assertEquals(1, proxy.getConfig().getInterceptors().size()); - MockInterceptor testInterceptor = (MockInterceptor) proxy.getConfig().getInterceptors().get(0); + MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor(); assertEquals("foo123", testInterceptor.getExpectedFoo()); proxy.execute(); assertTrue(testInterceptor.isExecuted()); @@ -96,7 +97,7 @@ ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("/foo/bar", "TestInterceptorParamInheritance", null); assertEquals(1, proxy.getConfig().getInterceptors().size()); - MockInterceptor testInterceptor = (MockInterceptor) proxy.getConfig().getInterceptors().get(0); + MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor(); assertEquals("expectedFoo", testInterceptor.getExpectedFoo()); proxy.execute(); assertTrue(testInterceptor.isExecuted()); @@ -111,7 +112,7 @@ ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", "TestInterceptorParamOverride", null); assertEquals(1, proxy.getConfig().getInterceptors().size()); - MockInterceptor testInterceptor = (MockInterceptor) proxy.getConfig().getInterceptors().get(0); + MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor(); assertEquals("foo123", testInterceptor.getExpectedFoo()); proxy.execute(); assertTrue(testInterceptor.isExecuted()); @@ -126,7 +127,7 @@ ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", "TestInterceptorParam", null); assertEquals(1, proxy.getConfig().getInterceptors().size()); - MockInterceptor testInterceptor = (MockInterceptor) proxy.getConfig().getInterceptors().get(0); + MockInterceptor testInterceptor = (MockInterceptor) ((InterceptorMapping) proxy.getConfig().getInterceptors().get(0)).getInterceptor(); assertEquals("expectedFoo", testInterceptor.getExpectedFoo()); proxy.execute(); assertTrue(testInterceptor.isExecuted()); Index: com/opensymphony/xwork/config/providers/MockConfigurationProvider.java =================================================================== RCS file: /cvs/xwork/src/test/com/opensymphony/xwork/config/providers/MockConfigurationProvider.java,v retrieving revision 1.8 diff -u -r1.8 MockConfigurationProvider.java --- com/opensymphony/xwork/config/providers/MockConfigurationProvider.java 8 Feb 2006 18:12:54 -0000 1.8 +++ com/opensymphony/xwork/config/providers/MockConfigurationProvider.java 6 Mar 2006 17:06:27 -0000 @@ -12,6 +12,7 @@ import com.opensymphony.xwork.config.entities.ActionConfig; import com.opensymphony.xwork.config.entities.PackageConfig; import com.opensymphony.xwork.config.entities.ResultConfig; +import com.opensymphony.xwork.config.entities.InterceptorMapping; import com.opensymphony.xwork.interceptor.ModelDrivenInterceptor; import com.opensymphony.xwork.interceptor.ParametersInterceptor; import com.opensymphony.xwork.interceptor.StaticParametersInterceptor; @@ -67,14 +68,14 @@ results.put("success", new ResultConfig("success", ActionChainResult.class, successParams)); List interceptors = new ArrayList(); - interceptors.add(new ParametersInterceptor()); + interceptors.add(new InterceptorMapping("params", new ParametersInterceptor())); ActionConfig paramInterceptorActionConfig = new ActionConfig(null, SimpleAction.class, null, results, interceptors); defaultPackageContext.addActionConfig(PARAM_INTERCEPTOR_ACTION_NAME, paramInterceptorActionConfig); interceptors = new ArrayList(); - interceptors.add(new ModelDrivenInterceptor()); - interceptors.add(new ParametersInterceptor()); + interceptors.add(new InterceptorMapping("model", new ModelDrivenInterceptor())); + interceptors.add(new InterceptorMapping("params", new ParametersInterceptor())); ActionConfig modelParamActionConfig = new ActionConfig(null, ModelDrivenAction.class, null, null, interceptors); defaultPackageContext.addActionConfig(MODEL_DRIVEN_PARAM_TEST, modelParamActionConfig); @@ -90,10 +91,10 @@ results.put("success", new ResultConfig("success", ActionChainResult.class, successParams)); interceptors = new ArrayList(); - interceptors.add(new StaticParametersInterceptor()); - interceptors.add(new ModelDrivenInterceptor()); - interceptors.add(new ParametersInterceptor()); - interceptors.add(new ValidationInterceptor()); + interceptors.add(new InterceptorMapping("static-params", new StaticParametersInterceptor())); + interceptors.add(new InterceptorMapping("model", new ModelDrivenInterceptor())); + interceptors.add(new InterceptorMapping("params", new ParametersInterceptor())); + interceptors.add(new InterceptorMapping("validation", new ValidationInterceptor())); //Explicitly set an out-of-range date for DateRangeValidatorTest params = new HashMap(); Index: com/opensymphony/xwork/config/providers/XmlConfigurationProviderActionsTest.java =================================================================== RCS file: /cvs/xwork/src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderActionsTest.java,v retrieving revision 1.6 diff -u -r1.6 XmlConfigurationProviderActionsTest.java --- com/opensymphony/xwork/config/providers/XmlConfigurationProviderActionsTest.java 5 Mar 2006 20:48:57 -0000 1.6 +++ com/opensymphony/xwork/config/providers/XmlConfigurationProviderActionsTest.java 6 Mar 2006 17:06:27 -0000 @@ -50,7 +50,7 @@ results.put("success", new ResultConfig("success", MockResult.class, new HashMap())); InterceptorConfig timerInterceptorConfig = new InterceptorConfig("timer", TimerInterceptor.class, new HashMap()); - interceptors.add(objectFactory.buildInterceptor(timerInterceptorConfig, new HashMap())); + interceptors.add(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptorConfig, new HashMap()))); ActionConfig fooAction = new ActionConfig(null, SimpleAction.class, params, results, interceptors); @@ -77,9 +77,9 @@ interceptorParams.put("expectedFoo", "expectedFooValue"); interceptorParams.put("foo", MockInterceptor.DEFAULT_FOO_VALUE); - InterceptorConfig mockInterceptorConfig = new InterceptorConfig("mock", MockInterceptor.class, new HashMap()); + InterceptorConfig mockInterceptorConfig = new InterceptorConfig("test", MockInterceptor.class, new HashMap()); interceptors = new ArrayList(); - interceptors.add(objectFactory.buildInterceptor(mockInterceptorConfig, interceptorParams)); + interceptors.add(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptorConfig, interceptorParams))); ActionConfig intAction = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); @@ -88,7 +88,7 @@ interceptorParams.put("expectedFoo", "expectedFooValue"); interceptorParams.put("foo", "foo123"); interceptors = new ArrayList(); - interceptors.add(objectFactory.buildInterceptor(mockInterceptorConfig, interceptorParams)); + interceptors.add(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptorConfig, interceptorParams))); ActionConfig intOverAction = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); Index: com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorsTest.java =================================================================== RCS file: /cvs/xwork/src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorsTest.java,v retrieving revision 1.6 diff -u -r1.6 XmlConfigurationProviderInterceptorsTest.java --- com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorsTest.java 3 Mar 2006 16:53:59 -0000 1.6 +++ com/opensymphony/xwork/config/providers/XmlConfigurationProviderInterceptorsTest.java 6 Mar 2006 17:06:27 -0000 @@ -11,10 +11,7 @@ import com.opensymphony.xwork.config.ConfigurationManager; import com.opensymphony.xwork.config.ConfigurationProvider; import com.opensymphony.xwork.config.RuntimeConfiguration; -import com.opensymphony.xwork.config.entities.ActionConfig; -import com.opensymphony.xwork.config.entities.InterceptorConfig; -import com.opensymphony.xwork.config.entities.InterceptorStackConfig; -import com.opensymphony.xwork.config.entities.PackageConfig; +import com.opensymphony.xwork.config.entities.*; import com.opensymphony.xwork.interceptor.LoggingInterceptor; import com.opensymphony.xwork.interceptor.TimerInterceptor; @@ -51,14 +48,14 @@ // the default interceptor stack InterceptorStackConfig defaultStack = new InterceptorStackConfig("defaultStack"); - defaultStack.addInterceptor(objectFactory.buildInterceptor(timerInterceptor, new HashMap())); - defaultStack.addInterceptor(objectFactory.buildInterceptor(mockInterceptor, params)); + defaultStack.addInterceptor(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); + defaultStack.addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))); // the derivative interceptor stack InterceptorStackConfig derivativeStack = new InterceptorStackConfig("derivativeStack"); - derivativeStack.addInterceptor(objectFactory.buildInterceptor(timerInterceptor, new HashMap())); - derivativeStack.addInterceptor(objectFactory.buildInterceptor(mockInterceptor, params)); - derivativeStack.addInterceptor(objectFactory.buildInterceptor(loggingInterceptor, new HashMap())); + derivativeStack.addInterceptor(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); + derivativeStack.addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))); + derivativeStack.addInterceptor(new InterceptorMapping("logging", objectFactory.buildInterceptor(loggingInterceptor, new HashMap()))); // execute the configuration provider.init(configuration); @@ -87,12 +84,12 @@ // expectations - the inherited interceptor stack // default package ArrayList interceptors = new ArrayList(); - interceptors.add(objectFactory.buildInterceptor(loggingInterceptor, new HashMap())); + interceptors.add(new InterceptorMapping("logging", objectFactory.buildInterceptor(loggingInterceptor, new HashMap()))); ActionConfig actionWithOwnRef = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); interceptors = new ArrayList(); - interceptors.add(objectFactory.buildInterceptor(timerInterceptor, new HashMap())); + interceptors.add(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); ActionConfig actionWithDefaultRef = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); @@ -101,7 +98,7 @@ ActionConfig actionWithNoRef = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); interceptors = new ArrayList(); - interceptors.add(objectFactory.buildInterceptor(loggingInterceptor, new HashMap())); + interceptors.add(new InterceptorMapping("logging", objectFactory.buildInterceptor(loggingInterceptor, new HashMap()))); ActionConfig anotherActionWithOwnRef = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); @@ -120,7 +117,7 @@ // expectations - the inherited interceptor stack InterceptorStackConfig inheritedStack = new InterceptorStackConfig("subDefaultStack"); - inheritedStack.addInterceptor(objectFactory.buildInterceptor(timerInterceptor, new HashMap())); + inheritedStack.addInterceptor(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); provider.init(configuration); @@ -135,13 +132,66 @@ // expectations - the inherited interceptor stack inheritedStack = new InterceptorStackConfig("subSubDefaultStack"); - inheritedStack.addInterceptor(objectFactory.buildInterceptor(timerInterceptor, new HashMap())); - inheritedStack.addInterceptor(objectFactory.buildInterceptor(timerInterceptor, new HashMap())); + inheritedStack.addInterceptor(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); + inheritedStack.addInterceptor(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); PackageConfig subSubPkg = configuration.getPackageConfig("subSubPackage"); assertEquals(1, subSubPkg.getInterceptorConfigs().size()); assertEquals(4, subSubPkg.getAllInterceptorConfigs().size()); assertEquals(inheritedStack, subSubPkg.getInterceptorConfigs().get("subSubDefaultStack")); + } + + + public void testInterceptorParamOverriding() throws Exception { + + XmlConfigurationProvider provider = new XmlConfigurationProvider("com/opensymphony/xwork/config/providers/xwork-test-interceptor-params.xml"); + + Map params = new HashMap(); + params.put("foo", "expectedFoo"); + params.put("expectedFoo", "expectedFooValue"); + + InterceptorStackConfig defaultStack = new InterceptorStackConfig("defaultStack"); + defaultStack.addInterceptor(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); + defaultStack.addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))); + + ArrayList interceptors = new ArrayList(); + interceptors.addAll(defaultStack.getInterceptors()); + + ActionConfig intAction = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); + + // TestInterceptorParamOverride action tests that an interceptor with a param override worked + HashMap interceptorParams = new HashMap(); + interceptorParams.put("expectedFoo", "expectedFooValue2"); + interceptorParams.put("foo", "foo123"); + interceptors = new ArrayList(); + + InterceptorStackConfig defaultStack2 = new InterceptorStackConfig("defaultStack"); + defaultStack2.addInterceptor(new InterceptorMapping("timer", objectFactory.buildInterceptor(timerInterceptor, new HashMap()))); + defaultStack2.addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, interceptorParams))); + + interceptors = new ArrayList(); + + interceptors.addAll(defaultStack2.getInterceptors()); + + ActionConfig intOverAction = new ActionConfig(null, SimpleAction.class, new HashMap(), new HashMap(), interceptors); + + // execute the configuration + provider.init(configuration); + + PackageConfig pkg = configuration.getPackageConfig("default"); + Map actionConfigs = pkg.getActionConfigs(); + + // assertions + assertEquals(2, actionConfigs.size()); + assertEquals(intAction, actionConfigs.get("TestInterceptorParam")); + assertEquals(intOverAction, actionConfigs.get("TestInterceptorParamOverride")); + + ActionConfig ac = (ActionConfig) actionConfigs.get("TestInterceptorParamOverride"); + assertEquals(defaultStack.getInterceptors(), ac.getInterceptors()); + + ActionConfig ac2 = (ActionConfig) actionConfigs.get("TestInterceptorParam"); + assertEquals(defaultStack2.getInterceptors(), ac2.getInterceptors()); + } protected void setUp() throws Exception { Index: com/opensymphony/xwork/config/providers/XmlConfigurationProviderMultilevelTest.java =================================================================== RCS file: /cvs/xwork/src/test/com/opensymphony/xwork/config/providers/XmlConfigurationProviderMultilevelTest.java,v retrieving revision 1.5 diff -u -r1.5 XmlConfigurationProviderMultilevelTest.java --- com/opensymphony/xwork/config/providers/XmlConfigurationProviderMultilevelTest.java 9 Oct 2005 04:27:58 -0000 1.5 +++ com/opensymphony/xwork/config/providers/XmlConfigurationProviderMultilevelTest.java 6 Mar 2006 17:06:27 -0000 @@ -9,6 +9,7 @@ import com.opensymphony.xwork.config.entities.ActionConfig; import com.opensymphony.xwork.config.entities.PackageConfig; import com.opensymphony.xwork.config.entities.ResultConfig; +import com.opensymphony.xwork.config.entities.InterceptorMapping; import com.opensymphony.xwork.interceptor.ParametersInterceptor; import junit.framework.Assert; @@ -46,7 +47,7 @@ assertNotNull(actionConfig); assertNotNull(actionConfig.getInterceptors()); assertEquals(2, actionConfig.getInterceptors().size()); - assertEquals(ParametersInterceptor.class, actionConfig.getInterceptors().get(0).getClass()); + assertEquals(ParametersInterceptor.class, ((InterceptorMapping) actionConfig.getInterceptors().get(0)).getInterceptor().getClass()); assertNotNull(actionConfig.getResults()); assertEquals(1, actionConfig.getResults().size()); assertTrue(actionConfig.getResults().containsKey("success"));