use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class DefaultServerRequestTests method session.
@Test
void session() {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true);
MockHttpSession session = new MockHttpSession();
servletRequest.setSession(session);
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
assertThat(request.session()).isEqualTo(session);
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class RequestLoggingFilterTests method session.
@Test
void session() throws Exception {
request.setSession(new MockHttpSession(null, "42"));
filter.setIncludeClientInfo(true);
applyFilter();
assertThat(filter.beforeRequestMessage).contains("session=42");
assertThat(filter.afterRequestMessage).contains("session=42");
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class ServletRequestAttributesTests method setSessionScopedAttribute.
@Test
public void setSessionScopedAttribute() {
MockHttpSession session = new MockHttpSession();
session.setAttribute(KEY, VALUE);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
ServletRequestAttributes attrs = new ServletRequestAttributes(request);
attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION);
assertThat(session.getAttribute(KEY)).isSameAs(VALUE);
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class ServletRequestAttributesTests method removeSessionScopedAttribute.
@Test
public void removeSessionScopedAttribute() {
MockHttpSession session = new MockHttpSession();
session.setAttribute(KEY, VALUE);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
ServletRequestAttributes attrs = new ServletRequestAttributes(request);
attrs.removeAttribute(KEY, RequestAttributes.SCOPE_SESSION);
Object value = session.getAttribute(KEY);
assertThat(value).isNull();
}
use of org.springframework.web.testfixture.servlet.MockHttpSession in project spring-framework by spring-projects.
the class ServletRequestAttributesTests method setSessionScopedAttributeAfterCompletion.
@Test
public void setSessionScopedAttributeAfterCompletion() {
MockHttpSession session = new MockHttpSession();
session.setAttribute(KEY, VALUE);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
ServletRequestAttributes attrs = new ServletRequestAttributes(request);
assertThat(attrs.getAttribute(KEY, RequestAttributes.SCOPE_SESSION)).isSameAs(VALUE);
attrs.requestCompleted();
request.close();
attrs.setAttribute(KEY, VALUE, RequestAttributes.SCOPE_SESSION);
assertThat(session.getAttribute(KEY)).isSameAs(VALUE);
}
Aggregations