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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations