diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/CachesEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/CachesEndpointDocumentationTests.java index 8bff0fa755..9f657419d1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/CachesEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/CachesEndpointDocumentationTests.java @@ -68,9 +68,9 @@ public class CachesEndpointDocumentationTests extends MockMvcEndpointDocumentati .andDo(MockMvcRestDocumentation.document("caches/all", responseFields( fieldWithPath("cacheManagers") .description("Cache managers keyed by id."), - fieldWithPath("cacheManagers.*").description( + fieldWithPath("cacheManagers.*.caches").description( "Caches in the application context keyed by " + "name.")) - .andWithPrefix("cacheManagers.*.*.", + .andWithPrefix("cacheManagers.*.caches.*.", fieldWithPath("target").description( "Fully qualified name of the native cache.")))); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java index 4b31bdef20..afcdc0c8b4 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/cache/CachesEndpoint.java @@ -67,7 +67,10 @@ public class CachesEndpoint { cacheManagerDescriptors.put(cacheName, new CacheDescriptor(entry.getTarget())); }); - return new CachesReport(descriptors); + Map cacheManagerDescriptors = new LinkedHashMap<>(); + descriptors.forEach((name, entries) -> + cacheManagerDescriptors.put(name, new CacheManagerDescriptor(entries))); + return new CachesReport(cacheManagerDescriptors); } /** @@ -160,18 +163,36 @@ public class CachesEndpoint { */ public static final class CachesReport { - private final Map> cacheManagers; + private final Map cacheManagers; - public CachesReport(Map> cacheManagers) { + public CachesReport(Map cacheManagers) { this.cacheManagers = cacheManagers; } - public Map> getCacheManagers() { + public Map getCacheManagers() { return this.cacheManagers; } } + /** + * Description of a {@link CacheManager}, primarily intended for serialization to + * JSON. + */ + public static final class CacheManagerDescriptor { + + private final Map caches; + + public CacheManagerDescriptor(Map caches) { + this.caches = caches; + } + + public Map getCaches() { + return this.caches; + } + + } + /** * Basic description of a {@link Cache}, primarily intended for serialization to JSON. */ diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java index 7a26912668..5777c9d738 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointTests.java @@ -26,8 +26,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.boot.actuate.cache.CachesEndpoint.CacheDescriptor; import org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry; +import org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; @@ -53,14 +53,14 @@ public class CachesEndpointTests { public void allCachesWithSingleCacheManager() { CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", new ConcurrentMapCacheManager("a", "b"))); - Map> allDescriptors = endpoint.caches() + Map allDescriptors = endpoint.caches() .getCacheManagers(); assertThat(allDescriptors).containsOnlyKeys("test"); - Map descriptors = allDescriptors.get("test"); - assertThat(descriptors).containsOnlyKeys("a", "b"); - assertThat(descriptors.get("a").getTarget()) + CacheManagerDescriptor descriptors = allDescriptors.get("test"); + assertThat(descriptors.getCaches()).containsOnlyKeys("a", "b"); + assertThat(descriptors.getCaches().get("a").getTarget()) .isEqualTo(ConcurrentHashMap.class.getName()); - assertThat(descriptors.get("b").getTarget()) + assertThat(descriptors.getCaches().get("b").getTarget()) .isEqualTo(ConcurrentHashMap.class.getName()); } @@ -70,11 +70,11 @@ public class CachesEndpointTests { cacheManagers.put("test", new ConcurrentMapCacheManager("a", "b")); cacheManagers.put("another", new ConcurrentMapCacheManager("a", "c")); CachesEndpoint endpoint = new CachesEndpoint(cacheManagers); - Map> allDescriptors = endpoint.caches() + Map allDescriptors = endpoint.caches() .getCacheManagers(); assertThat(allDescriptors).containsOnlyKeys("test", "another"); - assertThat(allDescriptors.get("test")).containsOnlyKeys("a", "b"); - assertThat(allDescriptors.get("another")).containsOnlyKeys("a", "c"); + assertThat(allDescriptors.get("test").getCaches()).containsOnlyKeys("a", "b"); + assertThat(allDescriptors.get("another").getCaches()).containsOnlyKeys("a", "c"); } @Test diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointWebIntegrationTests.java index 95a664a351..1f547a6f5c 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointWebIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cache/CachesEndpointWebIntegrationTests.java @@ -49,13 +49,13 @@ public class CachesEndpointWebIntegrationTests { @Test public void allCaches() { client.get().uri("/actuator/caches").exchange().expectStatus().isOk().expectBody() - .jsonPath("cacheManagers.one.a.target") + .jsonPath("cacheManagers.one.caches.a.target") .isEqualTo(ConcurrentHashMap.class.getName()) - .jsonPath("cacheManagers.one.b.target") + .jsonPath("cacheManagers.one.caches.b.target") .isEqualTo(ConcurrentHashMap.class.getName()) - .jsonPath("cacheManagers.two.a.target") + .jsonPath("cacheManagers.two.caches.a.target") .isEqualTo(ConcurrentHashMap.class.getName()) - .jsonPath("cacheManagers.two.c.target") + .jsonPath("cacheManagers.two.caches.c.target") .isEqualTo(ConcurrentHashMap.class.getName()); }