use of com.opensymphony.xwork2.config.impl.DefaultConfiguration in project struts by apache.
the class XmlConfigurationProviderInterceptorParamOverridingTest method testInterceptorParamOveriding.
public void testInterceptorParamOveriding() throws Exception {
DefaultConfiguration conf = new DefaultConfiguration();
final XmlConfigurationProvider p = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-param-overriding.xml");
DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
factory.setContainer(container);
factory.setFileManager(new DefaultFileManager());
p.setFileManagerFactory(factory);
conf.reloadContainer(new ArrayList<ContainerProvider>() {
{
add(new StrutsDefaultConfigurationProvider());
add(p);
}
});
RuntimeConfiguration rtConf = conf.getRuntimeConfiguration();
ActionConfig actionOne = rtConf.getActionConfig("", "actionOne");
ActionConfig actionTwo = rtConf.getActionConfig("", "actionTwo");
List<InterceptorMapping> actionOneInterceptors = actionOne.getInterceptors();
List<InterceptorMapping> actionTwoInterceptors = actionTwo.getInterceptors();
assertNotNull(actionOne);
assertNotNull(actionTwo);
assertNotNull(actionOneInterceptors);
assertNotNull(actionTwoInterceptors);
assertEquals(actionOneInterceptors.size(), 3);
assertEquals(actionTwoInterceptors.size(), 3);
InterceptorMapping actionOneInterceptorMapping1 = actionOneInterceptors.get(0);
InterceptorMapping actionOneInterceptorMapping2 = actionOneInterceptors.get(1);
InterceptorMapping actionOneInterceptorMapping3 = actionOneInterceptors.get(2);
InterceptorMapping actionTwoInterceptorMapping1 = actionTwoInterceptors.get(0);
InterceptorMapping actionTwoInterceptorMapping2 = actionTwoInterceptors.get(1);
InterceptorMapping actionTwoInterceptorMapping3 = actionTwoInterceptors.get(2);
assertNotNull(actionOneInterceptorMapping1);
assertNotNull(actionOneInterceptorMapping2);
assertNotNull(actionOneInterceptorMapping3);
assertNotNull(actionTwoInterceptorMapping1);
assertNotNull(actionTwoInterceptorMapping2);
assertNotNull(actionTwoInterceptorMapping3);
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
}
use of com.opensymphony.xwork2.config.impl.DefaultConfiguration in project struts by apache.
the class XmlConfigurationProviderInterceptorStackParamOverridingTest method testInterceptorStackParamOveriding.
public void testInterceptorStackParamOveriding() throws Exception {
DefaultConfiguration conf = new DefaultConfiguration();
final XmlConfigurationProvider p = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-stack-param-overriding.xml");
DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
factory.setContainer(container);
factory.setFileManager(new DefaultFileManager());
p.setFileManagerFactory(factory);
configurationManager.addContainerProvider(p);
conf.reloadContainer(new ArrayList<ContainerProvider>() {
{
add(new StrutsDefaultConfigurationProvider());
add(p);
}
});
RuntimeConfiguration rtConf = conf.getRuntimeConfiguration();
ActionConfig actionOne = rtConf.getActionConfig("", "actionOne");
ActionConfig actionTwo = rtConf.getActionConfig("", "actionTwo");
List actionOneInterceptors = actionOne.getInterceptors();
List actionTwoInterceptors = actionTwo.getInterceptors();
assertNotNull(actionOne);
assertNotNull(actionTwo);
assertNotNull(actionOneInterceptors);
assertNotNull(actionTwoInterceptors);
assertEquals(actionOneInterceptors.size(), 3);
assertEquals(actionTwoInterceptors.size(), 3);
InterceptorMapping actionOneInterceptorMapping1 = (InterceptorMapping) actionOneInterceptors.get(0);
InterceptorMapping actionOneInterceptorMapping2 = (InterceptorMapping) actionOneInterceptors.get(1);
InterceptorMapping actionOneInterceptorMapping3 = (InterceptorMapping) actionOneInterceptors.get(2);
InterceptorMapping actionTwoInterceptorMapping1 = (InterceptorMapping) actionTwoInterceptors.get(0);
InterceptorMapping actionTwoInterceptorMapping2 = (InterceptorMapping) actionTwoInterceptors.get(1);
InterceptorMapping actionTwoInterceptorMapping3 = (InterceptorMapping) actionTwoInterceptors.get(2);
assertNotNull(actionOneInterceptorMapping1);
assertNotNull(actionOneInterceptorMapping2);
assertNotNull(actionOneInterceptorMapping3);
assertNotNull(actionTwoInterceptorMapping1);
assertNotNull(actionTwoInterceptorMapping2);
assertNotNull(actionTwoInterceptorMapping3);
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
}
use of com.opensymphony.xwork2.config.impl.DefaultConfiguration in project struts by apache.
the class BundlePackageLoader method loadPackages.
@Deprecated
@Override
public List<PackageConfig> loadPackages(Bundle bundle, BundleContext bundleContext, ObjectFactory objectFactory, FileManagerFactory fileManagerFactory, Map<String, PackageConfig> pkgConfigs) throws ConfigurationException {
if (pkgConfigs == null) {
// Better than a NPE.
throw new IllegalArgumentException("Cannot load packages from a null package configuration");
}
Configuration config = new DefaultConfiguration("struts.xml");
LOG.trace("LoadPackages - After config constructed. Before BundleConfigurationProvider constructed");
BundleConfigurationProvider prov = new BundleConfigurationProvider("struts.xml", bundle, bundleContext);
LOG.trace("LoadPackages - After BundleConfigurationProvider constructed. Before config.addPackageConfig loop");
pkgConfigs.values().forEach(pkg -> {
config.addPackageConfig(pkg.getName(), pkg);
});
LOG.trace("LoadPackages - After config.addPackageConfig loop. Before prov.setObjectFactory()");
prov.setObjectFactory(objectFactory);
if (fileManagerFactory == null || fileManagerFactory.getFileManager() == null) {
LOG.warn("LoadPackages - FileManagerFactory parameter is null or produces a null FileManager, replacing with a new DefaultFileManagerFactory instance");
final DefaultFileManagerFactory defaultFileManagerFactory = new DefaultFileManagerFactory();
final Container container = getContextContainer();
if (container == null) {
LOG.warn("LoadPackages - Config Container is null. May cause a NPE to be thrown");
} else {
// Apply configuration (including the container reference) to the DefaultFileManagerFactory instance.
container.inject(defaultFileManagerFactory);
}
prov.setFileManagerFactory(defaultFileManagerFactory);
} else {
prov.setFileManagerFactory(fileManagerFactory);
}
LOG.trace("LoadPackages - After prov.setFileManagerFactory(). Before init()");
prov.init(config);
LOG.trace("LoadPackages - After prov.init(). Before loadPackages()");
prov.loadPackages();
LOG.trace("LoadPackages - After prov.loadPackages(). Before config.getPackageConfigs().values()");
List<PackageConfig> list = new ArrayList<>(config.getPackageConfigs().values());
LOG.trace("LoadPackages - After config.getPackageConfigs(). Before pkgConfigs.values()");
list.removeAll(pkgConfigs.values());
return list;
}
use of com.opensymphony.xwork2.config.impl.DefaultConfiguration in project struts by apache.
the class RestActionMapperTest method setUp.
protected void setUp() throws Exception {
super.setUp();
req = new MockHttpServletRequest();
req.setContextPath("/myapp");
req.setMethod("GET");
mapper = new RestActionMapper();
config = new DefaultConfiguration();
PackageConfig pkg = new PackageConfig.Builder("myns").namespace("/animals").build();
PackageConfig pkg2 = new PackageConfig.Builder("my").namespace("/my").build();
config.addPackageConfig("mvns", pkg);
config.addPackageConfig("my", pkg2);
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
public Configuration getConfiguration() {
return config;
}
};
}
use of com.opensymphony.xwork2.config.impl.DefaultConfiguration in project struts by apache.
the class Restful2ActionMapperTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
mapper = new Restful2ActionMapper();
mapper.setExtensions("");
req = new MockHttpServletRequest();
req.setupGetParameterMap(new HashMap());
req.setupGetContextPath("/my/namespace");
config = new DefaultConfiguration();
PackageConfig pkg = new PackageConfig.Builder("myns").namespace("/my/namespace").build();
PackageConfig pkg2 = new PackageConfig.Builder("my").namespace("/my").build();
config.addPackageConfig("mvns", pkg);
config.addPackageConfig("my", pkg2);
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
public Configuration getConfiguration() {
return config;
}
};
}
Aggregations