Search in sources :

Example 31 with InterceptorMapping

use of com.opensymphony.xwork2.config.entities.InterceptorMapping in project struts by apache.

the class XmlConfigurationProviderInterceptorsTest method testInterceptorInheritance.

public void testInterceptorInheritance() throws ConfigurationException {
    // expectations - the inherited interceptor stack
    InterceptorStackConfig inheritedStack = new InterceptorStackConfig.Builder("subDefaultStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).build();
    ConfigurationProvider provider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-inheritance.xml");
    // assertions
    PackageConfig defaultPkg = configuration.getPackageConfig("default");
    assertEquals(2, defaultPkg.getInterceptorConfigs().size());
    PackageConfig subPkg = configuration.getPackageConfig("subPackage");
    assertEquals(1, subPkg.getInterceptorConfigs().size());
    assertEquals(3, subPkg.getAllInterceptorConfigs().size());
    assertEquals(inheritedStack, subPkg.getInterceptorConfigs().get("subDefaultStack"));
    // expectations - the inherited interceptor stack
    inheritedStack = new InterceptorStackConfig.Builder("subSubDefaultStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).build();
    PackageConfig subSubPkg = configuration.getPackageConfig("subSubPackage");
    assertEquals(1, subSubPkg.getInterceptorConfigs().size());
    assertEquals(4, subSubPkg.getAllInterceptorConfigs().size());
    assertEquals(inheritedStack, subSubPkg.getInterceptorConfigs().get("subSubDefaultStack"));
}
Also used : InterceptorStackConfig(com.opensymphony.xwork2.config.entities.InterceptorStackConfig) HashMap(java.util.HashMap) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 32 with InterceptorMapping

use of com.opensymphony.xwork2.config.entities.InterceptorMapping in project struts by apache.

the class InterceptorBuilderTest method testBuildInterceptor_2.

/**
 * Try to test this
 * <interceptor-ref name="interceptorStack1">
 * <param name="interceptorStack2.interceptor1.param1">interceptor1_value1</param>
 * <param name="interceptorStack2.interceptor1.param2">interceptor1_value2</param>
 * <param name="interceptorStack3.interceptor2.param1">interceptor2_value1</param>
 * <param name="interceptorStack3.interceptor2.param2">interceptor2_value2</param>
 * </interceptor-ref>
 *
 * @throws Exception
 */
public void testBuildInterceptor_2() throws Exception {
    InterceptorStackConfig interceptorStackConfig1 = new InterceptorStackConfig.Builder("interceptorStack1").build();
    InterceptorStackConfig interceptorStackConfig2 = new InterceptorStackConfig.Builder("interceptorStack2").build();
    InterceptorStackConfig interceptorStackConfig3 = new InterceptorStackConfig.Builder("interceptorStack3").build();
    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();
    PackageConfig packageConfig = new PackageConfig.Builder("package1").namespace("/namspace").addInterceptorConfig(interceptorConfig1).addInterceptorConfig(interceptorConfig2).addInterceptorStackConfig(interceptorStackConfig1).addInterceptorStackConfig(interceptorStackConfig2).addInterceptorStackConfig(interceptorStackConfig3).build();
    List interceptorMappings = InterceptorBuilder.constructInterceptorReference(packageConfig, "interceptorStack1", new LinkedHashMap<String, String>() {

        private static final long serialVersionUID = -5819935102242042570L;

        {
            put("interceptorStack2.interceptor1.param1", "interceptor1_value1");
            put("interceptorStack2.interceptor1.param2", "interceptor1_value2");
            put("interceptorStack3.interceptor2.param1", "interceptor2_value1");
            put("interceptorStack3.interceptor2.param2", "interceptor2_value2");
        }
    }, null, objectFactory);
    assertEquals(interceptorMappings.size(), 2);
    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(((MockInterceptor2) ((InterceptorMapping) interceptorMappings.get(1)).getInterceptor()).getParam1(), "interceptor2_value1");
    assertEquals(((MockInterceptor2) ((InterceptorMapping) interceptorMappings.get(1)).getInterceptor()).getParam2(), "interceptor2_value2");
}
Also used : InterceptorStackConfig(com.opensymphony.xwork2.config.entities.InterceptorStackConfig) InterceptorConfig(com.opensymphony.xwork2.config.entities.InterceptorConfig) List(java.util.List) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Aggregations

InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)29 InterceptorStackConfig (com.opensymphony.xwork2.config.entities.InterceptorStackConfig)13 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)12 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)12 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)8 InterceptorConfig (com.opensymphony.xwork2.config.entities.InterceptorConfig)7 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)7 RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)6 List (java.util.List)6 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)5 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)5 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)4 Interceptor (com.opensymphony.xwork2.interceptor.Interceptor)4 Map (java.util.Map)4 SimpleAction (com.opensymphony.xwork2.SimpleAction)3 DefaultConfiguration (com.opensymphony.xwork2.config.impl.DefaultConfiguration)3 MockInterceptor (com.opensymphony.xwork2.mock.MockInterceptor)3 DefaultFileManager (com.opensymphony.xwork2.util.fs.DefaultFileManager)3 DefaultFileManagerFactory (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory)3