Search in sources :

Example 11 with ConfigurationProvider

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

the class XmlConfigurationProviderResultsTest method testResultInheritance.

public void testResultInheritance() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-result-inheritance.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    // expectations
    provider.init(configuration);
    provider.loadPackages();
    // assertions
    PackageConfig subPkg = configuration.getPackageConfig("subPackage");
    assertEquals(1, subPkg.getResultTypeConfigs().size());
    assertEquals(3, subPkg.getAllResultTypeConfigs().size());
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 12 with ConfigurationProvider

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

the class XmlConfigurationProviderTest method testEmptySpacesNotReloadingConfigs.

public void testEmptySpacesNotReloadingConfigs() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml";
    buildConfigurationProvider(filename);
    ConfigurationProvider provider = new StrutsXmlConfigurationProvider(filename);
    container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(false);
    container.inject(provider);
    provider.init(configuration);
    provider.loadPackages();
    assertFalse(provider.needsReload());
    URI uri = ClassLoaderUtil.getResource(filename, ConfigurationProvider.class).toURI();
    File file = new File(uri);
    assertTrue(file.exists());
    changeFileTime(filename, file);
    assertFalse(provider.needsReload());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) URI(java.net.URI) File(java.io.File)

Example 13 with ConfigurationProvider

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

the class XmlConfigurationProviderTest method testReload.

public void testReload() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-reload.xml";
    ConfigurationProvider provider = new StrutsXmlConfigurationProvider(filename);
    loadConfigurationProviders(provider);
    // Revision exists and timestamp didn't change
    assertFalse(provider.needsReload());
    File file = new File(getClass().getResource("/" + filename).toURI());
    assertTrue("not exists: " + file.toString(), file.exists());
    Path configPath = Paths.get(file.getAbsolutePath());
    String content = new String(Files.readAllBytes(configPath));
    content = content.replaceAll("<constant name=\"struts.configuration.xml.reload\" value=\"true\" />", "<constant name=\"struts.configuration.xml.reload\" value=\"false\" />");
    // user demand: stop reloading configs
    Files.write(configPath, content.getBytes());
    try {
        // config file has changed in previous lines
        assertTrue(provider.needsReload());
        configurationManager.reload();
        changeFileTime(filename, file);
        // user already has stopped reloading configs
        assertFalse(provider.needsReload());
    } finally {
        content = content.replaceAll("<constant name=\"struts.configuration.xml.reload\" value=\"false\" />", "<constant name=\"struts.configuration.xml.reload\" value=\"true\" />");
        Files.write(configPath, content.getBytes());
    }
}
Also used : Path(java.nio.file.Path) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) File(java.io.File)

Example 14 with ConfigurationProvider

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

the class XmlConfigurationProviderTest method testEmptySpaces.

public void testEmptySpaces() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml";
    ConfigurationProvider provider = new StrutsXmlConfigurationProvider(filename);
    container.inject(provider);
    provider.init(configuration);
    provider.loadPackages();
    container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
    assertFalse(provider.needsReload());
    URI uri = ClassLoaderUtil.getResource(filename, ConfigurationProvider.class).toURI();
    File file = new File(uri);
    assertTrue(file.exists());
    changeFileTime(filename, file);
    assertTrue(provider.needsReload());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) URI(java.net.URI) File(java.io.File)

Example 15 with ConfigurationProvider

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

the class XmlConfigurationProviderTest method testNeedsReloadNotReloadingConfigs.

public void testNeedsReloadNotReloadingConfigs() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
    buildConfigurationProvider(filename);
    ConfigurationProvider provider = new StrutsXmlConfigurationProvider(filename);
    container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(false);
    container.inject(provider);
    provider.init(configuration);
    provider.loadPackages();
    // Revision exists and timestamp didn't change
    assertFalse(provider.needsReload());
    File file = new File(getClass().getResource("/" + filename).toURI());
    assertTrue("not exists: " + file.toString(), file.exists());
    changeFileTime(filename, file);
    assertFalse(provider.needsReload());
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) File(java.io.File)

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