Search in sources :

Example 6 with ConfigurationProvider

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

the class XmlConfigurationProviderMultilevelTest method testMultiLevelInheritance.

/**
 * attempt to load an xwork.xml file that has multilevel levels of inheritance and verify that the interceptors are
 * correctly propagated through.
 *
 * @throws Exception
 */
public void testMultiLevelInheritance() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-multilevel.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    provider.loadPackages();
    /**
     * for this test, we expect the action named, action3, in the namespace, namespace3, to have a single
     * ParameterInterceptor.  The ParameterInterceptor, param, has been defined far up namespace3's parentage ...
     * namespace3 -> namespace2 -> namespace1 -> default
     */
    PackageConfig packageConfig = configuration.getPackageConfig("namespace3");
    Assert.assertNotNull(packageConfig);
    assertEquals(2, packageConfig.getAllInterceptorConfigs().size());
    ActionConfig actionConfig = packageConfig.getActionConfigs().get("action3");
    assertNotNull(actionConfig);
    assertNotNull(actionConfig.getInterceptors());
    assertEquals(2, actionConfig.getInterceptors().size());
    assertEquals(ParametersInterceptor.class, ((InterceptorMapping) actionConfig.getInterceptors().get(0)).getInterceptor().getClass());
    assertNotNull(actionConfig.getResults());
    assertEquals(1, actionConfig.getResults().size());
    assertTrue(actionConfig.getResults().containsKey("success"));
    ResultConfig resultConfig = (ResultConfig) actionConfig.getResults().get("success");
    assertEquals(ActionChainResult.class.getName(), resultConfig.getClassName());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ActionChainResult(com.opensymphony.xwork2.ActionChainResult) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 7 with ConfigurationProvider

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

the class XmlConfigurationProviderPackagesTest method testPackageInheritance.

public void testPackageInheritance() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-package-inheritance.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    provider.loadPackages();
    // test expectations
    assertEquals(5, configuration.getPackageConfigs().size());
    PackageConfig defaultPackage = configuration.getPackageConfig("default");
    assertNotNull(defaultPackage);
    assertEquals("default", defaultPackage.getName());
    PackageConfig abstractPackage = configuration.getPackageConfig("abstractPackage");
    assertNotNull(abstractPackage);
    assertEquals("abstractPackage", abstractPackage.getName());
    PackageConfig singlePackage = configuration.getPackageConfig("singleInheritance");
    assertNotNull(singlePackage);
    assertEquals("singleInheritance", singlePackage.getName());
    assertEquals(1, singlePackage.getParents().size());
    assertEquals(defaultPackage, singlePackage.getParents().get(0));
    PackageConfig multiplePackage = configuration.getPackageConfig("multipleInheritance");
    assertNotNull(multiplePackage);
    assertEquals("multipleInheritance", multiplePackage.getName());
    assertEquals(3, multiplePackage.getParents().size());
    List<PackageConfig> multipleParents = multiplePackage.getParents();
    assertTrue(multipleParents.contains(defaultPackage));
    assertTrue(multipleParents.contains(abstractPackage));
    assertTrue(multipleParents.contains(singlePackage));
    PackageConfig parentBelow = configuration.getPackageConfig("testParentBelow");
    assertEquals(1, parentBelow.getParents().size());
    List<PackageConfig> parentBelowParents = parentBelow.getParents();
    assertTrue(parentBelowParents.contains(multiplePackage));
    configurationManager.addContainerProvider(provider);
    configurationManager.reload();
    RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
    assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "default"));
    assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "abstract"));
    assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "single"));
    assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "multiple"));
    assertNotNull(runtimeConfiguration.getActionConfig("/single", "default"));
    assertNull(runtimeConfiguration.getActionConfig("/single", "abstract"));
    assertNotNull(runtimeConfiguration.getActionConfig("/single", "single"));
    assertNull(runtimeConfiguration.getActionConfig("/single", "multiple"));
    assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "default"));
    assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "abstract"));
    assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "single"));
    assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "multiple"));
    assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "testParentBelowAction"));
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 8 with ConfigurationProvider

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

the class XmlConfigurationProviderPackagesTest method testDefaultPackage.

public void testDefaultPackage() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-default-package.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    provider.loadPackages();
    // setup our expectations
    PackageConfig expectedPackageConfig = new PackageConfig.Builder("default").build();
    // test expectations
    assertEquals(1, configuration.getPackageConfigs().size());
    assertEquals(expectedPackageConfig, configuration.getPackageConfig("default"));
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 9 with ConfigurationProvider

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

the class XmlConfigurationProviderResultTypesTest method testInheritedResultTypesParams.

public void testInheritedResultTypesParams() throws Exception {
    ConfigurationProvider configurationProvider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-result-types.xml");
    PackageConfig packageConfig = configuration.getPackageConfig("xworkResultTypesTestPackage2");
    Map actionConfigMap = packageConfig.getActionConfigs();
    ActionConfig action1ActionConfig = (ActionConfig) actionConfigMap.get("action1");
    ActionConfig action2ActionConfig = (ActionConfig) actionConfigMap.get("action2");
    ResultConfig action1Result = (ResultConfig) action1ActionConfig.getResults().get("success");
    ResultConfig action2Result = (ResultConfig) action2ActionConfig.getResults().get("success");
    assertEquals(action1Result.getName(), "success");
    assertEquals(action1Result.getClassName(), "com.opensymphony.xwork2.mock.MockResult");
    assertEquals(action1Result.getName(), "success");
    assertEquals(action1Result.getClassName(), "com.opensymphony.xwork2.mock.MockResult");
    Map action1ResultMap = action1Result.getParams();
    Map action2ResultMap = action2Result.getParams();
    assertEquals(action1ResultMap.size(), 5);
    assertTrue(action1ResultMap.containsKey("param1"));
    assertTrue(action1ResultMap.containsKey("param2"));
    assertTrue(action1ResultMap.containsKey("param3"));
    assertTrue(action1ResultMap.containsKey("param10"));
    assertTrue(action1ResultMap.containsKey("param11"));
    assertFalse(action1ResultMap.containsKey("param12"));
    assertEquals(action1ResultMap.get("param1"), "newValue1");
    assertEquals(action1ResultMap.get("param2"), "value2");
    assertEquals(action1ResultMap.get("param3"), "newValue3");
    assertEquals(action1ResultMap.get("param10"), "value10");
    assertEquals(action1ResultMap.get("param11"), "value11");
    assertEquals(action2ResultMap.size(), 3);
    assertTrue(action2ResultMap.containsKey("paramA"));
    assertTrue(action2ResultMap.containsKey("paramB"));
    assertTrue(action2ResultMap.containsKey("paramZ"));
    assertFalse(action2ResultMap.containsKey("paramY"));
    assertEquals(action2ResultMap.get("paramA"), "valueA");
    assertEquals(action2ResultMap.get("paramB"), "newValueB");
    assertEquals(action2ResultMap.get("paramZ"), "valueZ");
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) Map(java.util.Map) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 10 with ConfigurationProvider

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

the class XmlConfigurationProviderResultTypesTest method testPlainResultTypesParams.

public void testPlainResultTypesParams() throws Exception {
    ConfigurationProvider configurationProvider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-result-types.xml");
    PackageConfig packageConfig = configuration.getPackageConfig("xworkResultTypesTestPackage1");
    Map resultTypesConfigMap = packageConfig.getResultTypeConfigs();
    assertEquals(resultTypesConfigMap.size(), 2);
    assertTrue(resultTypesConfigMap.containsKey("result1"));
    assertTrue(resultTypesConfigMap.containsKey("result2"));
    assertFalse(resultTypesConfigMap.containsKey("result3"));
    ResultTypeConfig result1ResultTypeConfig = (ResultTypeConfig) resultTypesConfigMap.get("result1");
    Map result1ParamsMap = result1ResultTypeConfig.getParams();
    ResultTypeConfig result2ResultTypeConfig = (ResultTypeConfig) resultTypesConfigMap.get("result2");
    Map result2ParamsMap = result2ResultTypeConfig.getParams();
    assertEquals(result1ResultTypeConfig.getName(), "result1");
    assertEquals(result1ResultTypeConfig.getClassName(), MockResult.class.getName());
    assertEquals(result2ResultTypeConfig.getName(), "result2");
    assertEquals(result2ResultTypeConfig.getClassName(), MockResult.class.getName());
    assertEquals(result1ParamsMap.size(), 3);
    assertEquals(result2ParamsMap.size(), 2);
    assertTrue(result1ParamsMap.containsKey("param1"));
    assertTrue(result1ParamsMap.containsKey("param2"));
    assertTrue(result1ParamsMap.containsKey("param3"));
    assertFalse(result1ParamsMap.containsKey("param4"));
    assertTrue(result2ParamsMap.containsKey("paramA"));
    assertTrue(result2ParamsMap.containsKey("paramB"));
    assertFalse(result2ParamsMap.containsKey("paramC"));
    assertEquals(result1ParamsMap.get("param1"), "value1");
    assertEquals(result1ParamsMap.get("param2"), "value2");
    assertEquals(result1ParamsMap.get("param3"), "value3");
    assertEquals(result2ParamsMap.get("paramA"), "valueA");
    assertEquals(result2ParamsMap.get("paramB"), "valueB");
}
Also used : MockResult(com.opensymphony.xwork2.mock.MockResult) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) Map(java.util.Map) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Aggregations

ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)41 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)22 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)21 Map (java.util.Map)12 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)11 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)10 HashMap (java.util.HashMap)9 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)7 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)6 File (java.io.File)6 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)5 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)5 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)5 InterceptorStackConfig (com.opensymphony.xwork2.config.entities.InterceptorStackConfig)4 MockResult (com.opensymphony.xwork2.mock.MockResult)4 DefaultUnknownHandlerManager (com.opensymphony.xwork2.DefaultUnknownHandlerManager)3 SimpleAction (com.opensymphony.xwork2.SimpleAction)3 UnknownHandlerManager (com.opensymphony.xwork2.UnknownHandlerManager)3 Configuration (com.opensymphony.xwork2.config.Configuration)3 RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)3