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:
commit
a7fac3cbae
|
|
@ -60,6 +60,9 @@ public class SessionsEndpoint {
|
||||||
@ReadOperation
|
@ReadOperation
|
||||||
public SessionDescriptor getSession(@Selector String sessionId) {
|
public SessionDescriptor getSession(@Selector String sessionId) {
|
||||||
Session session = this.sessionRepository.findById(sessionId);
|
Session session = this.sessionRepository.findById(sessionId);
|
||||||
|
if (session == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new SessionDescriptor(session);
|
return new SessionDescriptor(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,12 @@ public class SessionsEndpointTests {
|
||||||
assertThat(result.isExpired()).isEqualTo(session.isExpired());
|
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
|
@Test
|
||||||
public void deleteSession() {
|
public void deleteSession() {
|
||||||
this.endpoint.deleteSession(session.getId());
|
this.endpoint.deleteSession(session.getId());
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,14 @@ public class SessionsEndpointWebIntegrationTests {
|
||||||
.isEqualTo(new JSONArray().appendElement(session.getId()));
|
.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
|
@Configuration
|
||||||
protected static class TestConfiguration {
|
protected static class TestConfiguration {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue