Search in sources :

Example 51 with ConfigurationProvider

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

the class XmlConfigurationProviderActionsTest method testInvalidActions.

public void testInvalidActions() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-action-invalid.xml";
    try {
        ConfigurationProvider provider = buildConfigurationProvider(filename);
        fail("Should have thrown an exception");
    } catch (ConfigurationException ex) {
    // it worked correctly
    }
}
Also used : ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider)

Example 52 with ConfigurationProvider

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

the class XmlConfigurationProviderActionsTest method testPackageDefaultClassRef.

public void testPackageDefaultClassRef() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions-packagedefaultclassref.xml";
    final String testDefaultClassName = "com.opensymphony.xwork2.UserSpecifiedDefaultAction";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    // setup expectations
    params.put("foo", "17");
    params.put("bar", "23");
    ActionConfig barWithPackageDefaultClassRefConfig = new ActionConfig.Builder("", "Bar", "").addParams(params).build();
    // execute the configuration
    provider.init(configuration);
    PackageConfig pkg = configuration.getPackageConfig("default");
    Map actionConfigs = pkg.getActionConfigs();
    // assertions
    assertEquals(1, actionConfigs.size());
    assertEquals(barWithPackageDefaultClassRefConfig, actionConfigs.get("Bar"));
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) Map(java.util.Map) HashMap(java.util.HashMap)

Example 53 with ConfigurationProvider

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

the class XmlConfigurationProviderAllowedMethodsTest method testDefaultAllowedMethods.

public void testDefaultAllowedMethods() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-allowed-methods.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    // execute the configuration
    provider.init(configuration);
    provider.loadPackages();
    PackageConfig pkg = configuration.getPackageConfig("default");
    Map actionConfigs = pkg.getActionConfigs();
    // assertions
    assertEquals(5, actionConfigs.size());
    ActionConfig action = (ActionConfig) actionConfigs.get("Default");
    assertEquals(1, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertTrue(action.isAllowedMethod("foo"));
    assertTrue(action.isAllowedMethod("bar"));
    assertTrue(action.isAllowedMethod("baz"));
    assertTrue(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Boring");
    assertEquals(2, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertFalse(action.isAllowedMethod("foo"));
    assertFalse(action.isAllowedMethod("bar"));
    assertFalse(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Foo");
    assertEquals(3, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertTrue(action.isAllowedMethod("foo"));
    assertFalse(action.isAllowedMethod("bar"));
    assertFalse(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Bar");
    assertEquals(4, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertTrue(action.isAllowedMethod("foo"));
    assertTrue(action.isAllowedMethod("bar"));
    assertFalse(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Baz");
    assertEquals(5, action.getAllowedMethods().size());
    assertFalse(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertTrue(action.isAllowedMethod("foo"));
    assertTrue(action.isAllowedMethod("bar"));
    assertTrue(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) Map(java.util.Map) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 54 with ConfigurationProvider

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

the class XmlConfigurationProviderAllowedMethodsTest method testStrictAllowedMethods.

public void testStrictAllowedMethods() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-allowed-methods.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    // execute the configuration
    provider.init(configuration);
    provider.loadPackages();
    PackageConfig pkg = configuration.getPackageConfig("strict");
    Map actionConfigs = pkg.getActionConfigs();
    // assertions
    assertEquals(5, actionConfigs.size());
    ActionConfig action = (ActionConfig) actionConfigs.get("Default");
    assertEquals(2, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertFalse(action.isAllowedMethod("foo"));
    assertFalse(action.isAllowedMethod("bar"));
    assertFalse(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Boring");
    assertEquals(2, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertFalse(action.isAllowedMethod("foo"));
    assertFalse(action.isAllowedMethod("bar"));
    assertFalse(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Foo");
    assertEquals(3, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertTrue(action.isAllowedMethod("foo"));
    assertFalse(action.isAllowedMethod("bar"));
    assertFalse(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Bar");
    assertEquals(4, action.getAllowedMethods().size());
    assertTrue(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertTrue(action.isAllowedMethod("foo"));
    assertTrue(action.isAllowedMethod("bar"));
    assertFalse(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
    action = (ActionConfig) actionConfigs.get("Baz");
    assertEquals(5, action.getAllowedMethods().size());
    assertFalse(action.isAllowedMethod("execute"));
    assertTrue(action.isAllowedMethod("input"));
    assertTrue(action.isAllowedMethod("cancel"));
    assertTrue(action.isAllowedMethod("foo"));
    assertTrue(action.isAllowedMethod("bar"));
    assertTrue(action.isAllowedMethod("baz"));
    assertFalse(action.isAllowedMethod("xyz"));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) 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