@Test public void endpointsEachHaveSelf() throws Exception { Set<String> collections = new HashSet<String>(Arrays.asList("/trace", "/beans", "/dump")); for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) { String path = endpoint.getPath(); if (collections.contains(path)) { continue; } path = path.length() > 0 ? path : "/"; this.mockMvc .perform(get(path).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$._links.self.href").value("http://localhost" + endpoint.getPath())); } }
@Test public void endpointsAllListed() throws Exception { for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) { String path = endpoint.getPath(); if ("/actuator".equals(path)) { continue; } path = path.startsWith("/") ? path.substring(1) : path; this.mockMvc .perform(get("/actuator").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$._links.%s.href", path).exists()); } }
@Test public void endpointsDoNotHaveLinks() throws Exception { for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) { String path = endpoint.getPath(); if ("/actuator".equals(path)) { continue; } path = path.length() > 0 ? path : "/"; this.mockMvc .perform(get(path).accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$._links").doesNotExist()); } }
/** * Return the path that should be used to map the given {@link MvcEndpoint}. * * @param endpoint the endpoint to map * @return the path to use for the endpoint or {@code null} if no mapping is required */ protected String getPath(MvcEndpoint endpoint) { return endpoint.getPath(); }