Merge pull request #11202 from ptahchiev:11201

* pr/11202:
  Polish "Fix NullPointer when requesting a session that does not exist"
  Fix NullPointer when requesting a session that does not exist
This commit is contained in:
Stephane Nicoll 2017-11-30 10:05:49 +01:00
commit a7fac3cbae
3 changed files with 17 additions and 0 deletions

View File

@ -60,6 +60,9 @@ public class SessionsEndpoint {
@ReadOperation
public SessionDescriptor getSession(@Selector String sessionId) {
Session session = this.sessionRepository.findById(sessionId);
if (session == null) {
return null;
}
return new SessionDescriptor(session);
}

View File

@ -81,6 +81,12 @@ public class SessionsEndpointTests {
assertThat(result.isExpired()).isEqualTo(session.isExpired());
}
@Test
public void getSessionWithIdNotFound() {
given(this.repository.findById("not-found")).willReturn(null);
assertThat(this.endpoint.getSession("not-found")).isNull();
}
@Test
public void deleteSession() {
this.endpoint.deleteSession(session.getId());

View File

@ -80,6 +80,14 @@ public class SessionsEndpointWebIntegrationTests {
.isEqualTo(new JSONArray().appendElement(session.getId()));
}
@Test
public void sessionForIdNotFound() {
client.get()
.uri((builder) -> builder.path(
"/actuator/sessions/session-id-not-found").build())
.exchange().expectStatus().isNotFound();
}
@Configuration
protected static class TestConfiguration {