use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class RequestLoggingFilterTests method allOptions.
@Test
void allOptions() throws Exception {
filter.setIncludeQueryString(true);
filter.setIncludeClientInfo(true);
filter.setIncludeHeaders(true);
filter.setIncludePayload(true);
request.setQueryString("booking=42");
request.setRemoteAddr("4.2.2.2");
request.setSession(new MockHttpSession(null, "42"));
request.setRemoteUser("Arthur");
request.setContentType("application/json");
String requestBody = "{\"msg\": \"Hello World\"}";
request.setContent(requestBody.getBytes(StandardCharsets.UTF_8));
FilterChain filterChain = (filterRequest, filterResponse) -> {
((HttpServletResponse) filterResponse).setStatus(HttpServletResponse.SC_OK);
String buf = FileCopyUtils.copyToString(filterRequest.getReader());
assertThat(buf).isEqualTo(requestBody);
};
filter.doFilter(request, response, filterChain);
assertThat(filter.beforeRequestMessage).isEqualTo("Before request [" + "POST /hotels?booking=42" + ", client=4.2.2.2" + ", session=42" + ", user=Arthur" + ", headers=[Content-Type:\"application/json;charset=ISO-8859-1\", Content-Length:\"22\"]" + "]");
assertThat(filter.afterRequestMessage).isEqualTo("After request [" + "POST /hotels?booking=42" + ", client=4.2.2.2" + ", session=42" + ", user=Arthur" + ", headers=[Content-Type:\"application/json;charset=ISO-8859-1\", Content-Length:\"22\"]" + ", payload={\"msg\": \"Hello World\"}" + "]");
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method defaultConstructor.
@Test
public void defaultConstructor() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
this.servletRequest.getSession().setAttribute("bar", "baz");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertThat(attributes.size()).isEqualTo(3);
assertThat(attributes.get("foo")).isEqualTo("bar");
assertThat(attributes.get("bar")).isEqualTo("baz");
assertThat(attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)).isEqualTo("123");
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method doNotCopyAttributes.
@Test
public void doNotCopyAttributes() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
interceptor.setCopyAllAttributes(false);
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertThat(attributes.size()).isEqualTo(1);
assertThat(attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)).isEqualTo("123");
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method constructorWithAttributeNames.
@Test
public void constructorWithAttributeNames() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
this.servletRequest.getSession().setAttribute("bar", "baz");
Set<String> names = Collections.singleton("foo");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor(names);
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertThat(attributes.size()).isEqualTo(2);
assertThat(attributes.get("foo")).isEqualTo("bar");
assertThat(attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME)).isEqualTo("123");
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method doNotCopyHttpSessionId.
@Test
public void doNotCopyHttpSessionId() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
interceptor.setCopyHttpSessionId(false);
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);
assertThat(attributes.size()).isEqualTo(1);
assertThat(attributes.get("foo")).isEqualTo("bar");
}
Aggregations