Search in sources :

Example 51 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testForceAddSchemeHostAndPort.

public void testForceAddSchemeHostAndPort() throws Exception {
    String expectedUrl = "http://localhost/contextPath/path1/path2/myAction.action";
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getScheme", "http");
    mockHttpServletRequest.expectAndReturn("getServerName", "localhost");
    mockHttpServletRequest.expectAndReturn("getContextPath", "/contextPath");
    mockHttpServletRequest.expectAndReturn("getServerPort", 80);
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedUrl, expectedUrl);
    String result = urlHelper.buildUrl("/path1/path2/myAction.action", (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), null, "http", true, true, true);
    assertEquals(expectedUrl, result);
    mockHttpServletRequest.verify();
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 52 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testSwitchToHttpScheme.

/**
 * The UrlHelper should build a URL that starts with "http" followed by the server name when the scheme of the
 * current request is "https" and the port for the "http" scheme is 80.
 */
public void testSwitchToHttpScheme() {
    String expectedString = "http://www.mydomain.com/mywebapp/MyAction.action?foo=bar&hello=earth&hello=mars";
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getServerName", "www.mydomain.com");
    mockHttpServletRequest.expectAndReturn("getScheme", "https");
    mockHttpServletRequest.expectAndReturn("getServerPort", 443);
    mockHttpServletRequest.expectAndReturn("getContextPath", "/mywebapp");
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedString, expectedString);
    String actionName = "/MyAction.action";
    TreeMap params = new TreeMap();
    params.put("hello", new String[] { "earth", "mars" });
    params.put("foo", "bar");
    String urlString = urlHelper.buildUrl(actionName, (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), params, "http", true, true);
    assertEquals(expectedString, urlString);
}
Also used : TreeMap(java.util.TreeMap) Mock(com.mockobjects.dynamic.Mock)

Example 53 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testForceAddNullSchemeHostAndPort.

public void testForceAddNullSchemeHostAndPort() throws Exception {
    String expectedUrl = "http://localhost/contextPath/path1/path2/myAction.action";
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getScheme", "http");
    mockHttpServletRequest.expectAndReturn("getServerName", "localhost");
    mockHttpServletRequest.expectAndReturn("getContextPath", "/contextPath");
    mockHttpServletRequest.expectAndReturn("getServerPort", 80);
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedUrl, expectedUrl);
    String result = urlHelper.buildUrl("/path1/path2/myAction.action", (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), null, null, true, true, true);
    assertEquals(expectedUrl, result);
    mockHttpServletRequest.verify();
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 54 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testForceAddNullSchemeHostAndPort2.

public void testForceAddNullSchemeHostAndPort2() throws Exception {
    String expectedUrl = "http://localhost:8080/contextPath/path1/path2/myAction.action";
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getScheme", "http");
    mockHttpServletRequest.expectAndReturn("getServerName", "localhost");
    mockHttpServletRequest.expectAndReturn("getContextPath", "/contextPath");
    mockHttpServletRequest.expectAndReturn("getServerPort", 8080);
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedUrl, expectedUrl);
    String result = urlHelper.buildUrl("/path1/path2/myAction.action", (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), null, null, true, true, true);
    assertEquals(expectedUrl, result);
    mockHttpServletRequest.verify();
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 55 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultUrlHelperTest method testSwitchToHttpsNonDefaultPort.

/**
 * This test is similar to {@link #testSwitchToHttpsScheme()} with the HTTP port equal to 7001 and the HTTPS port
 * equal to 7002.
 */
public void testSwitchToHttpsNonDefaultPort() {
    String expectedString = "https://www.mydomain.com:7002/mywebapp/MyAction.action?foo=bar&hello=earth&hello=mars";
    urlHelper.setHttpPort("7001");
    urlHelper.setHttpsPort("7002");
    Mock mockHttpServletRequest = new Mock(HttpServletRequest.class);
    mockHttpServletRequest.expectAndReturn("getServerName", "www.mydomain.com");
    mockHttpServletRequest.expectAndReturn("getScheme", "http");
    mockHttpServletRequest.expectAndReturn("getServerPort", 7001);
    mockHttpServletRequest.expectAndReturn("getContextPath", "/mywebapp");
    Mock mockHttpServletResponse = new Mock(HttpServletResponse.class);
    mockHttpServletResponse.expectAndReturn("encodeURL", expectedString, expectedString);
    String actionName = "/MyAction.action";
    TreeMap params = new TreeMap();
    params.put("hello", new String[] { "earth", "mars" });
    params.put("foo", "bar");
    String urlString = urlHelper.buildUrl(actionName, (HttpServletRequest) mockHttpServletRequest.proxy(), (HttpServletResponse) mockHttpServletResponse.proxy(), params, "https", true, true);
    assertEquals(expectedString, urlString);
}
Also used : TreeMap(java.util.TreeMap) Mock(com.mockobjects.dynamic.Mock)

Aggregations

Mock (com.mockobjects.dynamic.Mock)91 HashMap (java.util.HashMap)14 ValidationException (com.opensymphony.xwork2.validator.ValidationException)12 StrutsException (org.apache.struts2.StrutsException)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 TreeMap (java.util.TreeMap)8 ActionProxy (com.opensymphony.xwork2.ActionProxy)6 HttpParameters (org.apache.struts2.dispatcher.HttpParameters)6 MockHttpSession (org.springframework.mock.web.MockHttpSession)6 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)4 Container (com.opensymphony.xwork2.inject.Container)4 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)4 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)4 LinkedHashMap (java.util.LinkedHashMap)4 Action (com.opensymphony.xwork2.Action)3