use of org.springframework.web.server.WebSession in project spring-framework by spring-projects.
the class WebSessionIntegrationTests method expiredSession.
@Test
public void expiredSession() throws Exception {
// First request: no session yet, new session created
RequestEntity<Void> request = RequestEntity.get(createUri("/")).build();
ResponseEntity<Void> response = this.restTemplate.exchange(request, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
String id = extractSessionId(response.getHeaders());
assertNotNull(id);
assertEquals(1, this.handler.getCount());
// Second request: same session
request = RequestEntity.get(createUri("/")).header("Cookie", "SESSION=" + id).build();
response = this.restTemplate.exchange(request, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNull(response.getHeaders().get("Set-Cookie"));
assertEquals(2, this.handler.getCount());
// Update lastAccessTime of the created session to -31 min
WebSession session = this.sessionManager.getSessionStore().retrieveSession(id).block();
((DefaultWebSession) session).setLastAccessTime(Clock.offset(this.sessionManager.getClock(), Duration.ofMinutes(-31)).instant());
// Third request: expired session, new session created
request = RequestEntity.get(createUri("/")).header("Cookie", "SESSION=" + id).build();
response = this.restTemplate.exchange(request, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
id = extractSessionId(response.getHeaders());
assertNotNull("Expected new session id", id);
assertEquals("Expected new session attribute", 1, this.handler.getCount());
}
use of org.springframework.web.server.WebSession in project spring-session by spring-projects.
the class SpringSessionWebSessionStoreTests method createSessionWhenGetAttributesAndEntrySetThenDelegatesToCreateSession.
@Test
public void createSessionWhenGetAttributesAndEntrySetThenDelegatesToCreateSession() {
String attrName = "attrName";
given(this.createSession.getAttributeNames()).willReturn(Collections.singleton(attrName));
String attrValue = "attrValue";
given(this.createSession.getAttribute(attrName)).willReturn(attrValue);
WebSession createdWebSession = this.webSessionStore.createWebSession().block();
Map<String, Object> attributes = createdWebSession.getAttributes();
Set<Map.Entry<String, Object>> entries = attributes.entrySet();
assertThat(entries).containsExactly(new AbstractMap.SimpleEntry<>(attrName, attrValue));
}
use of org.springframework.web.server.WebSession in project spring-session by spring-projects.
the class SpringSessionWebSessionStoreTests method createSessionWhenGetAttributesAndContainsKeyAndFoundThenTrue.
@Test
public void createSessionWhenGetAttributesAndContainsKeyAndFoundThenTrue() {
given(this.createSession.getAttributeNames()).willReturn(Collections.singleton("a"));
WebSession createdWebSession = this.webSessionStore.createWebSession().block();
Map<String, Object> attributes = createdWebSession.getAttributes();
assertThat(attributes.containsKey("a")).isTrue();
}
use of org.springframework.web.server.WebSession in project spring-session by spring-projects.
the class SpringSessionWebSessionStoreTests method createSessionWhenAddAttributeThenStarted.
@Test
public void createSessionWhenAddAttributeThenStarted() {
given(this.createSession.getAttributeNames()).willReturn(Collections.singleton("a"));
WebSession createdWebSession = this.webSessionStore.createWebSession().block();
assertThat(createdWebSession.isStarted()).isTrue();
}
use of org.springframework.web.server.WebSession in project spring-session by spring-projects.
the class SpringSessionWebSessionStoreTests method createSessionWhenGetAttributesAndContainsKeyAndNotStringThenFalse.
@Test
public void createSessionWhenGetAttributesAndContainsKeyAndNotStringThenFalse() {
WebSession createdWebSession = this.webSessionStore.createWebSession().block();
Map<String, Object> attributes = createdWebSession.getAttributes();
assertThat(attributes.containsKey(1L)).isFalse();
}
Aggregations