@Test public void shouldGraduallyRemoveAttributeByOverwritingByNull() { assertThat((String) session.getAttribute("attribute"), is("value")); session.setAttribute("attribute", null); assertThat(session.getAttribute("attribute"), is(nullValue())); }
@Test public void shouldGraduallyRemoveAttribute() { assertThat((String) session.getAttribute("attribute"), is("value")); session.removeAttribute("attribute"); assertThat(session.getAttribute("attribute"), is(nullValue())); }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenAccessingInvalidatedSession() { session.invalidate(); session.getAttribute("attribute"); }
@Test public void shouldPersistRestoreAndRemoveSession() throws IOException { HttpSessionImpl sessionWrapper = new HttpSessionImpl(VALID_SESSION_ID, System.currentTimeMillis()); sessionWrapper.setAttribute("attributeName", "SomeValue"); fileSessionStorage.persistSession(sessionWrapper); sessionWrapper = fileSessionStorage.getSession(VALID_SESSION_ID); assertThat(sessionWrapper, is(not(nullValue()))); assertThat((String) sessionWrapper.getAttribute("attributeName"), is("SomeValue")); fileSessionStorage.removeSession(sessionWrapper); sessionWrapper = fileSessionStorage.getSession(VALID_SESSION_ID); assertThat(sessionWrapper, is(nullValue())); }
@Test public void shouldPersistSessionAndOverWriteFile() throws IOException { HttpSessionImpl sessionWrapper = new HttpSessionImpl(VALID_SESSION_ID, System.currentTimeMillis()); sessionWrapper.setAttribute("attributeName", "SomeValue"); fileSessionStorage.persistSession(sessionWrapper); sessionWrapper = fileSessionStorage.getSession(VALID_SESSION_ID); assertThat(sessionWrapper, is(not(nullValue()))); assertThat((String) sessionWrapper.getAttribute("attributeName"), is("SomeValue")); HttpSessionImpl session2Wrapper = new HttpSessionImpl(VALID_SESSION_ID, System.currentTimeMillis()); session2Wrapper.setAttribute("otherName", "OtherValue"); fileSessionStorage.persistSession(session2Wrapper); sessionWrapper = fileSessionStorage.getSession(VALID_SESSION_ID); assertThat(sessionWrapper, is(not(nullValue()))); assertThat(sessionWrapper.getAttribute("attributeName"), is(nullValue())); assertThat((String) sessionWrapper.getAttribute("otherName"), is("OtherValue")); fileSessionStorage.removeSession(sessionWrapper); sessionWrapper = fileSessionStorage.getSession(VALID_SESSION_ID); assertThat(sessionWrapper, is(nullValue())); }