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);
}
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);
}
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());
}
}
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();
}
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);
}
Aggregations