Search in sources :

Example 6 with RuntimeConfiguration

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

the class XmlConfigurationProviderTest method testInheritence.

public void testInheritence() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-include-parent.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    provider.loadPackages();
    // test expectations
    assertEquals(6, configuration.getPackageConfigs().size());
    PackageConfig defaultPackage = configuration.getPackageConfig("default");
    assertNotNull(defaultPackage);
    assertEquals("default", defaultPackage.getName());
    PackageConfig namespace1 = configuration.getPackageConfig("namespace1");
    assertNotNull(namespace1);
    assertEquals("namespace1", namespace1.getName());
    assertEquals(defaultPackage, namespace1.getParents().get(0));
    PackageConfig namespace2 = configuration.getPackageConfig("namespace2");
    assertNotNull(namespace2);
    assertEquals("namespace2", namespace2.getName());
    assertEquals(1, namespace2.getParents().size());
    assertEquals(namespace1, namespace2.getParents().get(0));
    PackageConfig namespace4 = configuration.getPackageConfig("namespace4");
    assertNotNull(namespace4);
    assertEquals("namespace4", namespace4.getName());
    assertEquals(1, namespace4.getParents().size());
    assertEquals(namespace1, namespace4.getParents().get(0));
    PackageConfig namespace5 = configuration.getPackageConfig("namespace5");
    assertNotNull(namespace5);
    assertEquals("namespace5", namespace5.getName());
    assertEquals(1, namespace5.getParents().size());
    assertEquals(namespace4, namespace5.getParents().get(0));
    configurationManager.addContainerProvider(provider);
    configurationManager.reload();
    RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace1", "action1"));
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace2", "action2"));
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace4", "action4"));
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace5", "action5"));
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 7 with RuntimeConfiguration

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

the class ConfigurationTest method testWildcardNamespace.

public void testWildcardNamespace() {
    RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
    ActionConfig config = configuration.getActionConfig("/animals/dog", "commandTest");
    assertNotNull(config);
    assertTrue("Wrong class name, " + config.getClassName(), "com.opensymphony.xwork2.SimpleAction".equals(config.getClassName()));
    Map<String, String> p = config.getParams();
    assertTrue("Wrong parameter, " + p.get("0"), "/animals/dog".equals(p.get("0")));
    assertTrue("Wrong parameter, " + p.get("1"), "dog".equals(p.get("1")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

Example 8 with RuntimeConfiguration

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

the class ConventionUnknownHandlerTest method configuration.

private Configuration configuration(final String packageName) {
    final Configuration mock = createNiceMock(Configuration.class);
    packageConfiguration = packageConfiguration();
    expect(mock.getPackageConfig(packageName)).andStubReturn(packageConfiguration);
    RuntimeConfiguration runtime = createNiceMock(RuntimeConfiguration.class);
    expect(runtime.getActionConfig("", "index")).andStubReturn(new ActionConfig.Builder("", "index", "").build());
    expect(mock.getRuntimeConfiguration()).andStubReturn(runtime);
    replay(mock, runtime);
    return mock;
}
Also used : Configuration(com.opensymphony.xwork2.config.Configuration) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 9 with RuntimeConfiguration

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

the class Form method isValidateAnnotatedMethodOnly.

private boolean isValidateAnnotatedMethodOnly(String actionName) {
    RuntimeConfiguration runtimeConfiguration = configuration.getRuntimeConfiguration();
    String actionNamespace = TagUtils.buildNamespace(actionMapper, stack, request);
    ActionConfig actionConfig = runtimeConfiguration.getActionConfig(actionNamespace, actionName);
    if (actionConfig != null) {
        List<InterceptorMapping> interceptors = actionConfig.getInterceptors();
        for (InterceptorMapping interceptorMapping : interceptors) {
            if (ValidationInterceptor.class.isInstance(interceptorMapping.getInterceptor())) {
                ValidationInterceptor validationInterceptor = (ValidationInterceptor) interceptorMapping.getInterceptor();
                return validationInterceptor.isValidateAnnotatedMethodOnly();
            }
        }
    }
    return false;
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 10 with RuntimeConfiguration

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

the class ConfigurationTest method testWildcardName.

public void testWildcardName() {
    RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
    ActionConfig config = configuration.getActionConfig("", "WildCard/Simple/input");
    assertNotNull(config);
    assertTrue("Wrong class name, " + config.getClassName(), "com.opensymphony.xwork2.SimpleAction".equals(config.getClassName()));
    assertTrue("Wrong method name", "input".equals(config.getMethodName()));
    Map<String, String> p = config.getParams();
    assertTrue("Wrong parameter, " + p.get("foo"), "Simple".equals(p.get("foo")));
    assertTrue("Wrong parameter, " + p.get("bar"), "input".equals(p.get("bar")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

Aggregations

RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)10 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)9 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)6 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)6 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)3 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)2 ContainerProvider (com.opensymphony.xwork2.config.ContainerProvider)2 DefaultConfiguration (com.opensymphony.xwork2.config.impl.DefaultConfiguration)2 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)2 DefaultFileManager (com.opensymphony.xwork2.util.fs.DefaultFileManager)2 DefaultFileManagerFactory (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory)2 ArrayList (java.util.ArrayList)2 Mock (com.mockobjects.dynamic.Mock)1 SimpleAction (com.opensymphony.xwork2.SimpleAction)1 Configuration (com.opensymphony.xwork2.config.Configuration)1 InterceptorStackConfig (com.opensymphony.xwork2.config.entities.InterceptorStackConfig)1 MockConfigurationProvider (com.opensymphony.xwork2.config.providers.MockConfigurationProvider)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1