Search in sources :

Example 51 with Result

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());
}
Also used : StrutsException(org.apache.struts2.StrutsException) Mock(com.mockobjects.dynamic.Mock) StrutsException(org.apache.struts2.StrutsException) ValidationException(com.opensymphony.xwork2.validator.ValidationException)

Example 52 with Result

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);
}
Also used : Foo(com.opensymphony.xwork2.util.Foo)

Example 53 with Result

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());
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 54 with Result

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");
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) Map(java.util.Map) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 55 with Result

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");
}
Also used : MockResult(com.opensymphony.xwork2.mock.MockResult) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) Map(java.util.Map) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Aggregations

ActionSupport (com.opensymphony.xwork2.ActionSupport)63 Test (org.junit.Test)52 ActionProxy (com.opensymphony.xwork2.ActionProxy)51 List (java.util.List)49 ValueStack (com.opensymphony.xwork2.util.ValueStack)38 Result (edu.stanford.CVC4.Result)35 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)34 ActionContext (com.opensymphony.xwork2.ActionContext)33 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 ArrayList (java.util.ArrayList)31 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)30 HashMap (java.util.HashMap)29 Rational (edu.stanford.CVC4.Rational)25 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)22 Map (java.util.Map)21 ServletActionContext (org.apache.struts2.ServletActionContext)21 Result (com.opensymphony.xwork2.Result)18 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)18