Search in sources :

Example 86 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class ExecuteAndWaitInterceptorTest method testOneWaitWithDelay.

public void testOneWaitWithDelay() throws Exception {
    waitInterceptor.setDelay(200);
    waitInterceptor.setDelaySleepInterval(100);
    ActionProxy proxy = buildProxy("action1");
    long before = System.currentTimeMillis();
    String result = proxy.execute();
    long after = System.currentTimeMillis();
    assertEquals("wait", result);
    assertTrue("delay should be ca. 200 millis", (after - before) >= 190);
    Thread.sleep(400);
    ActionProxy proxy2 = buildProxy("action1");
    String result2 = proxy2.execute();
    assertEquals("success", result2);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 87 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class ExecuteAndWaitInterceptorTest method testTwoWaitWithDelay.

public void testTwoWaitWithDelay() throws Exception {
    waitInterceptor.setDelay(100);
    waitInterceptor.setDelaySleepInterval(100);
    ActionProxy proxy = buildProxy("action1");
    long before = System.currentTimeMillis();
    String result = proxy.execute();
    long after = System.currentTimeMillis();
    assertEquals("wait", result);
    assertTrue("delay should be ca. 100 millis", (after - before) >= 90);
    Thread.sleep(100);
    ActionProxy proxy2 = buildProxy("action1");
    long before2 = System.currentTimeMillis();
    String result2 = proxy2.execute();
    long after2 = System.currentTimeMillis();
    assertEquals("wait", result2);
    assertTrue("there should be no delay", (after2 - before2) < 110);
    Thread.sleep(400);
    ActionProxy proxy3 = buildProxy("action1");
    String result3 = proxy3.execute();
    assertEquals("success", result3);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 88 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class PostbackResultTest method testPassingNullInvocation.

public void testPassingNullInvocation() throws Exception {
    Result result = new PostbackResult();
    try {
        result.execute(null);
        fail("Exception should be thrown!");
    } catch (IllegalArgumentException e) {
        assertEquals("Invocation cannot be null!", e.getMessage());
    }
}
Also used : Result(com.opensymphony.xwork2.Result)

Example 89 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class PostbackResultTest method testWithNamespace.

public void testWithNamespace() throws Exception {
    ActionContext context = ActionContext.getContext();
    ValueStack stack = context.getValueStack();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    context.put(ServletActionContext.HTTP_REQUEST, req);
    context.put(ServletActionContext.HTTP_RESPONSE, res);
    PostbackResult result = new PostbackResult();
    result.setActionName("myAction${1-1}");
    result.setNamespace("myNamespace${1-1}");
    result.setPrependServletContext(false);
    IMocksControl control = createControl();
    ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
    expect(mockInvocation.getInvocationContext()).andReturn(context).anyTimes();
    expect(mockInvocation.getStack()).andReturn(stack).anyTimes();
    control.replay();
    result.setActionMapper(container.getInstance(ActionMapper.class));
    result.execute(mockInvocation);
    assertEquals("<!DOCTYPE html><html><body><form action=\"myNamespace0/myAction0.action\" method=\"POST\">" + "<script>setTimeout(function(){document.forms[0].submit();},0);</script></html>", res.getContentAsString());
    control.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) ActionMapper(org.apache.struts2.dispatcher.mapper.ActionMapper) ValueStack(com.opensymphony.xwork2.util.ValueStack) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 90 with Result

use of com.opensymphony.xwork2.Result in project struts by apache.

the class ServletActionRedirectResultTest method testBuildResultWithParameter.

public void testBuildResultWithParameter() throws Exception {
    ResultConfig resultConfig = new ResultConfig.Builder("", ServletActionRedirectResult.class.getName()).addParam("actionName", "someActionName").addParam("namespace", "someNamespace").addParam("encode", "true").addParam("parse", "true").addParam("location", "someLocation").addParam("prependServletContext", "true").addParam("method", "someMethod").addParam("param1", "value 1").addParam("param2", "value 2").addParam("param3", "value 3").addParam("anchor", "fragment").build();
    ObjectFactory factory = container.getInstance(ObjectFactory.class);
    ServletActionRedirectResult result = (ServletActionRedirectResult) factory.buildResult(resultConfig, ActionContext.getContext().getContextMap());
    assertNotNull(result);
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ObjectFactory(com.opensymphony.xwork2.ObjectFactory)

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