use of cn.taketoday.web.testfixture.servlet.MockHttpServletResponse in project today-framework by TAKETODAY.
the class ServerHttpRequestTests method createRequest.
private ServerHttpRequest createRequest(String uriString, String contextPath) throws Exception {
URI uri = URI.create(uriString);
MockHttpServletRequest request = new TestHttpServletRequest(uri);
request.setContextPath(contextPath);
AsyncContext asyncContext = new MockAsyncContext(request, new MockHttpServletResponse());
return new ServletServerHttpRequest(request, asyncContext, "", DefaultDataBufferFactory.sharedInstance, 1024);
}
use of cn.taketoday.web.testfixture.servlet.MockHttpServletResponse in project today-framework by TAKETODAY.
the class DefaultServletHandlerConfigurerTests method setup.
@BeforeEach
public void setup() {
response = new MockHttpServletResponse();
servletContext = new DispatchingMockServletContext();
configurer = new DefaultServletHandlerConfigurer(servletContext);
}
use of cn.taketoday.web.testfixture.servlet.MockHttpServletResponse in project today-framework by TAKETODAY.
the class CorsFilterTests method nonCorsRequest.
@Test
public void nonCorsRequest() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(), "/test.html");
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = (filterRequest, filterResponse) -> {
assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isNull();
assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS)).isNull();
};
filter.doFilter(request, response, filterChain);
}
use of cn.taketoday.web.testfixture.servlet.MockHttpServletResponse in project today-framework by TAKETODAY.
the class CorsFilterTests method validActualRequest.
@Test
public void validActualRequest() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest(HttpMethod.GET.name(), "/test.html");
request.addHeader(HttpHeaders.ORIGIN, "https://domain2.com");
request.addHeader("header2", "foo");
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = (filterRequest, filterResponse) -> {
final RequestContext context = ServletUtils.getRequestContext(request, response);
assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("https://domain2.com");
final String header = response.getHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS);
assertThat(header).isEqualTo("header3, header4");
};
filter.doFilter(request, response, filterChain);
}
use of cn.taketoday.web.testfixture.servlet.MockHttpServletResponse in project today-framework by TAKETODAY.
the class CookieLocaleResolverTests method testSetAndResolveLocale.
@Test
public void testSetAndResolveLocale() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
MockServletRequestContext requestContext = new MockServletRequestContext(request, response);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocale(requestContext, new Locale("nl", ""));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
assertThat(cookie).isNotNull();
assertThat(cookie.getName()).isEqualTo(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
assertThat(cookie.getDomain()).isNull();
assertThat(cookie.getPath()).isEqualTo(CookieLocaleResolver.DEFAULT_COOKIE_PATH);
assertThat(cookie.getSecure()).isFalse();
request = new MockHttpServletRequest();
request.setCookies(cookie);
resolver = new CookieLocaleResolver();
Locale loc = resolver.resolveLocale(requestContext);
assertThat(loc.getLanguage()).isEqualTo("nl");
}
Aggregations