use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class HiddenHttpMethodFilterTests method filterWithParameterForMethod.
private void filterWithParameterForMethod(String methodParam, String expectedMethod) throws IOException, ServletException {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels");
if (methodParam != null) {
request.addParameter("_method", methodParam);
}
MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain filterChain = (filterRequest, filterResponse) -> assertThat(((HttpServletRequest) filterRequest).getMethod()).as("Invalid method").isEqualTo(expectedMethod);
this.filter.doFilter(request, response, filterChain);
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ForwardedHeaderFilterTests method forwardedRequestWithServletForward.
// SPR-16983
@Test
public void forwardedRequestWithServletForward() throws Exception {
this.request.setRequestURI("/foo");
this.request.addHeader(X_FORWARDED_PROTO, "https");
this.request.addHeader(X_FORWARDED_HOST, "www.mycompany.example");
this.request.addHeader(X_FORWARDED_PORT, "443");
this.filter.doFilter(this.request, new MockHttpServletResponse(), this.filterChain);
HttpServletRequest wrappedRequest = (HttpServletRequest) this.filterChain.getRequest();
this.request.setDispatcherType(DispatcherType.FORWARD);
this.request.setRequestURI("/bar");
this.filterChain.reset();
this.filter.doFilter(wrappedRequest, new MockHttpServletResponse(), this.filterChain);
HttpServletRequest actual = (HttpServletRequest) this.filterChain.getRequest();
assertThat(actual).isNotNull();
assertThat(actual.getRequestURI()).isEqualTo("/bar");
assertThat(actual.getRequestURL().toString()).isEqualTo("https://www.mycompany.example/bar");
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ForwardedHeaderFilterTests method forwardedRequestInRemoveOnlyMode.
@Test
public void forwardedRequestInRemoveOnlyMode() 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(X_FORWARDED_SSL, "on");
this.request.addHeader("foo", "bar");
this.request.addHeader(X_FORWARDED_FOR, "203.0.113.195");
this.filter.setRemoveOnly(true);
this.filter.doFilter(this.request, new MockHttpServletResponse(), this.filterChain);
HttpServletRequest actual = (HttpServletRequest) this.filterChain.getRequest();
assertThat(actual).isNotNull();
assertThat(actual.getRequestURL().toString()).isEqualTo("http://localhost/mvc-showcase");
assertThat(actual.getScheme()).isEqualTo("http");
assertThat(actual.getServerName()).isEqualTo("localhost");
assertThat(actual.getServerPort()).isEqualTo(80);
assertThat(actual.isSecure()).isFalse();
assertThat(actual.getRemoteAddr()).isEqualTo(MockHttpServletRequest.DEFAULT_REMOTE_ADDR);
assertThat(actual.getRemoteHost()).isEqualTo(MockHttpServletRequest.DEFAULT_REMOTE_HOST);
assertThat(actual.getHeader(X_FORWARDED_PROTO)).isNull();
assertThat(actual.getHeader(X_FORWARDED_HOST)).isNull();
assertThat(actual.getHeader(X_FORWARDED_PORT)).isNull();
assertThat(actual.getHeader(X_FORWARDED_SSL)).isNull();
assertThat(actual.getHeader(X_FORWARDED_FOR)).isNull();
assertThat(actual.getHeader("foo")).isEqualTo("bar");
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ReactiveTypeHandlerTests method resetRequest.
private void resetRequest() {
this.servletRequest = new MockHttpServletRequest();
this.servletResponse = new MockHttpServletResponse();
this.webRequest = new ServletRequestContext(null, this.servletRequest, this.servletResponse);
AsyncWebRequest webRequest = new StandardServletAsyncWebRequest(this.webRequest);
WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncRequest(webRequest);
this.servletRequest.setAsyncSupported(true);
}
use of cn.taketoday.web.mock.MockHttpServletResponse in project today-infrastructure by TAKETODAY.
the class ControllerTests method parameterizableViewController.
@Test
public void parameterizableViewController() throws Exception {
String viewName = "viewName";
ParameterizableViewController pvc = new ParameterizableViewController();
pvc.setViewName(viewName);
// We don't care about the params.
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.refresh();
ServletRequestContext context = new ServletRequestContext(wac, new MockHttpServletRequest("GET", "foo.html"), new MockHttpServletResponse());
ModelAndView mv = pvc.handleRequest(context);
assertThat(mv.getModel().size() == 0).as("model has no data").isTrue();
assertThat(mv.getViewName().equals(viewName)).as("model has correct viewname").isTrue();
assertThat(pvc.getViewName().equals(viewName)).as("getViewName matches").isTrue();
}
Aggregations