Add Tests for Lazy Updates of Spring Session

Ensure that the session is only modified if it is accessed. This allows for
optimizations to ensure that for things like static resources there is
no need for hitting a data store.
This commit is contained in:
Rob Winch
2015-12-04 12:05:19 -06:00
parent 18a07abeb4
commit f14942edb0

View File

@@ -1165,6 +1165,39 @@ public class SessionRepositoryFilterTests {
verifyZeroInteractions(sessionRepository);
}
@Test
public void doFilterLazySessionCreation() throws Exception {
SessionRepository<ExpiringSession> sessionRepository = spy(new MapSessionRepository());
filter = new SessionRepositoryFilter<ExpiringSession>(sessionRepository);
doFilter(new DoInFilter(){
@Override
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
}
});
verifyZeroInteractions(sessionRepository);
}
@Test
public void doFilterLazySessionUpdates() throws Exception {
ExpiringSession session = this.sessionRepository.createSession();
this.sessionRepository.save(session);
SessionRepository<ExpiringSession> sessionRepository = spy(this.sessionRepository);
setSessionCookie(session.getId());
filter = new SessionRepositoryFilter<ExpiringSession>(sessionRepository);
doFilter(new DoInFilter(){
@Override
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
}
});
verifyZeroInteractions(sessionRepository);
}
// --- order
@Test