use of com.opensymphony.xwork2.Result in project struts by apache.
the class ExceptionMappingInterceptorTest method testThrownExceptionMatching.
public void testThrownExceptionMatching() throws Exception {
this.setUpWithExceptionMappings();
Mock action = new Mock(Action.class);
Exception exception = new StrutsException("test");
mockInvocation.expectAndThrow("invoke", exception);
mockInvocation.matchAndReturn("getAction", action.proxy());
String result = interceptor.intercept(invocation);
assertNotNull(stack.findValue("exception"));
assertEquals(stack.findValue("exception"), exception);
assertEquals(result, "spooky");
// is on top of the root
ExceptionHolder holder = (ExceptionHolder) stack.getRoot().get(0);
// to invoke the method for unit test
assertNotNull(holder.getExceptionStack());
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class OgnlUtilTest method testAccessContext.
public void testAccessContext() throws Exception {
Map<String, Object> context = ognlUtil.createDefaultContext(null);
Foo foo = new Foo();
Object result = ognlUtil.getValue("#context", context, null);
Object root = ognlUtil.getValue("#root", context, foo);
Object that = ognlUtil.getValue("#this", context, foo);
assertNotSame(context, result);
assertNull(result);
assertNotNull(root);
assertSame(root.getClass(), Foo.class);
assertNotNull(that);
assertSame(that.getClass(), Foo.class);
assertSame(that, root);
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class ChartResultTest method testChartWithOGNLProperties.
public void testChartWithOGNLProperties() throws Exception {
EasyMock.expect(responseMock.getOutputStream()).andReturn(os);
EasyMock.replay(responseMock, mockActionProxy, actionInvocation);
ChartResult result = new ChartResult();
result.setChart(mockChart);
result.setHeight("${myHeight}");
result.setWidth("${myWidth}");
ValueStack stack = ActionContext.getContext().getValueStack();
stack.set("myHeight", 250);
stack.set("myWidth", 150);
result.execute(actionInvocation);
EasyMock.verify(responseMock);
assertEquals(result.getHeight(), stack.findValue("myHeight").toString());
assertEquals(result.getWidth(), stack.findValue("myWidth").toString());
assertEquals("250", result.getHeight().toString());
assertEquals("150", result.getWidth().toString());
assertTrue(os.isWritten());
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class XmlConfigurationProviderResultTypesTest method testInheritedResultTypesParams.
public void testInheritedResultTypesParams() throws Exception {
ConfigurationProvider configurationProvider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-result-types.xml");
PackageConfig packageConfig = configuration.getPackageConfig("xworkResultTypesTestPackage2");
Map actionConfigMap = packageConfig.getActionConfigs();
ActionConfig action1ActionConfig = (ActionConfig) actionConfigMap.get("action1");
ActionConfig action2ActionConfig = (ActionConfig) actionConfigMap.get("action2");
ResultConfig action1Result = (ResultConfig) action1ActionConfig.getResults().get("success");
ResultConfig action2Result = (ResultConfig) action2ActionConfig.getResults().get("success");
assertEquals(action1Result.getName(), "success");
assertEquals(action1Result.getClassName(), "com.opensymphony.xwork2.mock.MockResult");
assertEquals(action1Result.getName(), "success");
assertEquals(action1Result.getClassName(), "com.opensymphony.xwork2.mock.MockResult");
Map action1ResultMap = action1Result.getParams();
Map action2ResultMap = action2Result.getParams();
assertEquals(action1ResultMap.size(), 5);
assertTrue(action1ResultMap.containsKey("param1"));
assertTrue(action1ResultMap.containsKey("param2"));
assertTrue(action1ResultMap.containsKey("param3"));
assertTrue(action1ResultMap.containsKey("param10"));
assertTrue(action1ResultMap.containsKey("param11"));
assertFalse(action1ResultMap.containsKey("param12"));
assertEquals(action1ResultMap.get("param1"), "newValue1");
assertEquals(action1ResultMap.get("param2"), "value2");
assertEquals(action1ResultMap.get("param3"), "newValue3");
assertEquals(action1ResultMap.get("param10"), "value10");
assertEquals(action1ResultMap.get("param11"), "value11");
assertEquals(action2ResultMap.size(), 3);
assertTrue(action2ResultMap.containsKey("paramA"));
assertTrue(action2ResultMap.containsKey("paramB"));
assertTrue(action2ResultMap.containsKey("paramZ"));
assertFalse(action2ResultMap.containsKey("paramY"));
assertEquals(action2ResultMap.get("paramA"), "valueA");
assertEquals(action2ResultMap.get("paramB"), "newValueB");
assertEquals(action2ResultMap.get("paramZ"), "valueZ");
}
use of com.opensymphony.xwork2.Result in project struts by apache.
the class XmlConfigurationProviderResultTypesTest method testPlainResultTypesParams.
public void testPlainResultTypesParams() throws Exception {
ConfigurationProvider configurationProvider = buildConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-result-types.xml");
PackageConfig packageConfig = configuration.getPackageConfig("xworkResultTypesTestPackage1");
Map resultTypesConfigMap = packageConfig.getResultTypeConfigs();
assertEquals(resultTypesConfigMap.size(), 2);
assertTrue(resultTypesConfigMap.containsKey("result1"));
assertTrue(resultTypesConfigMap.containsKey("result2"));
assertFalse(resultTypesConfigMap.containsKey("result3"));
ResultTypeConfig result1ResultTypeConfig = (ResultTypeConfig) resultTypesConfigMap.get("result1");
Map result1ParamsMap = result1ResultTypeConfig.getParams();
ResultTypeConfig result2ResultTypeConfig = (ResultTypeConfig) resultTypesConfigMap.get("result2");
Map result2ParamsMap = result2ResultTypeConfig.getParams();
assertEquals(result1ResultTypeConfig.getName(), "result1");
assertEquals(result1ResultTypeConfig.getClassName(), MockResult.class.getName());
assertEquals(result2ResultTypeConfig.getName(), "result2");
assertEquals(result2ResultTypeConfig.getClassName(), MockResult.class.getName());
assertEquals(result1ParamsMap.size(), 3);
assertEquals(result2ParamsMap.size(), 2);
assertTrue(result1ParamsMap.containsKey("param1"));
assertTrue(result1ParamsMap.containsKey("param2"));
assertTrue(result1ParamsMap.containsKey("param3"));
assertFalse(result1ParamsMap.containsKey("param4"));
assertTrue(result2ParamsMap.containsKey("paramA"));
assertTrue(result2ParamsMap.containsKey("paramB"));
assertFalse(result2ParamsMap.containsKey("paramC"));
assertEquals(result1ParamsMap.get("param1"), "value1");
assertEquals(result1ParamsMap.get("param2"), "value2");
assertEquals(result1ParamsMap.get("param3"), "value3");
assertEquals(result2ParamsMap.get("paramA"), "valueA");
assertEquals(result2ParamsMap.get("paramB"), "valueB");
}
Aggregations