Updates tests

This commit is contained in:
Lukasz Lenart
2015-11-25 19:03:36 +01:00
parent 60b9d85d44
commit 059ebc72c2
10 changed files with 39 additions and 37 deletions
@@ -57,7 +57,7 @@ public class DateTextFieldInterceptorTest extends StrutsInternalTestCase {
assertTrue(parameters.contains("name"));
assertEquals(1, parameters.getNames().size());
Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2000-06-15");
assertEquals(date, parameters.get("name").getValue());
assertEquals(date, parameters.get("name").getObject());
}
}
@@ -259,10 +259,11 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
assertTrue(!action.hasErrors());
assertTrue(param.size() == 3);
File[] files = (File[]) param.get("file");
String[] fileContentTypes = (String[]) param.get("fileContentType");
String[] fileRealFilenames = (String[]) param.get("fileFileName");
HttpParameters parameters = mai.getInvocationContext().getParameters();
assertTrue(parameters.getNames().size() == 3);
File[] files = (File[]) parameters.get("file").getObject();
String[] fileContentTypes = parameters.get("fileContentType").getMultipleValue();
String[] fileRealFilenames = parameters.get("fileFileName").getMultipleValue();
assertNotNull(files);
assertNotNull(fileContentTypes);
@@ -320,8 +321,8 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
HttpParameters parameters = mai.getInvocationContext().getParameters();
assertEquals(3, parameters.getNames().size());
File[] files = (File[]) parameters.get("file").getObject();
String[] fileContentTypes = (String[]) param.get("fileContentType");
String[] fileRealFilenames = (String[]) param.get("fileFileName");
String[] fileContentTypes = parameters.get("fileContentType").getMultipleValue();
String[] fileRealFilenames = parameters.get("fileFileName").getMultipleValue();
assertNotNull(files);
assertNotNull(fileContentTypes);
@@ -29,6 +29,7 @@ import java.util.Map;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.result.ServletActionRedirectResult;
import org.easymock.EasyMock;
@@ -65,7 +66,6 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
interceptor.setOperationMode(MessageStoreInterceptor.STORE_MODE);
Map paramMap = new LinkedHashMap();
Map sessionMap = new LinkedHashMap();
ActionSupport action = new ActionSupport();
@@ -77,8 +77,8 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.put(ActionContext.SESSION, sessionMap);
actionContext.setParameters(HttpParameters.createEmpty().build());
actionContext.setSession(sessionMap);
// Mock (ActionInvocation)
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
@@ -133,15 +133,13 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
interceptor.setAllowRequestParameterSwitch(true);
interceptor.setOperationMode(MessageStoreInterceptor.STORE_MODE);
Map paramMap = new LinkedHashMap();
ActionSupport action = new ActionSupport();
action.addActionError("some action error 1");
action.addActionMessage("some action message 1");
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.setParameters(HttpParameters.createEmpty().build());
// Mock (ActionInvocation)
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
@@ -179,7 +177,6 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
mockActionInvocation.invoke();
EasyMock.expectLastCall().andReturn(Action.SUCCESS);
Map paramsMap = new LinkedHashMap();
Map sessionMap = new LinkedHashMap();
List actionErrors = new ArrayList();
@@ -203,7 +200,7 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramsMap);
actionContext.setParameters(HttpParameters.createEmpty().build());
actionContext.put(ActionContext.SESSION, sessionMap);
mockActionInvocation.getInvocationContext();
@@ -244,7 +241,6 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
interceptor.setOperationMode(MessageStoreInterceptor.AUTOMATIC_MODE);
Map paramMap = new LinkedHashMap();
Map sessionMap = new LinkedHashMap();
ActionSupport action = new ActionSupport();
@@ -256,7 +252,7 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
action.addFieldError("field2", "some field error 2");
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.setParameters(HttpParameters.createEmpty().build());
actionContext.put(ActionContext.SESSION, sessionMap);
// Mock (ActionInvocation)
@@ -319,7 +315,7 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.setParameters(HttpParameters.createEmpty().build());
actionContext.put(ActionContext.SESSION, sessionMap);
mockActionInvocation.getInvocationContext();
@@ -360,7 +356,7 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
paramMap.put("operationMode", new String[] { MessageStoreInterceptor.RETRIEVE_MODE });
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.setParameters(HttpParameters.create(paramMap).build());
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.getInvocationContext();
@@ -383,7 +379,7 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
paramMap.put("operationMode", new String[] { MessageStoreInterceptor.STORE_MODE });
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.setParameters(HttpParameters.create(paramMap).build());
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.getInvocationContext();
@@ -402,10 +398,8 @@ public class MessageStoreInterceptorTest extends StrutsInternalTestCase {
public void testRequestOperationMode3() throws Exception {
Map paramMap = new LinkedHashMap();
ActionContext actionContext = new ActionContext(new HashMap());
actionContext.put(ActionContext.PARAMETERS, paramMap);
actionContext.setParameters(HttpParameters.createEmpty().build());
ActionInvocation mockActionInvocation = EasyMock.createControl().createMock(ActionInvocation.class);
mockActionInvocation.getInvocationContext();
@@ -89,10 +89,10 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
MockActionInvocation mai = createActionInvocation(mock);
Map<String, Object> param = new HashMap<String, Object>();
mai.getInvocationContext().setParameters(HttpParameters.createEmpty().build());
HttpParameters param = HttpParameters.createEmpty().build();
mai.getInvocationContext().setParameters(param);
mock.setParameters((Map)param);
mock.setParameters(param);
control.setVoidCallable();
control.replay();
@@ -49,7 +49,7 @@ public class TokenInterceptorTest extends StrutsInternalTestCase {
ActionContext oldContext;
HttpSession httpSession;
Map<String, Object> extraContext;
Map<String, String> params;
Map<String, Object> params;
Map<String, Object> session;
StrutsMockHttpServletRequest request;
@@ -62,8 +62,8 @@ public class TokenInterceptorTest extends StrutsInternalTestCase {
public void testNoTokenInSession() throws Exception {
assertEquals(oldContext, ActionContext.getContext());
setToken(request);
ActionProxy proxy = buildProxy(getActionName());
setToken(request);
ActionContext.getContext().getSession().clear();
assertEquals(TokenInterceptor.INVALID_TOKEN_CODE, proxy.execute());
}
@@ -74,7 +74,7 @@ public class TokenInterceptorTest extends StrutsInternalTestCase {
assertEquals(Action.SUCCESS, proxy.execute());
}
public void testCallExecute2Times() throws Exception {
public void testCAllExecute2Times() throws Exception {
setToken(request);
ActionProxy proxy = buildProxy(getActionName());
assertEquals(Action.SUCCESS, proxy.execute());
@@ -128,6 +128,6 @@ public class TokenInterceptorTest extends StrutsInternalTestCase {
}
protected ActionProxy buildProxy(String actionName) throws Exception {
return actionProxyFactory.createActionProxy("", actionName, null, extraContext, true, true);
return actionProxyFactory.createActionProxy("", actionName, null, extraContext);
}
}
@@ -31,8 +31,10 @@ import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.finder.ClassLoaderInterface;
import com.opensymphony.xwork2.util.finder.ClassLoaderInterfaceDelegate;
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
import com.sun.net.httpserver.HttpsParameters;
import junit.framework.TestCase;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.views.util.DefaultUrlHelper;
import org.apache.struts2.views.util.UrlHelper;
import org.easymock.EasyMock;
@@ -248,7 +250,7 @@ public class EmbeddedJSPResultTest extends TestCase {
EasyMock.expect(request.getParameterMap()).andReturn(params).anyTimes();
EasyMock.expect(request.getParameter("username")).andAnswer(new IAnswer<String>() {
public String answer() throws Throwable {
return ((String[]) params.get("username"))[0];
return ActionContext.getContext().getParameters().get("username").getValue();
}
});
EasyMock.expect(request.getAttribute("something")).andReturn("somethingelse").anyTimes();
@@ -257,7 +259,7 @@ public class EmbeddedJSPResultTest extends TestCase {
ActionContext actionContext = new ActionContext(new HashMap<String, Object>());
ActionContext.setContext(actionContext);
actionContext.setParameters(params);
actionContext.setParameters(HttpParameters.create(params).build());
ServletActionContext.setRequest(request);
ServletActionContext.setResponse(response);
ServletActionContext.setServletContext(context);
@@ -33,6 +33,7 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.util.StrutsTestCaseHelper;
@@ -158,7 +159,7 @@ public abstract class StrutsJUnit4TestCase<T> extends XWorkJUnit4TestCase {
namespace, name, method, new HashMap<String, Object>(), true, false);
ActionContext invocationContext = proxy.getInvocation().getInvocationContext();
invocationContext.setParameters(new HashMap<String, Object>(request.getParameterMap()));
invocationContext.setParameters(HttpParameters.create(request.getParameterMap()).build());
// set the action context to the one used by the proxy
ActionContext.setContext(invocationContext);
@@ -4,7 +4,9 @@ import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.config.Configuration;
import com.sun.net.httpserver.HttpsParameters;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -103,7 +105,7 @@ public class StrutsRestTestCase<T> extends StrutsJUnit4TestCase<T> {
ActionContext invocationContext = proxy.getInvocation().getInvocationContext();
invocationContext.getContextMap().put(ServletActionContext.ACTION_MAPPING, mapping);
invocationContext.setParameters(new HashMap<String, Object>(request.getParameterMap()));
invocationContext.setParameters(HttpParameters.create(request.getParameterMap()).build());
// set the action context to the one used by the proxy
ActionContext.setContext(invocationContext);
@@ -30,6 +30,7 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import com.opensymphony.xwork2.util.logging.jdk.JdkLoggerFactory;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.util.StrutsTestCaseHelper;
@@ -152,7 +153,7 @@ public abstract class StrutsTestCase extends XWorkTestCase {
}
protected void initActionContext(ActionContext actionContext) {
actionContext.setParameters(new HashMap<String, Object>(request.getParameterMap()));
actionContext.setParameters(HttpParameters.create(request.getParameterMap()).build());
initSession(actionContext);
applyAdditionalParams(actionContext);
// set the action context to the one used by the proxy
@@ -23,8 +23,10 @@ package org.apache.struts2.portlet.result;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.sun.net.httpserver.HttpsParameters;
import junit.textui.TestRunner;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.portlet.PortletConstants;
import org.apache.struts2.portlet.PortletPhase;
import org.jmock.Mock;
@@ -68,12 +70,11 @@ public class PortletResultTest extends MockObjectTestCase implements StrutsStati
mockCtx = mock(PortletContext.class);
mockProxy = mock(ActionProxy.class);
Map<String, String[]> paramMap = new HashMap<String, String[]>();
Map<String, Object> sessionMap = new HashMap<String, Object>();
Map<String, Object> context = new HashMap<String, Object>();
context.put(SESSION, sessionMap);
context.put(PARAMETERS, paramMap);
context.put(PARAMETERS, HttpParameters.createEmpty().build());
context.put(STRUTS_PORTLET_CONTEXT, mockCtx.proxy());
ActionContext.setContext(new ActionContext(context));