use of org.springframework.session.MapSessionRepository in project spring-session by spring-projects.
the class SessionRepositoryFilterTests method doFilterAdapterGetRequestedSessionId.
// --- HttpSessionIdResolver
@Test
public void doFilterAdapterGetRequestedSessionId() throws Exception {
SessionRepository<MapSession> sessionRepository = spy(new MapSessionRepository(new ConcurrentHashMap<>()));
this.filter = new SessionRepositoryFilter<>(sessionRepository);
this.filter.setHttpSessionIdResolver(this.strategy);
final String expectedId = "HttpSessionIdResolver-requested-id";
given(this.strategy.resolveSessionIds(any(HttpServletRequest.class))).willReturn(Collections.singletonList(expectedId));
given(sessionRepository.findById(anyString())).willReturn(new MapSession(expectedId));
doFilter(new DoInFilter() {
@Override
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
String actualId = wrappedRequest.getRequestedSessionId();
assertThat(actualId).isEqualTo(expectedId);
}
});
}
use of org.springframework.session.MapSessionRepository in project spring-session by spring-projects.
the class SessionRepositoryFilterTests method doFilterRequestSessionNoRequestSessionNoSessionRepositoryInteractions.
@Test
@SuppressWarnings("unchecked")
public void doFilterRequestSessionNoRequestSessionNoSessionRepositoryInteractions() throws Exception {
SessionRepository<MapSession> sessionRepository = spy(new MapSessionRepository(new ConcurrentHashMap<>()));
this.filter = new SessionRepositoryFilter<>(sessionRepository);
doFilter(new DoInFilter() {
@Override
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
wrappedRequest.getSession().getId();
}
});
reset(sessionRepository);
setupRequest();
doFilter(new DoInFilter() {
@Override
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
}
});
verifyZeroInteractions(sessionRepository);
}
use of org.springframework.session.MapSessionRepository in project spring-session by spring-projects.
the class SessionRepositoryFilterTests method doFilterSetsCookieIfChanged.
@Test
public void doFilterSetsCookieIfChanged() throws Exception {
this.sessionRepository = new MapSessionRepository(new ConcurrentHashMap<>()) {
@Override
public MapSession findById(String id) {
return createSession();
}
};
this.filter = new SessionRepositoryFilter<>(this.sessionRepository);
doFilter(new DoInFilter() {
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
wrappedRequest.getSession();
}
});
assertThat(this.response.getCookie("SESSION")).isNotNull();
nextRequest();
this.response.reset();
doFilter(new DoInFilter() {
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
assertThat(wrappedRequest.getSession().isNew()).isFalse();
}
});
assertThat(this.response.getCookie("SESSION")).isNotNull();
}
Aggregations