@Test public final void testGetSessionCookieName() throws IOException, ServletException { final RequestTrackingHostValve cut = new RequestTrackingHostValve(null, "foo", _service, Statistics.create(), new AtomicBoolean( true ), new CurrentRequest()) { @Override protected String[] getSetCookieHeaders(final Response response) { final Collection<String> result = response.getHeaders("Set-Cookie"); return result.toArray(new String[result.size()]); } }; assertEquals(cut.getSessionCookieName(), "foo"); }
@Test public final void testChangeSessionIdForRelocatedSession() throws IOException, ServletException { final String sessionId = "bar"; final String newSessionId = "newId"; when(_request.getNote(eq(RequestTrackingHostValve.SESSION_ID_CHANGED))).thenReturn(Boolean.TRUE); when( _request.getRequestedSessionId() ).thenReturn( sessionId ); final Cookie cookie = new Cookie( _sessionTrackerValve.getSessionCookieName(), newSessionId ); setupGetResponseSetCookieHeadersExpectations(_response, new String[]{generateCookieString( cookie )}); _sessionTrackerValve.invoke( _request, _response ); verify( _service ).backupSession( eq( newSessionId ), eq( true ), anyString() ); }
@Test public final void testBackupSessionInvokedWhenResponseCookiePresent() throws IOException, ServletException { when( _request.getRequestedSessionId() ).thenReturn( null ); final Cookie cookie = new Cookie( _sessionTrackerValve.getSessionCookieName(), "foo" ); setupGetResponseSetCookieHeadersExpectations(_response, new String[]{generateCookieString( cookie )}); _sessionTrackerValve.invoke( _request, _response ); verify( _service ).backupSession( eq( "foo" ), eq( false), anyString() ); }