Search in sources :

Example 41 with ConfigurationProvider

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

the class XmlConfigurationProviderTest method testNeedsReload.

public void testNeedsReload() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
    ConfigurationProvider provider = new StrutsXmlConfigurationProvider(filename);
    container.inject(provider);
    provider.init(configuration);
    provider.loadPackages();
    container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
    // 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);
    assertTrue(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)

Example 42 with ConfigurationProvider

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

the class XmlConfigurationProviderUnknownHandlerStackTest method testStackWithElements.

public void testStackWithElements() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-unknownhandler-stack.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    loadConfigurationProviders(provider);
    configurationManager.reload();
    List<UnknownHandlerConfig> unknownHandlerStack = configuration.getUnknownHandlerStack();
    assertNotNull(unknownHandlerStack);
    assertEquals(2, unknownHandlerStack.size());
    assertEquals("uh1", unknownHandlerStack.get(0).getName());
    assertEquals("uh2", unknownHandlerStack.get(1).getName());
    UnknownHandlerManager unknownHandlerManager = new DefaultUnknownHandlerManager();
    container.inject(unknownHandlerManager);
    assertTrue(unknownHandlerManager.hasUnknownHandlers());
}
Also used : UnknownHandlerConfig(com.opensymphony.xwork2.config.entities.UnknownHandlerConfig) DefaultUnknownHandlerManager(com.opensymphony.xwork2.DefaultUnknownHandlerManager) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) DefaultUnknownHandlerManager(com.opensymphony.xwork2.DefaultUnknownHandlerManager) UnknownHandlerManager(com.opensymphony.xwork2.UnknownHandlerManager)

Example 43 with ConfigurationProvider

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

the class XmlConfigurationProviderGlobalResultInheritenceTest method testGlobalResultInheritenceTest.

public void testGlobalResultInheritenceTest() throws Exception {
    ConfigurationProvider provider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-global-result-inheritence.xml");
    ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
    configurationManager.addContainerProvider(new StrutsDefaultConfigurationProvider());
    configurationManager.addContainerProvider(provider);
    Configuration configuration = configurationManager.getConfiguration();
    ActionConfig parentActionConfig = configuration.getRuntimeConfiguration().getActionConfig("/base", "parentAction");
    ActionConfig anotherActionConfig = configuration.getRuntimeConfiguration().getActionConfig("/base", "anotherAction");
    ActionConfig childActionConfig = configuration.getRuntimeConfiguration().getActionConfig("/base", "childAction");
    ResultConfig parentResultConfig1 = parentActionConfig.getResults().get("mockResult1");
    ResultConfig parentResultConfig2 = parentActionConfig.getResults().get("mockResult2");
    ResultConfig anotherResultConfig1 = anotherActionConfig.getResults().get("mockResult1");
    ResultConfig anotherResultConfig2 = anotherActionConfig.getResults().get("mockResult2");
    ResultConfig childResultConfig1 = childActionConfig.getResults().get("mockResult1");
    ResultConfig childResultConfig2 = childActionConfig.getResults().get("mockResult2");
    System.out.println(parentResultConfig1.getParams().get("identity"));
    System.out.println(parentResultConfig2.getParams().get("identity"));
    System.out.println(anotherResultConfig1.getParams().get("identity"));
    System.out.println(anotherResultConfig2.getParams().get("identity"));
    System.out.println(childResultConfig1.getParams().get("identity"));
    System.out.println(childResultConfig2.getParams().get("identity"));
    assertFalse(parentResultConfig1 == anotherResultConfig1);
    assertFalse(parentResultConfig2 == anotherResultConfig2);
    assertFalse(parentResultConfig1 == childResultConfig1);
    assertTrue(parentResultConfig2 == childResultConfig2);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) Configuration(com.opensymphony.xwork2.config.Configuration) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) ConfigurationManager(com.opensymphony.xwork2.config.ConfigurationManager)

Example 44 with ConfigurationProvider

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

the class XmlConfigurationProviderInterceptorsSpringTest method testInterceptorsLoadedFromSpringApplicationContext.

public void testInterceptorsLoadedFromSpringApplicationContext() throws ConfigurationException {
    sac.registerSingleton("noop-interceptor", NoOpInterceptor.class, new MutablePropertyValues());
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-interceptors-spring.xml";
    // Expect a ConfigurationException to be thrown if the interceptor reference
    // cannot be resolved
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    // execute the configuration
    provider.init(configuration);
    provider.loadPackages();
    PackageConfig pkg = configuration.getPackageConfig("default");
    Map interceptorConfigs = pkg.getInterceptorConfigs();
    // assertions for size
    assertEquals(1, interceptorConfigs.size());
    // assertions for interceptors
    InterceptorConfig seen = (InterceptorConfig) interceptorConfigs.get("noop");
    assertEquals("noop-interceptor", seen.getClassName());
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) InterceptorConfig(com.opensymphony.xwork2.config.entities.InterceptorConfig) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Map(java.util.Map) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 45 with ConfigurationProvider

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

the class XmlConfigurationProviderInterceptorsTest method testInterceptorParamOverriding.

public void testInterceptorParamOverriding() throws Exception {
    Map<String, String> params = new HashMap<>();
    params.put("foo", "expectedFoo");
    params.put("expectedFoo", "expectedFooValue");
    InterceptorStackConfig defaultStack = new InterceptorStackConfig.Builder("defaultStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))).build();
    ArrayList<InterceptorMapping> interceptors = new ArrayList<>();
    interceptors.addAll(defaultStack.getInterceptors());
    ActionConfig intAction = new ActionConfig.Builder("", "TestInterceptorParam", SimpleAction.class.getName()).addInterceptors(interceptors).build();
    // TestInterceptorParamOverride action tests that an interceptor with a param override worked
    HashMap<String, String> interceptorParams = new HashMap<>();
    interceptorParams.put("expectedFoo", "expectedFooValue2");
    interceptorParams.put("foo", "foo123");
    InterceptorStackConfig defaultStack2 = new InterceptorStackConfig.Builder("defaultStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, interceptorParams))).build();
    interceptors = new ArrayList<>();
    interceptors.addAll(defaultStack2.getInterceptors());
    ActionConfig intOverAction = new ActionConfig.Builder("", "TestInterceptorParamOverride", SimpleAction.class.getName()).addInterceptors(interceptors).build();
    ConfigurationProvider provider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-params.xml");
    PackageConfig pkg = configuration.getPackageConfig("default");
    Map actionConfigs = pkg.getActionConfigs();
    // assertions
    assertEquals(2, actionConfigs.size());
    assertEquals(intAction, actionConfigs.get("TestInterceptorParam"));
    assertEquals(intOverAction, actionConfigs.get("TestInterceptorParamOverride"));
    ActionConfig ac = (ActionConfig) actionConfigs.get("TestInterceptorParamOverride");
    assertEquals(defaultStack.getInterceptors(), ac.getInterceptors());
    ActionConfig ac2 = (ActionConfig) actionConfigs.get("TestInterceptorParam");
    assertEquals(defaultStack2.getInterceptors(), ac2.getInterceptors());
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) HashMap(java.util.HashMap) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) ArrayList(java.util.ArrayList) SimpleAction(com.opensymphony.xwork2.SimpleAction) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) InterceptorStackConfig(com.opensymphony.xwork2.config.entities.InterceptorStackConfig) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) HashMap(java.util.HashMap) Map(java.util.Map)

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