use of org.springframework.mock.web.test.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method doNotCopyAttributes.
@Test
public void doNotCopyAttributes() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
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);
assertEquals(1, attributes.size());
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
use of org.springframework.mock.web.test.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method defaultConstructor.
@Test
public void defaultConstructor() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
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);
assertEquals(3, attributes.size());
assertEquals("bar", attributes.get("foo"));
assertEquals("baz", attributes.get("bar"));
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
use of org.springframework.mock.web.test.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method constructorWithAttributeNames.
@Test
public void constructorWithAttributeNames() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
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);
assertEquals(2, attributes.size());
assertEquals("bar", attributes.get("foo"));
assertEquals("123", attributes.get(HttpSessionHandshakeInterceptor.HTTP_SESSION_ID_ATTR_NAME));
}
use of org.springframework.mock.web.test.MockHttpSession in project spring-framework by spring-projects.
the class HttpSessionHandshakeInterceptorTests method doNotCopyHttpSessionId.
@Test
public void doNotCopyHttpSessionId() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
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);
assertEquals(1, attributes.size());
assertEquals("bar", attributes.get("foo"));
}
use of org.springframework.mock.web.test.MockHttpSession in project spring-framework by spring-projects.
the class ServletRequestAttributesTests method removeSessionScopedAttribute.
@Test
public void removeSessionScopedAttribute() throws Exception {
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);
assertNull(value);
}
Aggregations