Search in sources :

Example 46 with ConfigurationProvider

use of com.opensymphony.xwork2.config.ConfigurationProvider 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 47 with ConfigurationProvider

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

the class XmlConfigurationProviderPackagesTest method testBadInheritance.

public void testBadInheritance() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-bad-inheritance.xml";
    ConfigurationProvider provider = null;
    try {
        provider = buildConfigurationProvider(filename);
        fail("Should have thrown a ConfigurationException");
        provider.init(configuration);
        provider.loadPackages();
    } catch (ConfigurationException e) {
    // Expected
    }
}
Also used : ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider)

Example 48 with ConfigurationProvider

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

the class XmlConfigurationProviderPackagesTest method testDefaultClassRef.

public void testDefaultClassRef() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-defaultclassref-package.xml";
    final String hasDefaultClassRefPkgName = "hasDefaultClassRef";
    final String noDefaultClassRefPkgName = "noDefaultClassRef";
    final String testDefaultClassRef = "com.opensymphony.xwork2.ActionSupport";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    // setup our expectations
    PackageConfig expectedDefaultClassRefPackage = new PackageConfig.Builder(hasDefaultClassRefPkgName).defaultClassRef(testDefaultClassRef).build();
    PackageConfig expectedNoDefaultClassRefPackage = new PackageConfig.Builder(noDefaultClassRefPkgName).build();
    // test expectations
    assertEquals(2, configuration.getPackageConfigs().size());
    assertEquals(expectedDefaultClassRefPackage, configuration.getPackageConfig(hasDefaultClassRefPkgName));
    assertEquals(expectedNoDefaultClassRefPackage, configuration.getPackageConfig(noDefaultClassRefPkgName));
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 49 with ConfigurationProvider

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

the class XmlConfigurationProviderPackagesTest method testBasicPackages.

public void testBasicPackages() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-basic-packages.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    provider.loadPackages();
    // setup our expectations
    PackageConfig expectedNamespacePackage = new PackageConfig.Builder("namespacepkg").namespace("/namespace/set").isAbstract(false).build();
    PackageConfig expectedAbstractPackage = new PackageConfig.Builder("abstractpkg").isAbstract(true).build();
    // test expectations
    assertEquals(3, configuration.getPackageConfigs().size());
    assertEquals(expectedNamespacePackage, configuration.getPackageConfig("namespacepkg"));
    assertEquals(expectedAbstractPackage, configuration.getPackageConfig("abstractpkg"));
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 50 with ConfigurationProvider

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

the class ConfigurationTestBase method buildConfigurationProvider.

protected ConfigurationProvider buildConfigurationProvider(final String filename) {
    configuration = new MockConfiguration();
    ((MockConfiguration) configuration).selfRegister();
    container = configuration.getContainer();
    XmlConfigurationProvider prov = new StrutsXmlConfigurationProvider(filename);
    container.inject(prov);
    prov.init(configuration);
    prov.loadPackages();
    return prov;
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) MockConfiguration(com.opensymphony.xwork2.config.impl.MockConfiguration)

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