mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
WW-4789 WW-3788 Introduces helper methods to allow build fluent API
This commit is contained in:
@@ -329,12 +329,6 @@ public class EmbeddedJSPResultTest extends TestCase {
|
||||
|
||||
EasyMock.replay(request);
|
||||
|
||||
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
|
||||
actionContext.setParameters(HttpParameters.create(params).build());
|
||||
actionContext.setServletRequest(request);
|
||||
actionContext.setServletResponse(response);
|
||||
actionContext.setServletContext(context);
|
||||
|
||||
//mock value stack
|
||||
Map<String, Object> stackContext = new HashMap<>();
|
||||
ValueStack valueStack = EasyMock.createNiceMock(ValueStack.class);
|
||||
@@ -362,9 +356,15 @@ public class EmbeddedJSPResultTest extends TestCase {
|
||||
|
||||
EasyMock.replay(container);
|
||||
stackContext.put(ActionContext.CONTAINER, container);
|
||||
actionContext.setContainer(container);
|
||||
|
||||
actionContext.setValueStack(valueStack);
|
||||
ActionContext.of(new HashMap<>())
|
||||
.withParameters(HttpParameters.create(params).build())
|
||||
.withServletRequest(request)
|
||||
.withServletResponse(response)
|
||||
.withServletContext(context)
|
||||
.withContainer(container)
|
||||
.withValueStack(valueStack)
|
||||
.bind();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ public abstract class AbstractTest extends TestCase {
|
||||
replay(container);
|
||||
|
||||
ActionContext actionContext = ActionContext.of(stackContext).bind();
|
||||
actionContext.setServletRequest(request);
|
||||
actionContext.withServletRequest(request);
|
||||
}
|
||||
|
||||
protected static String s(String input) {
|
||||
|
||||
@@ -153,8 +153,6 @@ public class ChartResultTest extends StrutsTestCase {
|
||||
|
||||
|
||||
stack = ActionContext.getContext().getValueStack();
|
||||
ActionContext.getContext().setValueStack(stack);
|
||||
|
||||
|
||||
mockActionProxy = EasyMock.createNiceMock(ActionProxy.class);
|
||||
EasyMock.expect(mockActionProxy.getNamespace()).andReturn("/html");
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -517,15 +516,15 @@ public class JSONInterceptorTest extends StrutsTestCase {
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.response = new MockHttpServletResponse();
|
||||
|
||||
ActionContext context = ActionContext.getContext();
|
||||
ValueStack stack = context.getValueStack();
|
||||
|
||||
context.setServletRequest(request);
|
||||
context.setServletResponse(response);
|
||||
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
|
||||
context.setServletContext(servletContext);
|
||||
ActionContext context = ActionContext.getContext()
|
||||
.withServletRequest(request)
|
||||
.withServletResponse(response)
|
||||
.withServletContext(servletContext);
|
||||
|
||||
ValueStack stack = context.getValueStack();
|
||||
|
||||
this.invocation = new MockActionInvocationEx();
|
||||
this.invocation.setInvocationContext(context);
|
||||
this.invocation.setStack(stack);
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
|
||||
|
||||
protected void initSession(ActionContext actionContext) {
|
||||
if (actionContext.getSession() == null) {
|
||||
actionContext.setSession(new HashMap<String, Object>());
|
||||
actionContext.withSession(new HashMap<>());
|
||||
request.setSession(new MockHttpSession(servletContext));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class StrutsPortletTestCase extends StrutsTestCase {
|
||||
portletResponse = new MockStateAwareResponse();
|
||||
portletSession = new MockPortletSession();
|
||||
portletRequest.setSession(portletSession);
|
||||
actionContext.setSession(createSession());
|
||||
actionContext.withSession(createSession());
|
||||
actionContext.put(PortletConstants.REQUEST, portletRequest);
|
||||
actionContext.put(PortletConstants.RESPONSE, portletResponse);
|
||||
actionContext.put(PortletConstants.MODE_NAMESPACE_MAP, new HashMap<PortletMode, String>());
|
||||
|
||||
@@ -127,7 +127,7 @@ public abstract class StrutsTestCase extends XWorkTestCase {
|
||||
|
||||
protected void initSession(ActionContext actionContext) {
|
||||
if (actionContext.getSession() == null) {
|
||||
actionContext.setSession(new HashMap<String, Object>());
|
||||
actionContext.withSession(new HashMap<>());
|
||||
request.setSession(new MockHttpSession(servletContext));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -159,11 +159,11 @@ public class PortletVelocityResult extends StrutsResultSupport {
|
||||
velocityManager.init(servletContext);
|
||||
|
||||
boolean usedJspFactory = false;
|
||||
PageContext pageContext = (PageContext) ActionContext.getContext().get(ServletActionContext.PAGE_CONTEXT);
|
||||
PageContext pageContext = ActionContext.getContext().getPageContext();
|
||||
|
||||
if (pageContext == null && servlet != null) {
|
||||
pageContext = jspFactory.getPageContext(servlet, request, response, null, true, 8192, true);
|
||||
ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT, pageContext);
|
||||
ActionContext.getContext().withPageContext(pageContext);
|
||||
usedJspFactory = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,12 +153,13 @@ public class PortletUrlTagTest extends MockObjectTestCase {
|
||||
contextMap.put(PortletConstants.DEFAULT_ACTION_MAP, actionMap);
|
||||
contextMap.put(STRUTS_PORTLET_CONTEXT, mockCtx.proxy());
|
||||
|
||||
ActionContext ctx = ActionContext.of(contextMap).bind();
|
||||
ctx.setValueStack(stack);
|
||||
ctx.setContainer(dispatcher.getContainer());
|
||||
|
||||
ActionInvocation ai = (ActionInvocation) mockActionInvocation.proxy();
|
||||
ctx.setActionInvocation(ai);
|
||||
|
||||
ActionContext.of(contextMap)
|
||||
.withValueStack(stack)
|
||||
.withContainer(dispatcher.getContainer())
|
||||
.withActionInvocation(ai)
|
||||
.bind();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
+2
-2
@@ -59,8 +59,8 @@ public class ContentTypeHandlerManagerTest extends TestCase {
|
||||
mockRequest = new MockHttpServletRequest();
|
||||
mockRequest.setMethod("GET");
|
||||
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
|
||||
actionContext.setServletRequest(mockRequest);
|
||||
actionContext.setServletResponse(mockResponse);
|
||||
actionContext.withServletRequest(mockRequest);
|
||||
actionContext.withServletResponse(mockResponse);
|
||||
|
||||
invocation = new MockActionInvocation();
|
||||
invocation.setProxy(new MockActionProxy());
|
||||
|
||||
@@ -51,8 +51,9 @@ public class RestWorkflowInterceptorTest extends TestCase {
|
||||
}, null);
|
||||
wf.setContentTypeHandlerManager((ContentTypeHandlerManager) mockContentTypeHandlerManager.proxy());
|
||||
|
||||
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
|
||||
actionContext.setActionMapping(new ActionMapping());
|
||||
ActionContext.of(new HashMap<>())
|
||||
.withActionMapping(new ActionMapping())
|
||||
.bind();
|
||||
|
||||
wf.doIntercept((ActionInvocation) mockActionInvocation.proxy());
|
||||
mockContentTypeHandlerManager.verify();
|
||||
|
||||
+2
-2
@@ -128,11 +128,11 @@ public class VelocityResult extends StrutsResultSupport {
|
||||
velocityManager.init(servletContext);
|
||||
|
||||
boolean usedJspFactory = false;
|
||||
PageContext pageContext = (PageContext) ActionContext.getContext().get(ServletActionContext.PAGE_CONTEXT);
|
||||
PageContext pageContext = (PageContext) ActionContext.getContext().getPageContext();
|
||||
|
||||
if (pageContext == null && servlet != null) {
|
||||
pageContext = jspFactory.getPageContext(servlet, request, response, null, true, 8192, true);
|
||||
ActionContext.getContext().put(ServletActionContext.PAGE_CONTEXT, pageContext);
|
||||
ActionContext.getContext().withPageContext(pageContext);
|
||||
usedJspFactory = true;
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -93,7 +93,6 @@ public class VelocityResultTest extends XWorkTestCase {
|
||||
namespace = "/html";
|
||||
result = new VelocityResult();
|
||||
stack = ActionContext.getContext().getValueStack();
|
||||
ActionContext.getContext().setValueStack(stack);
|
||||
velocity = new TestVelocityEngine();
|
||||
mockActionProxy = new Mock(ActionProxy.class);
|
||||
mockActionProxy.expectAndReturn("getNamespace", "/html");
|
||||
|
||||
Reference in New Issue
Block a user