use of org.springframework.mock.web.test.MockHttpSession in project spring-framework by spring-projects.
the class SessionScopeTests method getFromScope.
@Test
public void getFromScope() throws Exception {
AtomicInteger count = new AtomicInteger();
MockHttpSession session = new MockHttpSession() {
@Override
public void setAttribute(String name, Object value) {
super.setAttribute(name, value);
count.incrementAndGet();
}
};
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(session);
ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
String name = "sessionScopedObject";
assertNull(session.getAttribute(name));
TestBean bean = (TestBean) this.beanFactory.getBean(name);
assertEquals(1, count.intValue());
assertEquals(session.getAttribute(name), bean);
assertSame(bean, this.beanFactory.getBean(name));
assertEquals(1, count.intValue());
// should re-propagate updated attribute
requestAttributes.requestCompleted();
assertEquals(session.getAttribute(name), bean);
assertEquals(2, count.intValue());
}
use of org.springframework.mock.web.test.MockHttpSession in project spring-framework by spring-projects.
the class ServletRequestMethodArgumentResolverTests method session.
@Test
public void session() throws Exception {
MockHttpSession session = new MockHttpSession();
servletRequest.setSession(session);
MethodParameter sessionParameter = new MethodParameter(method, 2);
assertTrue("Session not supported", resolver.supportsParameter(sessionParameter));
Object result = resolver.resolveArgument(sessionParameter, mavContainer, webRequest, null);
assertSame("Invalid result", session, result);
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
}
Aggregations