@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(); }
@Override public Mono<WebSession> getSession(ServerWebExchange exchange) { return Mono.defer(() -> retrieveSession(exchange) .switchIfEmpty(this.sessionStore.createWebSession()) .doOnNext(session -> exchange.getResponse().beforeCommit(() -> save(exchange, session)))); }
@Before public void setUp() throws Exception { when(this.createSession.save()).thenReturn(Mono.empty()); when(this.createSession.getId()).thenReturn("create-session-id"); when(this.updateSession.getId()).thenReturn("update-session-id"); when(this.sessionStore.createWebSession()).thenReturn(Mono.just(this.createSession)); when(this.sessionStore.retrieveSession(this.updateSession.getId())).thenReturn(Mono.just(this.updateSession)); this.sessionManager = new DefaultWebSessionManager(); this.sessionManager.setSessionIdResolver(this.sessionIdResolver); this.sessionManager.setSessionStore(this.sessionStore); MockServerHttpRequest request = MockServerHttpRequest.get("/path").build(); MockServerHttpResponse response = new MockServerHttpResponse(); this.exchange = new DefaultServerWebExchange(request, response, this.sessionManager, ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver()); }
@Override public Mono<WebSession> getSession(ServerWebExchange exchange) { return Mono.defer(() -> retrieveSession(exchange) .switchIfEmpty(this.sessionStore.createWebSession()) .doOnNext(session -> exchange.getResponse().beforeCommit(() -> save(exchange, session)))); }
@Override public Mono<WebSession> getSession(ServerWebExchange exchange) { return Mono.defer(() -> retrieveSession(exchange) .switchIfEmpty(this.sessionStore.createWebSession()) .doOnNext(session -> exchange.getResponse().beforeCommit(() -> save(exchange, session)))); }
@Override public Mono<WebSession> getSession(ServerWebExchange exchange) { return Mono.defer(() -> retrieveSession(exchange) .switchIfEmpty(this.sessionStore.createWebSession()) .doOnNext(session -> exchange.getResponse().beforeCommit(() -> save(exchange, session)))); }