use of cn.taketoday.web.MockRequestContext in project today-framework by TAKETODAY.
the class DefaultWebSessionManagerTests method testWebSession.
@Test
public void testWebSession() {
try (StandardApplicationContext applicationContext = new StandardApplicationContext()) {
applicationContext.register(AppConfig.class);
applicationContext.refresh();
SessionManager sessionManager = applicationContext.getBean(SessionManager.class);
MockRequestContext context = new MockRequestContext();
WebSession noneExistingSession = sessionManager.getSession(context, false);
assertThat(noneExistingSession).isNull();
WebSession createdSession = sessionManager.getSession(context);
assertThat(createdSession).isNotNull();
// CookieTokenResolver
CookieSessionIdResolver cookieTokenResolver = applicationContext.getBean(CookieSessionIdResolver.class);
List<HttpCookie> responseCookies = context.responseCookies();
String sessionId = createdSession.getId();
HttpCookie sessionCookie = cookieTokenResolver.createCookie(sessionId);
assertThat(responseCookies).hasSize(1);
assertThat(responseCookies.get(0)).isEqualTo(sessionCookie);
// WebSessionStorage
SessionRepository sessionStorage = applicationContext.getBean(SessionRepository.class);
WebSession webSession = sessionStorage.retrieveSession(sessionId);
assertThat(webSession).isEqualTo(createdSession);
assertThat(sessionStorage.contains(sessionId)).isTrue();
sessionStorage.removeSession(sessionId);
assertThat(sessionStorage.contains(sessionId)).isFalse();
}
}
use of cn.taketoday.web.MockRequestContext in project today-infrastructure by TAKETODAY.
the class DefaultWebSessionManagerTests method testWebSession.
@Test
public void testWebSession() {
try (StandardApplicationContext applicationContext = new StandardApplicationContext()) {
applicationContext.register(AppConfig.class);
applicationContext.refresh();
SessionManager sessionManager = applicationContext.getBean(SessionManager.class);
MockRequestContext context = new MockRequestContext();
WebSession noneExistingSession = sessionManager.getSession(context, false);
assertThat(noneExistingSession).isNull();
WebSession createdSession = sessionManager.getSession(context);
assertThat(createdSession).isNotNull();
// CookieTokenResolver
CookieSessionIdResolver cookieTokenResolver = applicationContext.getBean(CookieSessionIdResolver.class);
List<HttpCookie> responseCookies = context.responseCookies();
String sessionId = createdSession.getId();
HttpCookie sessionCookie = cookieTokenResolver.createCookie(sessionId);
assertThat(responseCookies).hasSize(1);
assertThat(responseCookies.get(0)).isEqualTo(sessionCookie);
// WebSessionStorage
SessionRepository sessionStorage = applicationContext.getBean(SessionRepository.class);
WebSession webSession = sessionStorage.retrieveSession(sessionId);
assertThat(webSession).isEqualTo(createdSession);
assertThat(sessionStorage.contains(sessionId)).isTrue();
sessionStorage.removeSession(sessionId);
assertThat(sessionStorage.contains(sessionId)).isFalse();
}
}
Aggregations