use of com.opensymphony.xwork2.config.RuntimeConfiguration in project struts-examples by apache.
the class ConfigTest method assertClass.
protected ActionConfig assertClass(String namespace, String action_name, String class_name) {
RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
ActionConfig config = configuration.getActionConfig(namespace, action_name);
assertNotNull("Mssing action", config);
assertEquals("Wrong class name: [" + config.getClassName() + "]", class_name, config.getClassName());
return config;
}
use of com.opensymphony.xwork2.config.RuntimeConfiguration in project struts by apache.
the class Form method evaluateClientSideJsEnablement.
/**
* Evaluate client side JavaScript Enablement.
* @param actionName the actioName to check for
* @param namespace the namespace to check for
* @param actionMethod the method to ckeck for
*/
protected void evaluateClientSideJsEnablement(String actionName, String namespace, String actionMethod) {
// Only evaluate if Client-Side js is to be enable when validate=true
Boolean validate = (Boolean) getParameters().get("validate");
if (validate != null && validate) {
addParameter("performValidation", Boolean.FALSE);
RuntimeConfiguration runtimeConfiguration = configuration.getRuntimeConfiguration();
ActionConfig actionConfig = runtimeConfiguration.getActionConfig(namespace, actionName);
if (actionConfig != null) {
List<InterceptorMapping> interceptors = actionConfig.getInterceptors();
for (InterceptorMapping interceptorMapping : interceptors) {
if (ValidationInterceptor.class.isInstance(interceptorMapping.getInterceptor())) {
ValidationInterceptor validationInterceptor = (ValidationInterceptor) interceptorMapping.getInterceptor();
Set excludeMethods = validationInterceptor.getExcludeMethodsSet();
Set includeMethods = validationInterceptor.getIncludeMethodsSet();
if (MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, actionMethod)) {
addParameter("performValidation", Boolean.TRUE);
}
return;
}
}
}
}
}
use of com.opensymphony.xwork2.config.RuntimeConfiguration 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.RuntimeConfiguration 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.RuntimeConfiguration in project struts by apache.
the class XmlConfigurationProviderPackagesTest method testPackageInheritance.
public void testPackageInheritance() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-package-inheritance.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
provider.init(configuration);
provider.loadPackages();
// test expectations
assertEquals(5, configuration.getPackageConfigs().size());
PackageConfig defaultPackage = configuration.getPackageConfig("default");
assertNotNull(defaultPackage);
assertEquals("default", defaultPackage.getName());
PackageConfig abstractPackage = configuration.getPackageConfig("abstractPackage");
assertNotNull(abstractPackage);
assertEquals("abstractPackage", abstractPackage.getName());
PackageConfig singlePackage = configuration.getPackageConfig("singleInheritance");
assertNotNull(singlePackage);
assertEquals("singleInheritance", singlePackage.getName());
assertEquals(1, singlePackage.getParents().size());
assertEquals(defaultPackage, singlePackage.getParents().get(0));
PackageConfig multiplePackage = configuration.getPackageConfig("multipleInheritance");
assertNotNull(multiplePackage);
assertEquals("multipleInheritance", multiplePackage.getName());
assertEquals(3, multiplePackage.getParents().size());
List<PackageConfig> multipleParents = multiplePackage.getParents();
assertTrue(multipleParents.contains(defaultPackage));
assertTrue(multipleParents.contains(abstractPackage));
assertTrue(multipleParents.contains(singlePackage));
PackageConfig parentBelow = configuration.getPackageConfig("testParentBelow");
assertEquals(1, parentBelow.getParents().size());
List<PackageConfig> parentBelowParents = parentBelow.getParents();
assertTrue(parentBelowParents.contains(multiplePackage));
configurationManager.addContainerProvider(provider);
configurationManager.reload();
RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "default"));
assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "abstract"));
assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "single"));
assertNotNull(runtimeConfiguration.getActionConfig("/multiple", "multiple"));
assertNotNull(runtimeConfiguration.getActionConfig("/single", "default"));
assertNull(runtimeConfiguration.getActionConfig("/single", "abstract"));
assertNotNull(runtimeConfiguration.getActionConfig("/single", "single"));
assertNull(runtimeConfiguration.getActionConfig("/single", "multiple"));
assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "default"));
assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "abstract"));
assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "single"));
assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "multiple"));
assertNotNull(runtimeConfiguration.getActionConfig("/parentBelow", "testParentBelowAction"));
}
Aggregations