@Test public void multipleSessionIds() { List<String> ids = Arrays.asList("not-this", "not-that", this.updateSession.getId()); when(this.sessionStore.retrieveSession("not-this")).thenReturn(Mono.empty()); when(this.sessionStore.retrieveSession("not-that")).thenReturn(Mono.empty()); when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(ids); WebSession actual = this.sessionManager.getSession(this.exchange).block(); assertNotNull(actual); assertEquals(this.updateSession.getId(), actual.getId()); } }
@Test public void getSessionSaveWhenCreatedAndStartedThenSavesAndSetsId() { when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.emptyList()); WebSession session = this.sessionManager.getSession(this.exchange).block(); assertSame(this.createSession, session); String sessionId = this.createSession.getId(); when(this.createSession.isStarted()).thenReturn(true); this.exchange.getResponse().setComplete().block(); verify(this.sessionStore).createWebSession(); verify(this.sessionIdResolver).setSessionId(any(), eq(sessionId)); verify(this.createSession).save(); }
@Test public void getSessionSaveWhenCreatedAndNotStartedThenNotSaved() { when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.emptyList()); WebSession session = this.sessionManager.getSession(this.exchange).block(); this.exchange.getResponse().setComplete().block(); assertSame(this.createSession, session); assertFalse(session.isStarted()); assertFalse(session.isExpired()); verify(this.createSession, never()).save(); verify(this.sessionIdResolver, never()).setSessionId(any(), any()); }
@Test public void existingSession() { String sessionId = this.updateSession.getId(); when(this.sessionIdResolver.resolveSessionIds(this.exchange)).thenReturn(Collections.singletonList(sessionId)); WebSession actual = this.sessionManager.getSession(this.exchange).block(); assertNotNull(actual); assertEquals(sessionId, actual.getId()); }