use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class HttpPutFormContentFilterTests method setup.
@Before
public void setup() {
filter = new HttpPutFormContentFilter();
request = new MockHttpServletRequest("PUT", "/");
request.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1");
response = new MockHttpServletResponse();
filterChain = new MockFilterChain();
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class RequestLoggingFilterTests method uri.
@Test
public void uri() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
MockHttpServletResponse response = new MockHttpServletResponse();
request.setQueryString("booking=42");
FilterChain filterChain = new NoOpFilterChain();
filter.doFilter(request, response, filterChain);
assertNotNull(filter.beforeRequestMessage);
assertTrue(filter.beforeRequestMessage.contains("uri=/hotel"));
assertFalse(filter.beforeRequestMessage.contains("booking=42"));
assertNotNull(filter.afterRequestMessage);
assertTrue(filter.afterRequestMessage.contains("uri=/hotel"));
assertFalse(filter.afterRequestMessage.contains("booking=42"));
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class ForwardedHeaderFilterTests method forwardedRequest.
@Test
public void forwardedRequest() throws Exception {
this.request.setRequestURI("/mvc-showcase");
this.request.addHeader(X_FORWARDED_PROTO, "https");
this.request.addHeader(X_FORWARDED_HOST, "84.198.58.199");
this.request.addHeader(X_FORWARDED_PORT, "443");
this.request.addHeader("foo", "bar");
this.filter.doFilter(this.request, new MockHttpServletResponse(), this.filterChain);
HttpServletRequest actual = (HttpServletRequest) this.filterChain.getRequest();
assertEquals("https://84.198.58.199/mvc-showcase", actual.getRequestURL().toString());
assertEquals("https", actual.getScheme());
assertEquals("84.198.58.199", actual.getServerName());
assertEquals(443, actual.getServerPort());
assertTrue(actual.isSecure());
assertNull(actual.getHeader(X_FORWARDED_PROTO));
assertNull(actual.getHeader(X_FORWARDED_HOST));
assertNull(actual.getHeader(X_FORWARDED_PORT));
assertEquals("bar", actual.getHeader("foo"));
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testSetAndResolveLocaleWithCountryAsLanguageTag.
@Test
public void testSetAndResolveLocaleWithCountryAsLanguageTag() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLanguageTagCompliant(true);
resolver.setLocale(request, response, new Locale("de", "AT"));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
assertNotNull(cookie);
assertEquals(CookieLocaleResolver.DEFAULT_COOKIE_NAME, cookie.getName());
assertEquals(null, cookie.getDomain());
assertEquals(CookieLocaleResolver.DEFAULT_COOKIE_PATH, cookie.getPath());
assertFalse(cookie.getSecure());
assertEquals("de-AT", cookie.getValue());
request = new MockHttpServletRequest();
request.setCookies(cookie);
resolver = new CookieLocaleResolver();
resolver.setLanguageTagCompliant(true);
Locale loc = resolver.resolveLocale(request);
assertEquals("de", loc.getLanguage());
assertEquals("AT", loc.getCountry());
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class UrlFilenameViewControllerTests method withFilenameAndMatrixVariables.
@Test
public void withFilenameAndMatrixVariables() throws Exception {
UrlFilenameViewController ctrl = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index;a=A;b=B");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = ctrl.handleRequest(request, response);
assertEquals("index", mv.getViewName());
assertTrue(mv.getModel().isEmpty());
}
Aggregations