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