From ab0cb82d31cbad47664dee423ddbf0894b004d27 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 6 Sep 2016 09:07:02 +0200 Subject: [PATCH] WW-4667 Applies params to all instances of interceptor defined in stack # Conflicts: # xwork-core/src/main/java/com/opensymphony/xwork2/config/providers/InterceptorBuilder.java --- .../providers/InterceptorBuilderTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/core/src/test/java/com/opensymphony/xwork2/config/providers/InterceptorBuilderTest.java b/core/src/test/java/com/opensymphony/xwork2/config/providers/InterceptorBuilderTest.java index 914d9630f..870691a54 100644 --- a/core/src/test/java/com/opensymphony/xwork2/config/providers/InterceptorBuilderTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/config/providers/InterceptorBuilderTest.java @@ -9,6 +9,7 @@ import com.opensymphony.xwork2.config.entities.InterceptorStackConfig; import com.opensymphony.xwork2.config.entities.PackageConfig; import com.opensymphony.xwork2.interceptor.Interceptor; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -78,6 +79,51 @@ public class InterceptorBuilderTest extends XWorkTestCase { assertEquals(((MockInterceptor2) ((InterceptorMapping) interceptorMappings.get(1)).getInterceptor()).getParam2(), "interceptor2_value2"); } + public void testMultipleSameInterceptors() throws Exception { + InterceptorConfig interceptorConfig1 = new InterceptorConfig.Builder("interceptor1", "com.opensymphony.xwork2.config.providers.InterceptorBuilderTest$MockInterceptor1").build(); + InterceptorConfig interceptorConfig2 = new InterceptorConfig.Builder("interceptor2", "com.opensymphony.xwork2.config.providers.InterceptorBuilderTest$MockInterceptor2").build(); + + InterceptorStackConfig interceptorStackConfig1 = new InterceptorStackConfig.Builder("multiStack") + .addInterceptor(new InterceptorMapping(interceptorConfig1.getName(), objectFactory.buildInterceptor(interceptorConfig1, Collections.emptyMap()))) + .addInterceptor(new InterceptorMapping(interceptorConfig2.getName(), objectFactory.buildInterceptor(interceptorConfig2, Collections.emptyMap()))) + .addInterceptor(new InterceptorMapping(interceptorConfig1.getName(), objectFactory.buildInterceptor(interceptorConfig1, Collections.emptyMap()))) + .build(); + + PackageConfig packageConfig = new PackageConfig.Builder("package1") + .namespace("/namespace") + .addInterceptorConfig(interceptorConfig1) + .addInterceptorConfig(interceptorConfig2) + .addInterceptorConfig(interceptorConfig1) + .addInterceptorStackConfig(interceptorStackConfig1) + .build(); + + List interceptorMappings = InterceptorBuilder.constructInterceptorReference(packageConfig, "multiStack", + new LinkedHashMap() { + { + put("interceptor1.param1", "interceptor1_value1"); + put("interceptor1.param2", "interceptor1_value2"); + } + }, null, objectFactory); + + assertEquals(interceptorMappings.size(), 3); + + assertEquals(((InterceptorMapping) interceptorMappings.get(0)).getName(), "interceptor1"); + assertNotNull(((InterceptorMapping) interceptorMappings.get(0)).getInterceptor()); + assertEquals(((InterceptorMapping) interceptorMappings.get(0)).getInterceptor().getClass(), MockInterceptor1.class); + assertEquals(((MockInterceptor1) ((InterceptorMapping) interceptorMappings.get(0)).getInterceptor()).getParam1(), "interceptor1_value1"); + assertEquals(((MockInterceptor1) ((InterceptorMapping) interceptorMappings.get(0)).getInterceptor()).getParam2(), "interceptor1_value2"); + + assertEquals(((InterceptorMapping) interceptorMappings.get(1)).getName(), "interceptor2"); + assertNotNull(((InterceptorMapping) interceptorMappings.get(1)).getInterceptor()); + assertEquals(((InterceptorMapping) interceptorMappings.get(1)).getInterceptor().getClass(), MockInterceptor2.class); + + assertEquals(((InterceptorMapping) interceptorMappings.get(2)).getName(), "interceptor1"); + assertNotNull(((InterceptorMapping) interceptorMappings.get(2)).getInterceptor()); + assertEquals(((InterceptorMapping) interceptorMappings.get(2)).getInterceptor().getClass(), MockInterceptor1.class); + assertEquals(((MockInterceptor1) ((InterceptorMapping) interceptorMappings.get(2)).getInterceptor()).getParam1(), "interceptor1_value1"); + assertEquals(((MockInterceptor1) ((InterceptorMapping) interceptorMappings.get(2)).getInterceptor()).getParam2(), "interceptor1_value2"); + } + /** * Try to test this *