use of com.opensymphony.xwork2.Result in project struts by apache.
the class XmlConfigurationProviderResultsTest method testResultInheritance.
public void testResultInheritance() throws ConfigurationException {
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-result-inheritance.xml";
ConfigurationProvider provider = buildConfigurationProvider(filename);
// expectations
provider.init(configuration);
provider.loadPackages();
// assertions
PackageConfig subPkg = configuration.getPackageConfig("subPackage");
assertEquals(1, subPkg.getResultTypeConfigs().size());
assertEquals(3, subPkg.getAllResultTypeConfigs().size());
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class XmlConfigurationProviderTest method testBuildResults.
/**
* Test buildResults() to ensure consistent results for processing
* <result/> in <action/> XML configuration elements.
*
* @throws Exception
*/
public void testBuildResults() throws Exception {
// Set up test using two mock DOM Elements:
// 1) A mock "action" Element with a two "result" child Elements that each contains a single
// TEXT_NODE Node. This simulates a typical result from a SAX parser parsing the result
// tag body.
// 2) A mock "action" Element with two "result" child Elements that each contain multiple
// TEXT_NODE Nodes. This simulates an unusal result from a SAX parser parsing the result
// tag body.
final String fakeBodyString = "/SomePath/SomePath/SomePath/SomeJSP.jsp";
final String fakeBodyString2 = "/SomePath2/SomePath2/SomePath2/SomeJSP2.jsp";
final String resultParam = "nonNullDefaultParam";
PackageConfig.Builder testPackageConfigBuilder = new PackageConfig.Builder("resultsPackage");
ResultTypeConfig.Builder resultTypeConfigBuilder = new ResultTypeConfig.Builder("dispatcher", ServletDispatcherResult.class.getName());
resultTypeConfigBuilder.defaultResultParam(resultParam);
ResultTypeConfig resultTypeConfig = resultTypeConfigBuilder.build();
testPackageConfigBuilder.addResultTypeConfig(resultTypeConfig);
List<String> singleStringList = new ArrayList<>(1);
List<String> singleStringList2 = new ArrayList<>(1);
List<String> multipleStringList = new ArrayList<>(4);
List<String> multipleStringList2 = new ArrayList<>(4);
singleStringList.add(fakeBodyString);
singleStringList2.add(fakeBodyString2);
multipleStringList.add("/SomePath");
multipleStringList.add("/SomePath/");
multipleStringList.add("SomePath/");
multipleStringList.add("SomeJSP.jsp");
multipleStringList2.add("/SomePath2");
multipleStringList2.add("/SomePath2/");
multipleStringList2.add("SomePath2/");
multipleStringList2.add("SomeJSP2.jsp");
NodeList mockNodeListSingleChild = new MockNodeList(singleStringList);
NodeList mockNodeListSingleChild2 = new MockNodeList(singleStringList2);
NodeList mockNodeListMultipleChild = new MockNodeList(multipleStringList);
NodeList mockNodeListMultipleChild2 = new MockNodeList(multipleStringList2);
Element mockSingleChildResultElement = new MockElement("result", fakeBodyString, "result", fakeBodyString, Node.TEXT_NODE, mockNodeListSingleChild, null);
mockSingleChildResultElement.setAttribute("name", "input");
mockSingleChildResultElement.setAttribute("type", "dispatcher");
Element mockSingleChildResultElement2 = new MockElement("result", fakeBodyString2, "result", fakeBodyString2, Node.TEXT_NODE, mockNodeListSingleChild2, null);
mockSingleChildResultElement2.setAttribute("name", "success");
mockSingleChildResultElement2.setAttribute("type", "dispatcher");
Element mockMultipleChildAllowedMethodsElement = new MockElement("result", fakeBodyString, "result", fakeBodyString, Node.TEXT_NODE, mockNodeListMultipleChild, null);
mockMultipleChildAllowedMethodsElement.setAttribute("name", "input");
mockMultipleChildAllowedMethodsElement.setAttribute("type", "dispatcher");
Element mockMultipleChildAllowedMethodsElement2 = new MockElement("result", fakeBodyString2, "result", fakeBodyString2, Node.TEXT_NODE, mockNodeListMultipleChild2, null);
mockMultipleChildAllowedMethodsElement2.setAttribute("name", "success");
mockMultipleChildAllowedMethodsElement2.setAttribute("type", "dispatcher");
MockNodeList mockActionElementChildrenSingle = new MockNodeList();
mockActionElementChildrenSingle.addToNodeList(mockSingleChildResultElement);
mockActionElementChildrenSingle.addToNodeList(mockSingleChildResultElement2);
MockNodeList mockActionElementChildrenMultiple = new MockNodeList();
mockActionElementChildrenMultiple.addToNodeList(mockMultipleChildAllowedMethodsElement);
mockActionElementChildrenMultiple.addToNodeList(mockMultipleChildAllowedMethodsElement2);
Element mockActionElementSingle = new MockElement("action", "fakeBody", "action", "fakeValue", Node.TEXT_NODE, mockActionElementChildrenSingle, null);
Element mockActionElementMultiple = new MockElement("action", "fakeBody", "action", "fakeValue", Node.TEXT_NODE, mockActionElementChildrenMultiple, null);
// Attempt the method using both types of Elements (single child and multiple child) and confirm
// the result is the same for both. Also confirm the results are as expected.
XmlConfigurationProvider prov = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork- test.xml");
Map<String, ResultConfig> singleChildResult = prov.buildResults(mockActionElementSingle, testPackageConfigBuilder);
Map<String, ResultConfig> multipleChildResult = prov.buildResults(mockActionElementMultiple, testPackageConfigBuilder);
assertNotNull("singleChildResult is null ?", singleChildResult);
assertNotNull("multipleChildResult is null ?", multipleChildResult);
assertEquals("singleChildResult not equal to multipleChildResult ?", singleChildResult, multipleChildResult);
// Since both Maps are equal, only need to test one to confirm the contents of ONE are correct.contents are correct
// The multipleChildResult (constructed from the multiple child TEXT_NODES) will be checked for correctness.
assertEquals("result Maps not of size 2 ?", 2, multipleChildResult.size());
ResultConfig inputResult = multipleChildResult.get("input");
ResultConfig successResult = multipleChildResult.get("success");
assertNotNull("inputResult (multipleChildResult) is null ?", inputResult);
assertNotNull("successResult (multipleChildResult) is null ?", successResult);
Map<String, String> inputResultParams = inputResult.getParams();
Map<String, String> successResultParams = successResult.getParams();
assertNotNull("inputResultParams (multipleChildResult) is null ?", inputResultParams);
assertNotNull("successResultParams (multipleChildResult) is null ?", successResultParams);
assertEquals("inputResult (multipleChildResult) resultParam value not equal to fakeBodyString ?", fakeBodyString, inputResultParams.get(resultParam));
assertEquals("successResult (multipleChildResult) resultParam value not equal to fakeBodyString2 ?", fakeBodyString2, successResultParams.get(resultParam));
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class XmlConfigurationProviderTest method testBuildAllowedMethods.
/**
* Test buildAllowedMethods() to ensure consistent results for processing
* <allowed-methods/> in <action/> XML configuration elements.
*
* @throws Exception
*/
public void testBuildAllowedMethods() throws Exception {
// Test introduced with WW-5029 fix.
// Set up test using two mock DOM Elements:
// 1) A mock "action" Element with a single "allowed-methods" child Element that contains a single
// TEXT_NODE Node. This simulates a typical result from a SAX parser parsing the allowed-methods
// tag body.
// 2) A mock "action" Element with a single "allowed-methods" child Element that contains multiple
// TEXT_NODE Nodes. This simulates an unusal result from a SAX parser parsing the allowed-methods
// tag body (as reported with WW-5029).
final String fakeBodyString = "allowedMethod1,allowedMethod2,allowedMethod3";
PackageConfig.Builder testPackageConfigBuilder = new PackageConfig.Builder("allowedMethodsPackage");
List<String> singleStringList = new ArrayList<>(1);
List<String> multipleStringList = new ArrayList<>(4);
singleStringList.add(fakeBodyString);
multipleStringList.add("allowedMethod1,");
multipleStringList.add("allowed");
multipleStringList.add("Method2,");
multipleStringList.add("allowedMethod3");
NodeList mockNodeListSingleChild = new MockNodeList(singleStringList);
NodeList mockNodeListMultipleChild = new MockNodeList(multipleStringList);
Element mockSingleChildAllowedMethodsElement = new MockElement("allowed-methods", fakeBodyString, "allowed-methods", fakeBodyString, Node.TEXT_NODE, mockNodeListSingleChild, null);
Element mockMultipleChildAllowedMethodsElement = new MockElement("allowed-methods", fakeBodyString, "allowed-methods", fakeBodyString, Node.TEXT_NODE, mockNodeListMultipleChild, null);
MockNodeList mockActionElementChildrenSingle = new MockNodeList();
mockActionElementChildrenSingle.addToNodeList(mockSingleChildAllowedMethodsElement);
MockNodeList mockActionElementChildrenMultiple = new MockNodeList();
mockActionElementChildrenMultiple.addToNodeList(mockMultipleChildAllowedMethodsElement);
Element mockActionElementSingle = new MockElement("action", "fakeBody", "action", "fakeValue", Node.TEXT_NODE, mockActionElementChildrenSingle, null);
Element mockActionElementMultiple = new MockElement("action", "fakeBody", "action", "fakeValue", Node.TEXT_NODE, mockActionElementChildrenMultiple, null);
// Attempt the method using both types of Elements (single child and multiple child) and confirm
// the result is the same for both. Also confirm the results are as expected.
XmlConfigurationProvider prov = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork- test.xml");
Set<String> singleChildResult = prov.buildAllowedMethods(mockActionElementSingle, testPackageConfigBuilder);
Set<String> multipleChildResult = prov.buildAllowedMethods(mockActionElementMultiple, testPackageConfigBuilder);
assertNotNull("singleChildResult is null ?", singleChildResult);
assertNotNull("multipleChildResult is null ?", multipleChildResult);
assertEquals("singleChildResult not equal to multipleChildResult ?", singleChildResult, multipleChildResult);
// Since both Sets are equal, only need to test one to confirm contents are correct
assertEquals("result Sets not of length 3 ?", 3, multipleChildResult.size());
assertTrue("allowedMethod1 not present ?", multipleChildResult.contains("allowedMethod1"));
assertTrue("allowedMethod2 not present ?", multipleChildResult.contains("allowedMethod2"));
assertTrue("allowedMethod3 not present ?", multipleChildResult.contains("allowedMethod3"));
assertFalse("noSuchMethod is present ?", multipleChildResult.contains("noSuchMethod"));
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class XmlConfigurationProviderTest method testLoadGlobalResults.
/**
* Test loadGlobalResults() to ensure consistent results for processing
* <global-results/> in <package/> XML configuration elements.
*
* @throws Exception
*/
public void testLoadGlobalResults() throws Exception {
// Set up test using two mock DOM Elements:
// 1) A mock "package" Element containing a mock "global-results" Element with a two "result"
// child Elements that each contains a single TEXT_NODE Node. This simulates a typical result
// from a SAX parser parsing the result tag body.
// 2) A mock "package" Element containing a mock "global-results" Element with two "result"
// child Elements that each contain multiple TEXT_NODE Nodes. This simulates an unusal result
// from a SAX parser parsing the result tag body.
final String fakeBodyString = "/SomePath/SomePath/SomePath/SomeJSP.jsp";
final String fakeBodyString2 = "/SomePath2/SomePath2/SomePath2/SomeJSP2.jsp";
final String resultParam = "nonNullDefaultParam";
PackageConfig.Builder testPackageConfigBuilder = new PackageConfig.Builder("resultsPackage");
ResultTypeConfig.Builder resultTypeConfigBuilder = new ResultTypeConfig.Builder("dispatcher", ServletDispatcherResult.class.getName());
resultTypeConfigBuilder.defaultResultParam(resultParam);
ResultTypeConfig resultTypeConfig = resultTypeConfigBuilder.build();
testPackageConfigBuilder.addResultTypeConfig(resultTypeConfig);
List<String> singleStringList = new ArrayList<>(1);
List<String> singleStringList2 = new ArrayList<>(1);
List<String> multipleStringList = new ArrayList<>(4);
List<String> multipleStringList2 = new ArrayList<>(4);
singleStringList.add(fakeBodyString);
singleStringList2.add(fakeBodyString2);
multipleStringList.add("/SomePath");
multipleStringList.add("/SomePath/");
multipleStringList.add("SomePath/");
multipleStringList.add("SomeJSP.jsp");
multipleStringList2.add("/SomePath2");
multipleStringList2.add("/SomePath2/");
multipleStringList2.add("SomePath2/");
multipleStringList2.add("SomeJSP2.jsp");
NodeList mockNodeListSingleChild = new MockNodeList(singleStringList);
NodeList mockNodeListSingleChild2 = new MockNodeList(singleStringList2);
NodeList mockNodeListMultipleChild = new MockNodeList(multipleStringList);
NodeList mockNodeListMultipleChild2 = new MockNodeList(multipleStringList2);
Element mockSingleChildResultElement = new MockElement("result", fakeBodyString, "result", fakeBodyString, Node.TEXT_NODE, mockNodeListSingleChild, null);
mockSingleChildResultElement.setAttribute("name", "input");
mockSingleChildResultElement.setAttribute("type", "dispatcher");
Element mockSingleChildResultElement2 = new MockElement("result", fakeBodyString2, "result", fakeBodyString2, Node.TEXT_NODE, mockNodeListSingleChild2, null);
mockSingleChildResultElement2.setAttribute("name", "success");
mockSingleChildResultElement2.setAttribute("type", "dispatcher");
Element mockMultipleChildAllowedMethodsElement = new MockElement("result", fakeBodyString, "result", fakeBodyString, Node.TEXT_NODE, mockNodeListMultipleChild, null);
mockMultipleChildAllowedMethodsElement.setAttribute("name", "input2");
mockMultipleChildAllowedMethodsElement.setAttribute("type", "dispatcher");
Element mockMultipleChildAllowedMethodsElement2 = new MockElement("result", fakeBodyString, "result", fakeBodyString2, Node.TEXT_NODE, mockNodeListMultipleChild2, null);
mockMultipleChildAllowedMethodsElement2.setAttribute("name", "success2");
mockMultipleChildAllowedMethodsElement2.setAttribute("type", "dispatcher");
MockNodeList mockGlobalResultsElementChildrenSingle = new MockNodeList();
mockGlobalResultsElementChildrenSingle.addToNodeList(mockSingleChildResultElement);
mockGlobalResultsElementChildrenSingle.addToNodeList(mockSingleChildResultElement2);
MockNodeList mockGlobalResultsElementChildrenMultiple = new MockNodeList();
mockGlobalResultsElementChildrenMultiple.addToNodeList(mockMultipleChildAllowedMethodsElement);
mockGlobalResultsElementChildrenMultiple.addToNodeList(mockMultipleChildAllowedMethodsElement2);
Element mockGlobalResultsElementSingle = new MockElement("global-results", "fakeBody", "global-results", "fakeValue", Node.TEXT_NODE, mockGlobalResultsElementChildrenSingle, null);
Element mockGlobalResultsGlobalResultsElementMultiple = new MockElement("global-results", "fakeBody", "global-results", "fakeValue", Node.TEXT_NODE, mockGlobalResultsElementChildrenMultiple, null);
MockNodeList mockPackageElementChildrenSingle = new MockNodeList();
mockPackageElementChildrenSingle.addToNodeList(mockGlobalResultsElementSingle);
MockNodeList mockPackageElementChildrenMultiple = new MockNodeList();
mockPackageElementChildrenMultiple.addToNodeList(mockGlobalResultsGlobalResultsElementMultiple);
Element mockPackageElementSingle = new MockElement("package", "fakeBody", "package", "fakeValue", Node.TEXT_NODE, mockPackageElementChildrenSingle, null);
Element mockPackageElementMultiple = new MockElement("package", "fakeBody", "package", "fakeValue", Node.TEXT_NODE, mockPackageElementChildrenMultiple, null);
// Attempt the global laod method using single child Elements first, and confirm the results are as expected.
XmlConfigurationProvider prov = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork- test.xml");
prov.loadGlobalResults(testPackageConfigBuilder, mockPackageElementSingle);
PackageConfig testPackageConfig = testPackageConfigBuilder.build();
Map<String, ResultConfig> currentGlobalResults = testPackageConfig.getAllGlobalResults();
assertNotNull("currentGlobalResults is null ?", currentGlobalResults);
assertEquals("currentGlobalResults size not 2 ?", 2, currentGlobalResults.size());
ResultConfig inputResult = currentGlobalResults.get("input");
ResultConfig successResult = currentGlobalResults.get("success");
assertNotNull("inputResult (currentGlobalResults - single) is null ?", inputResult);
assertNotNull("successResult (currentGlobalResults - single) is null ?", successResult);
Map<String, String> inputResultParams = inputResult.getParams();
Map<String, String> successResultParams = successResult.getParams();
assertNotNull("inputResultParams (currentGlobalResults - single) is null ?", inputResultParams);
assertNotNull("successResultParams (currentGlobalResults - single) is null ?", successResultParams);
assertEquals("inputResult (currentGlobalResults - single) resultParam value not equal to fakeBodyString ?", fakeBodyString, inputResultParams.get(resultParam));
assertEquals("successResult (currentGlobalResults - single) resultParam value not equal to fakeBodyString2 ?", fakeBodyString2, successResultParams.get(resultParam));
// Attempt the global laod method using mutliple child Elements next, and confirm the results are as expected.
prov.loadGlobalResults(testPackageConfigBuilder, mockPackageElementMultiple);
testPackageConfig = testPackageConfigBuilder.build();
currentGlobalResults = testPackageConfig.getAllGlobalResults();
assertNotNull("currentGlobalResults is null ?", currentGlobalResults);
assertEquals("currentGlobalResults size not 4 ?", 4, currentGlobalResults.size());
ResultConfig inputResult2 = currentGlobalResults.get("input2");
ResultConfig successResult2 = currentGlobalResults.get("success2");
assertNotNull("inputResult2 (currentGlobalResults - multiple) is null ?", inputResult2);
assertNotNull("successResult2 (currentGlobalResults - multiple) is null ?", successResult2);
Map<String, String> inputResultParams2 = inputResult2.getParams();
Map<String, String> successResultParams2 = successResult2.getParams();
assertNotNull("inputResultParams2 (currentGlobalResults - multiple) is null ?", inputResultParams2);
assertNotNull("successResultParams2 (currentGlobalResults - multiple) is null ?", successResultParams2);
assertEquals("inputResult2 (currentGlobalResults - multiple) resultParam value not equal to fakeBodyString ?", fakeBodyString, inputResultParams2.get(resultParam));
assertEquals("successResult2 (currentGlobalResults - multiple) resultParam value not equal to fakeBodyString2 ?", fakeBodyString2, successResultParams2.get(resultParam));
// Confirm the previous global results are still present
inputResult = currentGlobalResults.get("input");
successResult = currentGlobalResults.get("success");
assertNotNull("inputResult (currentGlobalResults - single) is null ?", inputResult);
assertNotNull("successResult (currentGlobalResults - single) is null ?", successResult);
inputResultParams = inputResult.getParams();
successResultParams = successResult.getParams();
assertNotNull("inputResultParams (currentGlobalResults - single) is null ?", inputResultParams);
assertNotNull("successResultParams (currentGlobalResults - single) is null ?", successResultParams);
assertEquals("inputResult (currentGlobalResults - single) resultParam value not equal to fakeBodyString ?", fakeBodyString, inputResultParams.get(resultParam));
assertEquals("successResult (currentGlobalResults - single) resultParam value not equal to fakeBodyString2 ?", fakeBodyString2, successResultParams.get(resultParam));
inputResult = currentGlobalResults.get("input");
successResult = currentGlobalResults.get("success");
assertNotNull("inputResult (currentGlobalResults - single) is null ?", inputResult);
assertNotNull("successResult (currentGlobalResults - single) is null ?", successResult);
inputResultParams = inputResult.getParams();
successResultParams = successResult.getParams();
assertNotNull("inputResultParams (currentGlobalResults - single) is null ?", inputResultParams);
assertNotNull("successResultParams (currentGlobalResults - single) is null ?", successResultParams);
assertEquals("inputResult (currentGlobalResults - single) resultParam value not equal to fakeBodyString ?", fakeBodyString, inputResultParams.get(resultParam));
assertEquals("successResult (currentGlobalResults - single) resultParam value not equal to fakeBodyString2 ?", fakeBodyString2, successResultParams.get(resultParam));
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class StrutsSpringJUnit4TestCaseTest method getActionProxy.
@Test
public void getActionProxy() throws Exception {
// set parameters before calling getActionProxy
request.setParameter("name", "FD");
ActionProxy proxy = getActionProxy("/test/testAction.action");
Assert.assertNotNull(proxy);
JUnitTestAction action = (JUnitTestAction) proxy.getAction();
Assert.assertNotNull(action);
String result = proxy.execute();
Assert.assertEquals(Action.SUCCESS, result);
Assert.assertEquals("FD", action.getName());
}
Aggregations