Search in sources :

Example 81 with Result

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

the class TokenInterceptorTest method testCAllExecute2Times.

public void testCAllExecute2Times() throws Exception {
    setToken(request);
    ActionProxy proxy = buildProxy(getActionName());
    assertEquals(Action.SUCCESS, proxy.execute());
    ActionProxy proxy2 = buildProxy(getActionName());
    // must not call setToken
    // double post will result in a invalid.token return code
    assertEquals(TokenInterceptor.INVALID_TOKEN_CODE, proxy2.execute());
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 82 with Result

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

the class HttpHeaderResultTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    result = new HttpHeaderResult();
    responseMock = new Mock(HttpServletResponse.class);
    response = (HttpServletResponse) responseMock.proxy();
    invocationMock = new Mock(ActionInvocation.class);
    invocationMock.expectAndReturn("getInvocationContext", ActionContext.getContext());
    invocationMock.expectAndReturn("getStack", ActionContext.getContext().getValueStack());
    invocation = (ActionInvocation) invocationMock.proxy();
    reflectionProvider = container.getInstance(ReflectionProvider.class);
    ServletActionContext.setResponse(response);
}
Also used : ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ReflectionProvider(com.opensymphony.xwork2.util.reflection.ReflectionProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) Mock(com.mockobjects.dynamic.Mock)

Example 83 with Result

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

the class ExecuteAndWaitInterceptorTest method testFromDeserializedSession.

public void testFromDeserializedSession() throws Exception {
    waitInterceptor.setDelay(0);
    waitInterceptor.setDelaySleepInterval(0);
    ActionProxy proxy = buildProxy("action1");
    String result = proxy.execute();
    assertEquals("wait", result);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    // WW-4900 action1 and invocation are not serializable but we should not fail at this line
    oos.writeObject(session);
    oos.close();
    byte[] b = baos.toByteArray();
    baos.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    ObjectInputStream ois = new ObjectInputStream(bais);
    session = (Map<String, Object>) ois.readObject();
    context = ActionContext.of(context).withSession(session).getContextMap();
    ois.close();
    bais.close();
    Thread.sleep(1000);
    ActionProxy proxy2 = buildProxy("action1");
    String result2 = proxy2.execute();
    // WW-4900 A new thread should be started when background thread missed
    assertEquals("wait", result2);
    Thread.sleep(1000);
    ActionProxy proxy3 = buildProxy("action1");
    String result3 = proxy3.execute();
    assertEquals("success", result3);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 84 with Result

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

the class ExecuteAndWaitInterceptorTest method testOneWait.

public void testOneWait() throws Exception {
    waitInterceptor.setDelay(0);
    waitInterceptor.setDelaySleepInterval(0);
    ActionProxy proxy = buildProxy("action1");
    String result = proxy.execute();
    assertEquals("wait", result);
    Thread.sleep(1000);
    ActionProxy proxy2 = buildProxy("action1");
    String result2 = proxy2.execute();
    assertEquals("success", result2);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

Example 85 with Result

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

the class ExecuteAndWaitInterceptorTest method testWaitDelayAndJobAlreadyDone2.

public void testWaitDelayAndJobAlreadyDone2() throws Exception {
    waitInterceptor.setDelay(1500);
    // just takes a little longer to find out job is done
    waitInterceptor.setDelaySleepInterval(200);
    ActionProxy proxy = buildProxy("action1");
    long before = System.currentTimeMillis();
    String result = proxy.execute();
    long diff = System.currentTimeMillis() - before;
    assertEquals("success", result);
    assertTrue("Job done already after 500 so there should not be such long delay", diff <= 1000);
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy)

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