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
This commit is contained in:
Lukasz Lenart
2016-09-06 09:07:02 +02:00
parent 175c852eef
commit ab0cb82d31
@@ -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.<String, String>emptyMap())))
.addInterceptor(new InterceptorMapping(interceptorConfig2.getName(), objectFactory.buildInterceptor(interceptorConfig2, Collections.<String, String>emptyMap())))
.addInterceptor(new InterceptorMapping(interceptorConfig1.getName(), objectFactory.buildInterceptor(interceptorConfig1, Collections.<String, String>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<String, String>() {
{
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
* <interceptor-ref name="interceptorStack1">