use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.
the class XWorkTestCaseHelper method loadConfigurationProviders.
public static ConfigurationManager loadConfigurationProviders(ConfigurationManager configurationManager, ConfigurationProvider... providers) {
try {
tearDown(configurationManager);
} catch (Exception e) {
throw new RuntimeException("Cannot clean old configuration", e);
}
configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.addContainerProvider(new ContainerProvider() {
public void destroy() {
}
public void init(Configuration configuration) throws ConfigurationException {
}
public boolean needsReload() {
return false;
}
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.setAllowDuplicates(true);
}
});
configurationManager.addContainerProvider(new StrutsDefaultConfigurationProvider());
for (ConfigurationProvider prov : providers) {
if (prov instanceof XmlConfigurationProvider) {
((XmlConfigurationProvider) prov).setThrowExceptionOnDuplicateBeans(false);
}
configurationManager.addContainerProvider(prov);
}
Container container = configurationManager.getConfiguration().getContainer();
// Reset the value stack
ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
stack.getActionContext().withContainer(container).withValueStack(stack).bind();
return configurationManager;
}
use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.
the class PreResultListenerTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
loadConfigurationProviders(new ConfigurationProvider() {
Configuration configuration;
public void destroy() {
}
public void init(Configuration config) {
this.configuration = config;
}
public void loadPackages() {
PackageConfig packageConfig = new PackageConfig.Builder("package").addActionConfig("action", new ActionConfig.Builder("package", "action", SimpleFooAction.class.getName()).build()).build();
configuration.addPackageConfig("package", packageConfig);
}
/**
* Tells whether the ConfigurationProvider should reload its configuration
*/
public boolean needsReload() {
return false;
}
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class);
builder.factory(ObjectFactory.class);
}
});
}
use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.
the class XmlConfigurationProviderExceptionMappingsTest method testActions.
public void testActions() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-exception-mappings.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
List<ExceptionMappingConfig> exceptionMappings = new ArrayList<>();
HashMap<String, String> parameters = new HashMap<>();
HashMap<String, ResultConfig> results = new HashMap<>();
exceptionMappings.add(new ExceptionMappingConfig.Builder("spooky-result", "com.opensymphony.xwork2.SpookyException", "spooky-result").build());
results.put("spooky-result", new ResultConfig.Builder("spooky-result", MockResult.class.getName()).build());
Map<String, String> resultParams = new HashMap<>();
resultParams.put("actionName", "bar.vm");
results.put("specificLocationResult", new ResultConfig.Builder("specificLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
ActionConfig expectedAction = new ActionConfig.Builder("default", "Bar", SimpleAction.class.getName()).addParams(parameters).addResultConfigs(results).addExceptionMappings(exceptionMappings).build();
// execute the configuration
provider.init(configuration);
provider.loadPackages();
PackageConfig pkg = configuration.getPackageConfig("default");
Map actionConfigs = pkg.getActionConfigs();
// assertions
assertEquals(1, actionConfigs.size());
ActionConfig action = (ActionConfig) actionConfigs.get("Bar");
assertEquals(expectedAction, action);
}
use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.
the class XmlConfigurationProviderInterceptorsTest method testBasicInterceptors.
public void testBasicInterceptors() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-interceptors-basic.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
// setup expectations
// the test interceptor with a parameter
Map<String, String> params = new HashMap<>();
params.put("foo", "expectedFoo");
InterceptorConfig paramsInterceptor = new InterceptorConfig.Builder("test", MockInterceptor.class.getName()).addParams(params).build();
// the default interceptor stack
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();
// the derivative interceptor stack
InterceptorStackConfig derivativeStack = new InterceptorStackConfig.Builder("derivativeStack").addInterceptor(new InterceptorMapping("noop", objectFactory.buildInterceptor(noopInterceptor, new HashMap<String, String>()))).addInterceptor(new InterceptorMapping("test", objectFactory.buildInterceptor(mockInterceptor, params))).addInterceptor(new InterceptorMapping("logging", objectFactory.buildInterceptor(loggingInterceptor, new HashMap<String, String>()))).build();
// execute the configuration
provider.init(configuration);
provider.loadPackages();
PackageConfig pkg = configuration.getPackageConfig("default");
Map interceptorConfigs = pkg.getInterceptorConfigs();
// assertions for size
assertEquals(5, interceptorConfigs.size());
// assertions for interceptors
assertEquals(noopInterceptor, interceptorConfigs.get("noop"));
assertEquals(loggingInterceptor, interceptorConfigs.get("logging"));
assertEquals(paramsInterceptor, interceptorConfigs.get("test"));
// assertions for interceptor stacks
assertEquals(defaultStack, interceptorConfigs.get("defaultStack"));
assertEquals(derivativeStack, interceptorConfigs.get("derivativeStack"));
}
use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.
the class XmlConfigurationProviderInvalidFileTest method testInvalidFileThrowsException.
public void testInvalidFileThrowsException() {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-invalid-file.xml";
try {
ConfigurationProvider provider = buildConfigurationProvider(filename);
fail();
} catch (ConfigurationException e) {
// this is what we expect
}
}
Aggregations