Skip to content

Commit 644ab5f

Browse files
vpavicsnicoll
authored andcommitted
Align SessionsEndpoint with Spring Session API improvements
This commit aligns SessionsEndpoint with FindByIndexNameSessionRepository API improvements that simplifies retrieval of sessions by principal name. Closes gh-14124
1 parent 94d45c7 commit 644ab5f

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/SessionsEndpointDocumentationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ public void sessionsForUsername() throws Exception {
8989
sessions.put(sessionOne.getId(), sessionOne);
9090
sessions.put(sessionTwo.getId(), sessionTwo);
9191
sessions.put(sessionThree.getId(), sessionThree);
92-
given(this.sessionRepository.findByIndexNameAndIndexValue(
93-
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "alice"))
94-
.willReturn(sessions);
92+
given(this.sessionRepository.findByPrincipalName("alice")).willReturn(sessions);
9593
this.mockMvc.perform(get("/actuator/sessions").param("username", "alice"))
9694
.andExpect(status().isOk())
9795
.andDo(document("sessions/username",

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/session/SessionsEndpoint.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ public SessionsEndpoint(
5252
@ReadOperation
5353
public SessionsReport sessionsForUsername(String username) {
5454
Map<String, ? extends Session> sessions = this.sessionRepository
55-
.findByIndexNameAndIndexValue(
56-
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME,
57-
username);
55+
.findByPrincipalName(username);
5856
return new SessionsReport(sessions);
5957
}
6058

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ public class SessionsEndpointTests {
4848

4949
@Test
5050
public void sessionsForUsername() {
51-
given(this.repository.findByIndexNameAndIndexValue(
52-
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "user"))
53-
.willReturn(Collections.singletonMap(session.getId(), session));
51+
given(this.repository.findByPrincipalName("user"))
52+
.willReturn(Collections.singletonMap(session.getId(), session));
5453
List<SessionDescriptor> result = this.endpoint.sessionsForUsername("user")
5554
.getSessions();
5655
assertThat(result).hasSize(1);

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/session/SessionsEndpointWebIntegrationTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,9 +58,7 @@ public void sessionsForUsernameWithoutUsernameParam() {
5858

5959
@Test
6060
public void sessionsForUsernameNoResults() {
61-
given(repository.findByIndexNameAndIndexValue(
62-
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "user"))
63-
.willReturn(Collections.emptyMap());
61+
given(repository.findByPrincipalName("user")).willReturn(Collections.emptyMap());
6462
client.get()
6563
.uri((builder) -> builder.path("/actuator/sessions")
6664
.queryParam("username", "user").build())
@@ -70,9 +68,8 @@ public void sessionsForUsernameNoResults() {
7068

7169
@Test
7270
public void sessionsForUsernameFound() {
73-
given(repository.findByIndexNameAndIndexValue(
74-
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "user"))
75-
.willReturn(Collections.singletonMap(session.getId(), session));
71+
given(repository.findByPrincipalName("user"))
72+
.willReturn(Collections.singletonMap(session.getId(), session));
7673
client.get()
7774
.uri((builder) -> builder.path("/actuator/sessions")
7875
.queryParam("username", "user").build())

0 commit comments

Comments
 (0)