@Test public final void testProcessRequestNotePresent() throws IOException, ServletException { _sessionTrackerValve.invoke( _request, _response ); verify( _service, never() ).backupSession( anyString(), anyBoolean(), anyString() ); verify(_request).setNote(eq(RequestTrackingHostValve.REQUEST_PROCESS), eq(Boolean.TRUE)); }
@Test public final void testRequestFinishedShouldBeInvokedForIgnoredResources() throws IOException, ServletException { when( _request.getRequestedSessionId() ).thenReturn( "foo" ); when(_request.getRequestURI()).thenReturn("/pixel.gif"); _sessionTrackerValve.invoke( _request, _response ); verify( _service ).requestFinished( eq( "foo" ), anyString() ); }
@Test public final void testBackupSessionNotInvokedWhenNoSessionIdPresent() throws IOException, ServletException { when( _request.getRequestedSessionId() ).thenReturn( null ); when( _response.getHeader( eq( "Set-Cookie" ) ) ).thenReturn( null ); _sessionTrackerValve.invoke( _request, _response ); verify( _service, never() ).backupSession( anyString(), anyBoolean(), 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() ); }
@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() ); }