Move all actuators under `/application`

Context path can be configured via `management.context-path`.

Closes gh-6886
pull/95/merge
Madhura Bhave 8 years ago
parent 92468d4ffc
commit bcd79dd992

@ -97,7 +97,7 @@ public class EndpointDocumentation {
@Test
public void logfile() throws Exception {
this.mockMvc.perform(get("/logfile").accept(MediaType.TEXT_PLAIN))
this.mockMvc.perform(get("/application/logfile").accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk()).andDo(document("logfile"));
}
@ -106,7 +106,7 @@ public class EndpointDocumentation {
FileCopyUtils.copy(getClass().getResourceAsStream("log.txt"),
new FileOutputStream(LOG_FILE));
this.mockMvc
.perform(get("/logfile").accept(MediaType.TEXT_PLAIN)
.perform(get("/application/logfile").accept(MediaType.TEXT_PLAIN)
.header(HttpHeaders.RANGE, "bytes=0-1024"))
.andExpect(status().isPartialContent())
.andDo(document("partial-logfile"));
@ -115,7 +115,7 @@ public class EndpointDocumentation {
@Test
public void singleLogger() throws Exception {
this.mockMvc
.perform(get("/loggers/org.springframework.boot")
.perform(get("/application/loggers/org.springframework.boot")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andDo(document("single-logger"));
}
@ -123,7 +123,7 @@ public class EndpointDocumentation {
@Test
public void setLogger() throws Exception {
this.mockMvc
.perform(post("/loggers/org.springframework.boot")
.perform(post("/application/loggers/org.springframework.boot")
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
.content("{\"configuredLevel\": \"DEBUG\"}"))
.andExpect(status().isOk()).andDo(document("set-logger"));
@ -132,7 +132,7 @@ public class EndpointDocumentation {
@Test
public void auditEvents() throws Exception {
this.mockMvc
.perform(get("/auditevents").param("after", "2016-11-01T10:00:00+0000")
.perform(get("/application/auditevents").param("after", "2016-11-01T10:00:00+0000")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()).andDo(document("auditevents"));
}
@ -140,7 +140,7 @@ public class EndpointDocumentation {
@Test
public void auditEventsByPrincipal() throws Exception {
this.mockMvc
.perform(get("/auditevents").param("principal", "admin")
.perform(get("/application/auditevents").param("principal", "admin")
.param("after", "2016-11-01T10:00:00+0000")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk())
@ -150,7 +150,7 @@ public class EndpointDocumentation {
@Test
public void auditEventsByPrincipalAndType() throws Exception {
this.mockMvc
.perform(get("/auditevents").param("principal", "admin")
.perform(get("/application/auditevents").param("principal", "admin")
.param("after", "2016-11-01T10:00:00+0000")
.param("type", "AUTHENTICATION_SUCCESS")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
@ -171,7 +171,7 @@ public class EndpointDocumentation {
String output = endpointPath.substring(1);
output = output.length() > 0 ? output : "./";
this.mockMvc
.perform(get(endpointPath)
.perform(get("/application" + endpointPath)
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()).andDo(document(output))
.andDo(new ResultHandler() {

@ -51,7 +51,7 @@ public class HealthEndpointDocumentation {
@Test
public void health() throws Exception {
this.mockMvc
.perform(get("/health")
.perform(get("/application/health")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()).andDo(document("health/insensitive"));
}

@ -52,7 +52,7 @@ public class HypermediaEndpointDocumentation {
@Test
public void beans() throws Exception {
this.mockMvc
.perform(get("/beans")
.perform(get("/application/beans")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()).andDo(document("beans/hypermedia"));
}
@ -60,18 +60,18 @@ public class HypermediaEndpointDocumentation {
@Test
public void metrics() throws Exception {
this.mockMvc
.perform(get("/metrics")
.perform(get("/application/metrics")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._links.self.href")
.value("http://localhost:8080/metrics"))
.value("http://localhost:8080/application/metrics"))
.andDo(document("metrics/hypermedia"));
}
@Test
public void home() throws Exception {
this.mockMvc
.perform(get("/actuator")
.perform(get("/application")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()).andDo(document("admin"));
}

@ -79,7 +79,7 @@ public class ManagementServerProperties implements SecurityPrerequisite {
/**
* Management endpoint context-path.
*/
private String contextPath = "";
private String contextPath = "/application";
/**
* Add the "X-Application-Context" HTTP header in each response.

@ -44,7 +44,7 @@ public class HalJsonMvcEndpoint extends AbstractNamedMvcEndpoint {
if (StringUtils.hasText(managementServletContext.getContextPath())) {
return "";
}
return "/actuator";
return "/application";
}
@ActuatorGetMapping

@ -49,35 +49,35 @@ public class BootCuriesHrefIntegrationTests {
@Test
public void basicCuriesHref() {
int port = load("endpoints.docs.curies.enabled:true", "server.port:0");
assertThat(getCurieHref("http://localhost:" + port + "/actuator")).isEqualTo(
"http://localhost:" + port + "/docs/#spring_boot_actuator__{rel}");
assertThat(getCurieHref("http://localhost:" + port + "/application")).isEqualTo(
"http://localhost:" + port + "/application/docs/#spring_boot_actuator__{rel}");
}
@Test
public void curiesHrefWithCustomContextPath() {
int port = load("endpoints.docs.curies.enabled:true", "server.port:0",
"server.servlet.context-path:/context");
assertThat(getCurieHref("http://localhost:" + port + "/context/actuator"))
assertThat(getCurieHref("http://localhost:" + port + "/context/application"))
.isEqualTo("http://localhost:" + port
+ "/context/docs/#spring_boot_actuator__{rel}");
+ "/context/application/docs/#spring_boot_actuator__{rel}");
}
@Test
public void curiesHrefWithCustomServletPath() {
int port = load("endpoints.docs.curies.enabled:true", "server.port:0",
"server.servlet.path:/servlet");
assertThat(getCurieHref("http://localhost:" + port + "/servlet/actuator"))
assertThat(getCurieHref("http://localhost:" + port + "/servlet/application"))
.isEqualTo("http://localhost:" + port
+ "/servlet/docs/#spring_boot_actuator__{rel}");
+ "/servlet/application/docs/#spring_boot_actuator__{rel}");
}
@Test
public void curiesHrefWithCustomServletAndContextPaths() {
int port = load("endpoints.docs.curies.enabled:true", "server.port:0",
"server.servlet.context-path:/context", "server.servlet.path:/servlet");
assertThat(getCurieHref("http://localhost:" + port + "/context/servlet/actuator"))
assertThat(getCurieHref("http://localhost:" + port + "/context/servlet/application"))
.isEqualTo("http://localhost:" + port
+ "/context/servlet/docs/#spring_boot_actuator__{rel}");
+ "/context/servlet/application/docs/#spring_boot_actuator__{rel}");
}
@Test
@ -95,8 +95,8 @@ public class BootCuriesHrefIntegrationTests {
int port = load("endpoints.docs.curies.enabled:true", "server.port:0",
"server.servlet.context-path:/context", "server.servlet.path:/servlet",
"management.port:0");
assertThat(getCurieHref("http://localhost:" + port + "/actuator/")).isEqualTo(
"http://localhost:" + port + "/docs/#spring_boot_actuator__{rel}");
assertThat(getCurieHref("http://localhost:" + port + "/application/")).isEqualTo(
"http://localhost:" + port + "/application/docs/#spring_boot_actuator__{rel}");
}
@Test

@ -85,7 +85,7 @@ public class EndpointMvcIntegrationTests {
@Test
public void envEndpointNotHidden() throws InterruptedException {
String body = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + "/env/foo.bar", String.class);
"http://localhost:" + this.port + "/application/env/foo.bar", String.class);
assertThat(body).isNotNull().contains("\"baz\"");
assertThat(this.interceptor.invoked()).isTrue();
}
@ -93,7 +93,7 @@ public class EndpointMvcIntegrationTests {
@Test
public void healthEndpointNotHidden() throws InterruptedException {
String body = new TestRestTemplate()
.getForObject("http://localhost:" + this.port + "/health", String.class);
.getForObject("http://localhost:" + this.port + "/application/health", String.class);
assertThat(body).isNotNull().contains("status");
assertThat(this.interceptor.invoked()).isTrue();
}

@ -80,28 +80,28 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
public void curiesEnabledWithDefaultPorts() {
load("endpoints.docs.curies.enabled:true");
assertThat(getCurieHref())
.isEqualTo("http://localhost/docs/#spring_boot_actuator__{rel}");
.isEqualTo("http://localhost/application/docs/#spring_boot_actuator__{rel}");
}
@Test
public void curiesEnabledWithRandomPorts() {
load("endpoints.docs.curies.enabled:true", "server.port:0", "management.port:0");
assertThat(getCurieHref())
.isEqualTo("http://localhost/docs/#spring_boot_actuator__{rel}");
.isEqualTo("http://localhost/application/docs/#spring_boot_actuator__{rel}");
}
@Test
public void curiesEnabledWithSpecificServerPort() {
load("endpoints.docs.curies.enabled:true", "server.port:8080");
assertThat(getCurieHref())
.isEqualTo("http://localhost/docs/#spring_boot_actuator__{rel}");
.isEqualTo("http://localhost/application/docs/#spring_boot_actuator__{rel}");
}
@Test
public void curiesEnabledWithSpecificManagementPort() {
load("endpoints.docs.curies.enabled:true", "management.port:8081");
assertThat(getCurieHref())
.isEqualTo("http://localhost/docs/#spring_boot_actuator__{rel}");
.isEqualTo("http://localhost/application/docs/#spring_boot_actuator__{rel}");
}
@Test
@ -109,7 +109,7 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
load("endpoints.docs.curies.enabled:true", "server.port:8080",
"management.port:8081");
assertThat(getCurieHref())
.isEqualTo("http://localhost/docs/#spring_boot_actuator__{rel}");
.isEqualTo("http://localhost/application/docs/#spring_boot_actuator__{rel}");
}
private void load(String... properties) {

@ -74,7 +74,7 @@ public class EndpointWebMvcManagementContextConfigurationTests {
this.context.refresh();
EndpointHandlerMapping mapping = this.context.getBean("endpointHandlerMapping",
EndpointHandlerMapping.class);
assertThat(mapping.getPrefix()).isEmpty();
assertThat(mapping.getPrefix()).isEqualTo("/application");
MvcEndpointSecurityInterceptor securityInterceptor = (MvcEndpointSecurityInterceptor) ReflectionTestUtils
.getField(mapping, "securityInterceptor");
Object secure = ReflectionTestUtils.getField(securityInterceptor, "secure");

@ -46,7 +46,7 @@ public class ManagementServerPropertiesTests {
public void defaultManagementServerProperties() {
ManagementServerProperties properties = new ManagementServerProperties();
assertThat(properties.getPort()).isNull();
assertThat(properties.getContextPath()).isEqualTo("");
assertThat(properties.getContextPath()).isEqualTo("/application");
assertThat(properties.getAddApplicationContextHeader()).isEqualTo(false);
}

@ -97,10 +97,10 @@ public class ManagementWebSecurityAutoConfigurationTests {
FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
// 1 for static resources, one for management endpoints and one for the rest
assertThat(filterChainProxy.getFilterChains()).hasSize(3);
assertThat(filterChainProxy.getFilters("/beans")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans/")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans.foo")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans/foo/bar")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/application/beans")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/application/beans/")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/application/beans.foo")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/application/beans/foo/bar")).isNotEmpty();
}
@Test

@ -74,14 +74,14 @@ public class AuditEventsMvcEndpointTests {
@Test
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/auditevents")).andExpect(status().isOk())
this.mvc.perform(get("/application/auditevents")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
}
@Test
public void contentTypeCanBeApplicationJson() throws Exception {
this.mvc.perform(get("/auditevents").header(HttpHeaders.ACCEPT,
this.mvc.perform(get("/application/auditevents").header(HttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));
@ -90,20 +90,20 @@ public class AuditEventsMvcEndpointTests {
@Test
public void invokeWhenDisabledShouldReturnNotFoundStatus() throws Exception {
this.context.getBean(AuditEventsMvcEndpoint.class).setEnabled(false);
this.mvc.perform(get("/auditevents").param("after", "2016-11-01T10:00:00+0000"))
this.mvc.perform(get("/application/auditevents").param("after", "2016-11-01T10:00:00+0000"))
.andExpect(status().isNotFound());
}
@Test
public void invokeFilterByDateAfter() throws Exception {
this.mvc.perform(get("/auditevents").param("after", "2016-11-01T13:00:00+0000"))
this.mvc.perform(get("/application/auditevents").param("after", "2016-11-01T13:00:00+0000"))
.andExpect(status().isOk())
.andExpect(content().string("{\"events\":[]}"));
}
@Test
public void invokeFilterByPrincipalAndDateAfter() throws Exception {
this.mvc.perform(get("/auditevents").param("principal", "user").param("after",
this.mvc.perform(get("/application/auditevents").param("principal", "user").param("after",
"2016-11-01T10:00:00+0000"))
.andExpect(status().isOk())
.andExpect(content().string(
@ -113,7 +113,7 @@ public class AuditEventsMvcEndpointTests {
@Test
public void invokeFilterByPrincipalAndDateAfterAndType() throws Exception {
this.mvc.perform(get("/auditevents").param("principal", "admin")
this.mvc.perform(get("/application/auditevents").param("principal", "admin")
.param("after", "2016-11-01T10:00:00+0000").param("type", "logout"))
.andExpect(status().isOk())
.andExpect(content().string(

@ -80,7 +80,7 @@ public class EnvironmentMvcEndpointTests {
@Test
public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/env")).andExpect(status().isOk())
this.mvc.perform(get("/application/env")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
}
@ -88,21 +88,21 @@ public class EnvironmentMvcEndpointTests {
@Test
public void homeContentTypeCanBeApplicationJson() throws Exception {
this.mvc.perform(
get("/env").header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE))
get("/application/env").header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk()).andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));
}
@Test
public void subContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/env/foo")).andExpect(status().isOk())
this.mvc.perform(get("/application/env/foo")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
}
@Test
public void subContentTypeCanBeApplicationJson() throws Exception {
this.mvc.perform(get("/env/foo").header(HttpHeaders.ACCEPT,
this.mvc.perform(get("/application/env/foo").header(HttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));
@ -110,20 +110,20 @@ public class EnvironmentMvcEndpointTests {
@Test
public void home() throws Exception {
this.mvc.perform(get("/env")).andExpect(status().isOk())
this.mvc.perform(get("/application/env")).andExpect(status().isOk())
.andExpect(content().string(containsString("systemProperties")));
}
@Test
public void sub() throws Exception {
this.mvc.perform(get("/env/foo")).andExpect(status().isOk())
this.mvc.perform(get("/application/env/foo")).andExpect(status().isOk())
.andExpect(content().string("{\"foo\":\"bar\"}"));
}
@Test
public void subWhenDisabled() throws Exception {
this.context.getBean(EnvironmentEndpoint.class).setEnabled(false);
this.mvc.perform(get("/env/foo")).andExpect(status().isNotFound());
this.mvc.perform(get("/application/env/foo")).andExpect(status().isNotFound());
}
@Test
@ -132,7 +132,7 @@ public class EnvironmentMvcEndpointTests {
map.put("food", null);
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
.addFirst(new MapPropertySource("null-value", map));
this.mvc.perform(get("/env/foo.*")).andExpect(status().isOk())
this.mvc.perform(get("/application/env/foo.*")).andExpect(status().isOk())
.andExpect(content().string(containsString("\"foo\":\"bar\"")))
.andExpect(content().string(containsString("\"fool\":\"baz\"")));
}
@ -144,7 +144,7 @@ public class EnvironmentMvcEndpointTests {
map.put("my.foo", "${my.bar}");
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
.addFirst(new MapPropertySource("unresolved-placeholder", map));
this.mvc.perform(get("/env/my.*")).andExpect(status().isOk())
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())
.andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\"")));
}
@ -155,7 +155,7 @@ public class EnvironmentMvcEndpointTests {
map.put("my.password", "hello");
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
.addFirst(new MapPropertySource("placeholder", map));
this.mvc.perform(get("/env/my.*")).andExpect(status().isOk())
this.mvc.perform(get("/application/env/my.*")).andExpect(status().isOk())
.andExpect(content().string(containsString("\"my.foo\":\"******\"")));
}

@ -61,16 +61,16 @@ public class HalBrowserMvcEndpointBrowserPathIntegrationTests {
@Test
public void requestWithTrailingSlashIsRedirectedToBrowserHtml() throws Exception {
this.mockMvc.perform(get("/actuator/").accept(MediaType.TEXT_HTML))
this.mockMvc.perform(get("/application/actuator/").accept(MediaType.TEXT_HTML))
.andExpect(status().isFound()).andExpect(header().string(
HttpHeaders.LOCATION, "http://localhost/actuator/browser.html"));
HttpHeaders.LOCATION, "http://localhost/application/actuator/browser.html"));
}
@Test
public void requestWithoutTrailingSlashIsRedirectedToBrowserHtml() throws Exception {
this.mockMvc.perform(get("/actuator").accept(MediaType.TEXT_HTML))
this.mockMvc.perform(get("/application/actuator").accept(MediaType.TEXT_HTML))
.andExpect(status().isFound()).andExpect(header().string("location",
"http://localhost/actuator/browser.html"));
"http://localhost/application/actuator/browser.html"));
}
@MinimalActuatorHypermediaApplication

@ -67,26 +67,26 @@ public class HalBrowserMvcEndpointDisabledIntegrationTests {
@Test
public void linksOnActuator() throws Exception {
this.mockMvc.perform(get("/actuator").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(jsonPath("$._links").exists())
.andExpect(header().doesNotExist("cache-control"));
}
@Test
public void browserRedirect() throws Exception {
this.mockMvc.perform(get("/actuator/").accept(MediaType.TEXT_HTML))
this.mockMvc.perform(get("/application/").accept(MediaType.TEXT_HTML))
.andExpect(status().isFound()).andExpect(header().string(
HttpHeaders.LOCATION, "http://localhost/actuator/browser.html"));
HttpHeaders.LOCATION, "http://localhost/application/browser.html"));
}
@Test
public void endpointsDoNotHaveLinks() throws Exception {
for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) {
String path = endpoint.getPath();
if ("/actuator".equals(path) || endpoint instanceof HeapdumpMvcEndpoint) {
if ("".equals(path) || endpoint instanceof HeapdumpMvcEndpoint) {
continue;
}
path = path.length() > 0 ? path : "/";
path = "/application" + (path.length() > 0 ? path : "/");
MockHttpServletRequestBuilder requestBuilder = get(path);
if (endpoint instanceof AuditEventsMvcEndpoint) {
requestBuilder.param("after", "2016-01-01T12:00:00+00:00");

@ -74,11 +74,11 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET,
"http://localhost:" + this.port + "/spring/application/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create(
"http://localhost:" + this.port + "/spring/actuator/browser.html"));
"http://localhost:" + this.port + "/spring/application/browser.html"));
}
@Test
@ -86,10 +86,10 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/browser.html",
"http://localhost:" + this.port + "/spring/application/browser.html",
HttpMethod.GET, new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("entryPoint: '/spring/actuator'");
assertThat(entity.getBody()).contains("entryPoint: '/spring/application'");
}
@Test
@ -97,7 +97,7 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator", HttpMethod.GET,
"http://localhost:" + this.port + "/spring/application", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\":");
@ -108,7 +108,7 @@ public class HalBrowserMvcEndpointServerContextPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET,
"http://localhost:" + this.port + "/spring/application/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\":");

@ -63,7 +63,7 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/actuator", HttpMethod.GET,
"http://localhost:" + this.port + "/application", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\":");
@ -75,7 +75,7 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/actuator/", HttpMethod.GET,
"http://localhost:" + this.port + "/application/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\":");
@ -87,11 +87,11 @@ public class HalBrowserMvcEndpointServerPortIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/actuator/", HttpMethod.GET,
"http://localhost:" + this.port + "/application/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation()).isEqualTo(
URI.create("http://localhost:" + this.port + "/actuator/browser.html"));
URI.create("http://localhost:" + this.port + "/application/browser.html"));
}
@MinimalActuatorHypermediaApplication

@ -74,11 +74,11 @@ public class HalBrowserMvcEndpointServerServletPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET,
"http://localhost:" + this.port + "/spring/application/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation()).isEqualTo(URI.create(
"http://localhost:" + this.port + "/spring/actuator/browser.html"));
"http://localhost:" + this.port + "/spring/application/browser.html"));
}
@Test
@ -86,10 +86,10 @@ public class HalBrowserMvcEndpointServerServletPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/browser.html",
"http://localhost:" + this.port + "/spring/application/browser.html",
HttpMethod.GET, new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("entryPoint: '/spring/actuator'");
assertThat(entity.getBody()).contains("entryPoint: '/spring/application'");
}
@Test
@ -97,7 +97,7 @@ public class HalBrowserMvcEndpointServerServletPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator", HttpMethod.GET,
"http://localhost:" + this.port + "/spring/application", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\":");
@ -108,7 +108,7 @@ public class HalBrowserMvcEndpointServerServletPathIntegrationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/spring/actuator/", HttpMethod.GET,
"http://localhost:" + this.port + "/spring/application/", HttpMethod.GET,
new HttpEntity<Void>(null, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\":");

@ -70,35 +70,35 @@ public class HalBrowserMvcEndpointVanillaIntegrationTests {
@Test
public void links() throws Exception {
this.mockMvc.perform(get("/actuator").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(jsonPath("$._links").exists())
.andExpect(header().doesNotExist("cache-control"));
}
@Test
public void linksWithTrailingSlash() throws Exception {
this.mockMvc.perform(get("/actuator/").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(jsonPath("$._links").exists())
.andExpect(header().doesNotExist("cache-control"));
}
@Test
public void browser() throws Exception {
this.mockMvc.perform(get("/actuator/").accept(MediaType.TEXT_HTML))
this.mockMvc.perform(get("/application/").accept(MediaType.TEXT_HTML))
.andExpect(status().isFound()).andExpect(header().string(
HttpHeaders.LOCATION, "http://localhost/actuator/browser.html"));
HttpHeaders.LOCATION, "http://localhost/application/browser.html"));
}
@Test
public void trace() throws Exception {
this.mockMvc.perform(get("/trace").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application/trace").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(jsonPath("$._links").doesNotExist())
.andExpect(jsonPath("$").isArray());
}
@Test
public void envValue() throws Exception {
this.mockMvc.perform(get("/env/user.home").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application/env/user.home").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._links").doesNotExist());
}
@ -107,11 +107,11 @@ public class HalBrowserMvcEndpointVanillaIntegrationTests {
public void endpointsAllListed() throws Exception {
for (MvcEndpoint endpoint : this.mvcEndpoints.getEndpoints()) {
String path = endpoint.getPath();
if ("/actuator".equals(path)) {
if ("/application".equals(path)) {
continue;
}
path = path.startsWith("/") ? path.substring(1) : path;
this.mockMvc.perform(get("/actuator").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._links.%s.href", path).exists());
}
@ -126,10 +126,10 @@ public class HalBrowserMvcEndpointVanillaIntegrationTests {
if (collections.contains(path)) {
continue;
}
path = path.length() > 0 ? path : "/";
path = "/application" + (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()));
.value("http://localhost/application" + endpoint.getPath()));
}
}

@ -0,0 +1,56 @@
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.endpoint.mvc;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link HalJsonMvcEndpoint}.
*
* @author Madhura Bhave
*/
public class HalJsonMvcEndpointTests {
@Mock
ManagementServletContext managementServletContext;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test
public void halJsonEndpointPathWhenManagementContextPathPresent() throws Exception {
Mockito.when(this.managementServletContext.getContextPath()).thenReturn("my-app");
HalJsonMvcEndpoint endpoint = new HalJsonMvcEndpoint(this.managementServletContext);
assertThat(endpoint.getPath()).isEqualTo("");
}
@Test
public void halJsonEndpointPathWhenManagementContextPathNotPresent() throws Exception {
Mockito.when(this.managementServletContext.getContextPath()).thenReturn("");
HalJsonMvcEndpoint endpoint = new HalJsonMvcEndpoint(this.managementServletContext);
assertThat(endpoint.getPath()).isEqualTo("/application");
}
}

@ -73,7 +73,7 @@ public class HeapdumpMvcEndpointSecureOptionsTests {
@Test
public void invokeOptionsShouldReturnSize() throws Exception {
this.mvc.perform(options("/heapdump")).andExpect(status().isOk());
this.mvc.perform(options("/application/heapdump")).andExpect(status().isOk());
}
@Import({ JacksonAutoConfiguration.class,

@ -82,26 +82,26 @@ public class HeapdumpMvcEndpointTests {
@Test
public void invokeWhenDisabledShouldReturnNotFoundStatus() throws Exception {
this.endpoint.setEnabled(false);
this.mvc.perform(get("/heapdump")).andExpect(status().isNotFound());
this.mvc.perform(get("/application/heapdump")).andExpect(status().isNotFound());
}
@Test
public void invokeWhenNotAvailableShouldReturnServiceUnavailableStatus()
throws Exception {
this.endpoint.setAvailable(false);
this.mvc.perform(get("/heapdump")).andExpect(status().isServiceUnavailable());
this.mvc.perform(get("/application/heapdump")).andExpect(status().isServiceUnavailable());
}
@Test
public void invokeWhenLockedShouldReturnTooManyRequestsStatus() throws Exception {
this.endpoint.setLocked(true);
this.mvc.perform(get("/heapdump")).andExpect(status().isTooManyRequests());
this.mvc.perform(get("/application/heapdump")).andExpect(status().isTooManyRequests());
assertThat(Thread.interrupted()).isTrue();
}
@Test
public void invokeShouldReturnGzipContent() throws Exception {
MvcResult result = this.mvc.perform(get("/heapdump")).andExpect(status().isOk())
MvcResult result = this.mvc.perform(get("/application/heapdump")).andExpect(status().isOk())
.andReturn();
byte[] bytes = result.getResponse().getContentAsByteArray();
GZIPInputStream stream = new GZIPInputStream(new ByteArrayInputStream(bytes));
@ -111,7 +111,7 @@ public class HeapdumpMvcEndpointTests {
@Test
public void invokeOptionsShouldReturnSize() throws Exception {
this.mvc.perform(options("/heapdump")).andExpect(status().isOk());
this.mvc.perform(options("/application/heapdump")).andExpect(status().isOk());
}
@Import({ JacksonAutoConfiguration.class, AuditAutoConfiguration.class,

@ -75,7 +75,7 @@ public class InfoMvcEndpointTests {
@Test
public void home() throws Exception {
this.mvc.perform(get("/info")).andExpect(status().isOk())
this.mvc.perform(get("/application/info")).andExpect(status().isOk())
.andExpect(content().string(containsString(
"\"beanName1\":{\"key11\":\"value11\",\"key12\":\"value12\"}")))
.andExpect(content().string(containsString(
@ -84,7 +84,7 @@ public class InfoMvcEndpointTests {
@Test
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/info")).andExpect(status().isOk())
this.mvc.perform(get("/application/info")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
}
@ -92,7 +92,7 @@ public class InfoMvcEndpointTests {
@Test
public void contentTypeCanBeApplicationJson() throws Exception {
this.mvc.perform(
get("/info").header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE))
get("/application/info").header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE))
.andExpect(status().isOk()).andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));
}

@ -65,7 +65,7 @@ public class InfoMvcEndpointWithNoInfoContributorsTests {
@Test
public void home() throws Exception {
this.mvc.perform(get("/info")).andExpect(status().isOk());
this.mvc.perform(get("/application/info")).andExpect(status().isOk());
}
@Import({ JacksonAutoConfiguration.class, AuditAutoConfiguration.class,

@ -79,20 +79,20 @@ public class JolokiaMvcEndpointIntegrationTests {
@Test
public void search() throws Exception {
this.mvc.perform(get("/jolokia/search/java.lang:*")).andExpect(status().isOk())
this.mvc.perform(get("/application/jolokia/search/java.lang:*")).andExpect(status().isOk())
.andExpect(content().string(containsString("GarbageCollector")));
}
@Test
public void read() throws Exception {
this.mvc.perform(get("/jolokia/read/java.lang:type=Memory"))
this.mvc.perform(get("/application/jolokia/read/java.lang:type=Memory"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("NonHeapMemoryUsage")));
}
@Test
public void list() throws Exception {
this.mvc.perform(get("/jolokia/list/java.lang/type=Memory/attr"))
this.mvc.perform(get("/application/jolokia/list/java.lang/type=Memory/attr"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("NonHeapMemoryUsage")));
}

@ -99,21 +99,21 @@ public class LoggersMvcEndpointTests {
.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
String expected = "{\"levels\":[\"OFF\",\"FATAL\",\"ERROR\",\"WARN\",\"INFO\",\"DEBUG\",\"TRACE\"],"
+ "\"loggers\":{\"ROOT\":{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}}}";
this.mvc.perform(get("/loggers")).andExpect(status().isOk())
this.mvc.perform(get("/application/loggers")).andExpect(status().isOk())
.andExpect(content().json(expected));
}
@Test
public void getLoggersWhenDisabledShouldReturnNotFound() throws Exception {
this.context.getBean(LoggersEndpoint.class).setEnabled(false);
this.mvc.perform(get("/loggers")).andExpect(status().isNotFound());
this.mvc.perform(get("/application/loggers")).andExpect(status().isNotFound());
}
@Test
public void getLoggerShouldReturnLogLevels() throws Exception {
given(this.loggingSystem.getLoggerConfiguration("ROOT"))
.willReturn(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG));
this.mvc.perform(get("/loggers/ROOT")).andExpect(status().isOk())
this.mvc.perform(get("/application/loggers/ROOT")).andExpect(status().isOk())
.andExpect(content().string(equalTo(
"{\"configuredLevel\":null," + "\"effectiveLevel\":\"DEBUG\"}")));
}
@ -121,25 +121,25 @@ public class LoggersMvcEndpointTests {
@Test
public void getLoggersRootWhenDisabledShouldReturnNotFound() throws Exception {
this.context.getBean(LoggersEndpoint.class).setEnabled(false);
this.mvc.perform(get("/loggers/ROOT")).andExpect(status().isNotFound());
this.mvc.perform(get("/application/loggers/ROOT")).andExpect(status().isNotFound());
}
@Test
public void getLoggersWhenLoggerNotFoundShouldReturnNotFound() throws Exception {
this.mvc.perform(get("/loggers/com.does.not.exist"))
this.mvc.perform(get("/application/loggers/com.does.not.exist"))
.andExpect(status().isNotFound());
}
@Test
public void contentTypeForGetDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/loggers")).andExpect(status().isOk())
this.mvc.perform(get("/application/loggers")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
}
@Test
public void contentTypeForGetCanBeApplicationJson() throws Exception {
this.mvc.perform(get("/loggers").header(HttpHeaders.ACCEPT,
this.mvc.perform(get("/application/loggers").header(HttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));
@ -147,14 +147,14 @@ public class LoggersMvcEndpointTests {
@Test
public void setLoggerUsingApplicationJsonShouldSetLogLevel() throws Exception {
this.mvc.perform(post("/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
this.mvc.perform(post("/application/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
}
@Test
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
this.mvc.perform(post("/loggers/ROOT")
this.mvc.perform(post("/application/loggers/ROOT")
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
@ -163,7 +163,7 @@ public class LoggersMvcEndpointTests {
@Test
public void setLoggerWhenDisabledShouldReturnNotFound() throws Exception {
this.context.getBean(LoggersEndpoint.class).setEnabled(false);
this.mvc.perform(post("/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
this.mvc.perform(post("/application/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
.content("{\"configuredLevel\":\"DEBUG\"}"))
.andExpect(status().isNotFound());
verifyZeroInteractions(this.loggingSystem);
@ -171,7 +171,7 @@ public class LoggersMvcEndpointTests {
@Test
public void setLoggerWithWrongLogLevel() throws Exception {
this.mvc.perform(post("/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
this.mvc.perform(post("/application/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
.content("{\"configuredLevel\":\"other\"}"))
.andExpect(status().is4xxClientError());
verifyZeroInteractions(this.loggingSystem);

@ -78,20 +78,20 @@ public class MetricsMvcEndpointTests {
@Test
public void home() throws Exception {
this.mvc.perform(get("/metrics")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics")).andExpect(status().isOk())
.andExpect(content().string(containsString("\"foo\":1")));
}
@Test
public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/metrics")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
}
@Test
public void homeContentTypeCanBeApplicationJson() throws Exception {
this.mvc.perform(get("/metrics").header(HttpHeaders.ACCEPT,
this.mvc.perform(get("/application/metrics").header(HttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));
@ -99,14 +99,14 @@ public class MetricsMvcEndpointTests {
@Test
public void specificMetricContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/metrics/foo")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics/foo")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
}
@Test
public void specificMetricContentTypeCanBeApplicationJson() throws Exception {
this.mvc.perform(get("/metrics/foo").header(HttpHeaders.ACCEPT,
this.mvc.perform(get("/application/metrics/foo").header(HttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));
@ -115,50 +115,50 @@ public class MetricsMvcEndpointTests {
@Test
public void homeWhenDisabled() throws Exception {
this.context.getBean(MetricsEndpoint.class).setEnabled(false);
this.mvc.perform(get("/metrics")).andExpect(status().isNotFound());
this.mvc.perform(get("/application/metrics")).andExpect(status().isNotFound());
}
@Test
public void specificMetric() throws Exception {
this.mvc.perform(get("/metrics/foo")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics/foo")).andExpect(status().isOk())
.andExpect(content().string(equalTo("{\"foo\":1}")));
}
@Test
public void specificMetricWhenDisabled() throws Exception {
this.context.getBean(MetricsEndpoint.class).setEnabled(false);
this.mvc.perform(get("/metrics/foo")).andExpect(status().isNotFound());
this.mvc.perform(get("/application/metrics/foo")).andExpect(status().isNotFound());
}
@Test
public void specificMetricThatDoesNotExist() throws Exception {
this.mvc.perform(get("/metrics/bar")).andExpect(status().isNotFound());
this.mvc.perform(get("/application/metrics/bar")).andExpect(status().isNotFound());
}
@Test
public void regexAll() throws Exception {
String expected = "\"foo\":1,\"group1.a\":1,\"group1.b\":1,\"group2.a\":1,\"group2_a\":1";
this.mvc.perform(get("/metrics/.*")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics/.*")).andExpect(status().isOk())
.andExpect(content().string(containsString(expected)));
}
@Test
public void regexGroupDot() throws Exception {
String expected = "\"group1.a\":1,\"group1.b\":1,\"group2.a\":1";
this.mvc.perform(get("/metrics/group[0-9]+\\..*")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics/group[0-9]+\\..*")).andExpect(status().isOk())
.andExpect(content().string(containsString(expected)));
}
@Test
public void regexGroup1() throws Exception {
String expected = "\"group1.a\":1,\"group1.b\":1";
this.mvc.perform(get("/metrics/group1\\..*")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics/group1\\..*")).andExpect(status().isOk())
.andExpect(content().string(containsString(expected)));
}
@Test
public void specificMetricWithDot() throws Exception {
this.mvc.perform(get("/metrics/group2.a")).andExpect(status().isOk())
this.mvc.perform(get("/application/metrics/group2.a")).andExpect(status().isOk())
.andExpect(content().string(containsString("1")));
}

@ -62,7 +62,7 @@ public class MvcEndpointCorsIntegrationTests {
@Test
public void corsIsDisabledByDefault() throws Exception {
createMockMvc()
.perform(options("/beans").header("Origin", "foo.example.com")
.perform(options("/application/beans").header("Origin", "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"))
.andExpect(
header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
@ -73,7 +73,7 @@ public class MvcEndpointCorsIntegrationTests {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
createMockMvc()
.perform(options("/beans").header("Origin", "bar.example.com")
.perform(options("/application/beans").header("Origin", "bar.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"))
.andExpect(status().isForbidden());
performAcceptedCorsRequest();
@ -101,7 +101,7 @@ public class MvcEndpointCorsIntegrationTests {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
createMockMvc()
.perform(options("/beans").header("Origin", "foo.example.com")
.perform(options("/application/beans").header("Origin", "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Alpha"))
.andExpect(status().isForbidden());
@ -113,7 +113,7 @@ public class MvcEndpointCorsIntegrationTests {
"endpoints.cors.allowed-origins:foo.example.com",
"endpoints.cors.allowed-headers:Alpha,Bravo");
createMockMvc()
.perform(options("/beans").header("Origin", "foo.example.com")
.perform(options("/application/beans").header("Origin", "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "Alpha"))
.andExpect(status().isOk()).andExpect(header()
@ -125,7 +125,7 @@ public class MvcEndpointCorsIntegrationTests {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
createMockMvc()
.perform(options("/health").header(HttpHeaders.ORIGIN, "foo.example.com")
.perform(options("/application/health").header(HttpHeaders.ORIGIN, "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "PATCH"))
.andExpect(status().isForbidden());
}
@ -136,7 +136,7 @@ public class MvcEndpointCorsIntegrationTests {
"endpoints.cors.allowed-origins:foo.example.com",
"endpoints.cors.allowed-methods:GET,HEAD");
createMockMvc()
.perform(options("/health").header(HttpHeaders.ORIGIN, "foo.example.com")
.perform(options("/application/health").header(HttpHeaders.ORIGIN, "foo.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "HEAD"))
.andExpect(status().isOk()).andExpect(header()
.string(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,HEAD"));
@ -165,10 +165,10 @@ public class MvcEndpointCorsIntegrationTests {
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.cors.allowed-origins:foo.example.com");
createMockMvc()
.perform(options("/jolokia").header("Origin", "bar.example.com")
.perform(options("/application/jolokia").header("Origin", "bar.example.com")
.header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"))
.andExpect(status().isForbidden());
performAcceptedCorsRequest("/jolokia");
performAcceptedCorsRequest("/application/jolokia");
}
private MockMvc createMockMvc() {
@ -177,7 +177,7 @@ public class MvcEndpointCorsIntegrationTests {
}
private ResultActions performAcceptedCorsRequest() throws Exception {
return performAcceptedCorsRequest("/beans");
return performAcceptedCorsRequest("/application/beans");
}
private ResultActions performAcceptedCorsRequest(String url) throws Exception {

@ -72,7 +72,7 @@ public class MvcEndpointIntegrationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/mappings")).andExpect(content().string(startsWith("{\"")));
mockMvc.perform(get("/application/mappings")).andExpect(content().string(startsWith("{\"")));
}
@Test
@ -97,7 +97,7 @@ public class MvcEndpointIntegrationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(DefaultConfiguration.class);
MockMvc mockMvc = createMockMvc();
mockMvc.perform(get("/beans.cmd")).andExpect(status().isNotFound());
mockMvc.perform(get("/application/beans.cmd")).andExpect(status().isNotFound());
}
@Test
@ -107,7 +107,7 @@ public class MvcEndpointIntegrationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/beans.json")).andExpect(status().isOk());
mockMvc.perform(get("/application/beans.json")).andExpect(status().isOk());
}
@Test
@ -115,8 +115,8 @@ public class MvcEndpointIntegrationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/info")).andExpect(status().isOk());
mockMvc.perform(get("/actuator")).andExpect(status().isOk());
mockMvc.perform(get("/application/info")).andExpect(status().isOk());
mockMvc.perform(get("/application")).andExpect(status().isOk());
}
@Test
@ -136,7 +136,7 @@ public class MvcEndpointIntegrationTests {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(SecureConfiguration.class);
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/beans")).andExpect(status().isUnauthorized());
mockMvc.perform(get("/application/beans")).andExpect(status().isUnauthorized());
}
@Test
@ -194,7 +194,7 @@ public class MvcEndpointIntegrationTests {
EnvironmentTestUtils.addEnvironment(this.context,
"management.security.enabled:false");
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/beans")).andExpect(status().isOk());
mockMvc.perform(get("/application/beans")).andExpect(status().isOk());
}
private void assertIndentedJsonResponse(Class<?> configuration) throws Exception {
@ -205,7 +205,7 @@ public class MvcEndpointIntegrationTests {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.serialization.indent-output:true");
MockMvc mockMvc = createSecureMockMvc();
mockMvc.perform(get("/mappings"))
mockMvc.perform(get("/application/mappings"))
.andExpect(content().string(startsWith("{" + LINE_SEPARATOR)));
}

@ -74,7 +74,7 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
this.context.register(TestConfiguration.class);
this.context.refresh();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(get("/health").with(getRequestPostProcessor()))
mockMvc.perform(get("/application/health").with(getRequestPostProcessor()))
.andExpect(status().isOk())
.andExpect(content().string("{\"status\":\"UP\"}"));
}
@ -88,7 +88,7 @@ public class NoSpringSecurityHealthMvcEndpointIntegrationTests {
"management.security.enabled:false");
this.context.refresh();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(get("/health")).andExpect(status().isOk())
mockMvc.perform(get("/application/health")).andExpect(status().isOk())
.andExpect(content().string(containsString(
"\"status\":\"UP\",\"test\":{\"status\":\"UP\",\"hello\":\"world\"}")));
}

@ -75,7 +75,7 @@ public class ShutdownMvcEndpointTests {
@Test
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(post("/shutdown")).andExpect(status().isOk())
this.mvc.perform(post("/application/shutdown")).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
assertThat(this.context.getBean(CountDownLatch.class).await(30, TimeUnit.SECONDS))
@ -84,7 +84,7 @@ public class ShutdownMvcEndpointTests {
@Test
public void contentTypeCanBeApplicationJson() throws Exception {
this.mvc.perform(post("/shutdown").header(HttpHeaders.ACCEPT,
this.mvc.perform(post("/application/shutdown").header(HttpHeaders.ACCEPT,
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
.andExpect(header().string("Content-Type",
MediaType.APPLICATION_JSON_UTF8_VALUE));

@ -63,7 +63,7 @@ public class SampleActuatorLog4J2ApplicationTests {
@Test
public void validateLoggersEndpoint() throws Exception {
this.mvc.perform(get("/loggers/org.apache.coyote.http11.Http11NioProtocol"))
this.mvc.perform(get("/application/loggers/org.apache.coyote.http11.Http11NioProtocol"))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("{\"configuredLevel\":\"WARN\","
+ "\"effectiveLevel\":\"WARN\"}")));

@ -61,14 +61,14 @@ public class SampleActuatorUiApplicationPortTests {
public void testMetrics() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/metrics", Map.class);
"http://localhost:" + this.managementPort + "/application//metrics", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/health", String.class);
"http://localhost:" + this.managementPort + "/application//health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}");
}

@ -71,7 +71,7 @@ public class SampleActuatorUiApplicationTests {
@Test
public void testMetrics() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics",
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/application/metrics",
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

@ -69,7 +69,7 @@ public class InsecureManagementSampleActuatorApplicationTests {
// ignore;
}
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/metrics",
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/application/metrics",
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")

@ -71,14 +71,14 @@ public class ManagementPortSampleActuatorApplicationTests {
testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/metrics", Map.class);
"http://localhost:" + this.managementPort + "/application/metrics", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/health", String.class);
"http://localhost:" + this.managementPort + "/application/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}

@ -46,7 +46,7 @@ public class NonSensitiveHealthTests {
@Test
public void testSecureHealth() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/health",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/health",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).doesNotContain("\"hello\":1");

@ -98,7 +98,7 @@ public class SampleActuatorApplicationTests {
testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate
.withBasicAuth("user", getPassword()).getForEntity("/metrics", Map.class);
.withBasicAuth("user", getPassword()).getForEntity("/application/metrics", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@ -109,7 +109,7 @@ public class SampleActuatorApplicationTests {
public void testEnv() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate
.withBasicAuth("user", getPassword()).getForEntity("/env", Map.class);
.withBasicAuth("user", getPassword()).getForEntity("/application/env", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();
@ -118,7 +118,7 @@ public class SampleActuatorApplicationTests {
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/health",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/health",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
@ -129,14 +129,14 @@ public class SampleActuatorApplicationTests {
public void testSecureHealth() throws Exception {
ResponseEntity<String> entity = this.restTemplate
.withBasicAuth("user", getPassword())
.getForEntity("/health", String.class);
.getForEntity("/application/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"hello\":1");
}
@Test
public void testInfo() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/info",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/info",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody())
@ -176,7 +176,7 @@ public class SampleActuatorApplicationTests {
this.restTemplate.getForEntity("/health", String.class);
@SuppressWarnings("rawtypes")
ResponseEntity<List> entity = this.restTemplate
.withBasicAuth("user", getPassword()).getForEntity("/trace", List.class);
.withBasicAuth("user", getPassword()).getForEntity("/application/trace", List.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
List<Map<String, Object>> list = entity.getBody();
@ -189,10 +189,10 @@ public class SampleActuatorApplicationTests {
@Test
public void traceWithParameterMap() throws Exception {
this.restTemplate.getForEntity("/health?param1=value1", String.class);
this.restTemplate.getForEntity("/application/health?param1=value1", String.class);
@SuppressWarnings("rawtypes")
ResponseEntity<List> entity = this.restTemplate
.withBasicAuth("user", getPassword()).getForEntity("/trace", List.class);
.withBasicAuth("user", getPassword()).getForEntity("/application/trace", List.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
List<Map<String, Object>> list = entity.getBody();
@ -219,7 +219,7 @@ public class SampleActuatorApplicationTests {
public void testBeans() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<List> entity = this.restTemplate
.withBasicAuth("user", getPassword()).getForEntity("/beans", List.class);
.withBasicAuth("user", getPassword()).getForEntity("/application/beans", List.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).hasSize(1);
Map<String, Object> body = (Map<String, Object>) entity.getBody().get(0);
@ -231,7 +231,7 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate
.withBasicAuth("user", getPassword())
.getForEntity("/configprops", Map.class);
.getForEntity("/application/configprops", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();

@ -62,7 +62,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
@Test
public void testMetricsIsSecure() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/metrics",
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring//application/metrics",
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

@ -60,7 +60,7 @@ public class ServletPathSampleActuatorApplicationTests {
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/spring/health",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/spring//application/health",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");

@ -65,7 +65,7 @@ public class ShutdownSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate
.withBasicAuth("user", getPassword())
.postForEntity("/shutdown", null, Map.class);
.postForEntity("/application/shutdown", null, Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();

@ -50,22 +50,22 @@ public class SampleHypermediaGsonApplicationTests {
@Test
public void health() throws Exception {
this.mockMvc.perform(get("/health").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application/health").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.links[0].href").value("http://localhost/health"))
.andExpect(jsonPath("$.links[0].href").value("http://localhost/application/health"))
.andExpect(jsonPath("$.content.status").exists());
}
@Test
public void trace() throws Exception {
this.mockMvc.perform(get("/trace").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application/trace").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(jsonPath("$.links").doesNotExist())
.andExpect(jsonPath("$").isArray());
}
@Test
public void envValue() throws Exception {
this.mockMvc.perform(get("/env/user.home").accept(MediaType.APPLICATION_JSON))
this.mockMvc.perform(get("/application/env/user.home").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$._links").doesNotExist());
}

@ -38,16 +38,16 @@ public class SampleHypermediaUiSecureApplicationTests {
@Test
public void links() {
String response = this.restTemplate.getForObject("/actuator", String.class);
String response = this.restTemplate.getForObject("/application", String.class);
assertThat(response).contains("\"_links\":");
}
@Test
public void testInsecureNestedPath() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/env",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/env",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
ResponseEntity<String> user = this.restTemplate.getForEntity("/env/foo",
ResponseEntity<String> user = this.restTemplate.getForEntity("/application/env/foo",
String.class);
assertThat(user.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(user.getBody()).contains("{\"foo\":");
@ -55,7 +55,7 @@ public class SampleHypermediaUiSecureApplicationTests {
@Test
public void testSecurePath() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/metrics",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/metrics",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

@ -50,7 +50,7 @@ public class SampleHypermediaUiApplicationTests {
@Test
public void links() {
String response = this.restTemplate.getForObject("/actuator", String.class);
String response = this.restTemplate.getForObject("/application", String.class);
assertThat(response).contains("\"_links\":");
}
@ -58,7 +58,7 @@ public class SampleHypermediaUiApplicationTests {
public void linksWithJson() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> response = this.restTemplate.exchange("/actuator",
ResponseEntity<String> response = this.restTemplate.exchange("/application",
HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
assertThat(response.getBody()).contains("\"_links\":");
}

@ -51,7 +51,7 @@ public class SampleHypermediaApplicationHomePageTests {
public void linksWithJson() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<String> response = this.restTemplate.exchange("/actuator",
ResponseEntity<String> response = this.restTemplate.exchange("/application",
HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
assertThat(response.getBody()).contains("\"_links\":");
}
@ -60,7 +60,7 @@ public class SampleHypermediaApplicationHomePageTests {
public void halWithHtml() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> response = this.restTemplate.exchange("/actuator/",
ResponseEntity<String> response = this.restTemplate.exchange("/application/",
HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
assertThat(response.getBody()).contains("HAL Browser");
}

@ -70,19 +70,19 @@ public class SampleSecureOAuth2ActuatorApplicationTests {
@Test
public void healthAvailable() throws Exception {
this.mvc.perform(get("/health")).andExpect(status().isOk()).andDo(print());
this.mvc.perform(get("/application/health")).andExpect(status().isOk()).andDo(print());
}
@Test
public void envSecuredWithBasic() throws Exception {
this.mvc.perform(get("/env")).andExpect(status().isUnauthorized())
this.mvc.perform(get("/application/env")).andExpect(status().isUnauthorized())
.andExpect(header().string("WWW-Authenticate", containsString("Basic")))
.andDo(print());
}
@Test
public void envWithPassword() throws Exception {
this.mvc.perform(get("/env").header("Authorization",
this.mvc.perform(get("/application/env").header("Authorization",
"Basic " + Base64Utils.encodeToString("user:password".getBytes())))
.andExpect(status().isOk()).andDo(print());
}

@ -105,7 +105,7 @@ public class SampleMethodSecurityApplicationTests {
@Test
public void testManagementProtected() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/beans",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@ -116,7 +116,7 @@ public class SampleMethodSecurityApplicationTests {
"admin", "admin");
this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor);
try {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/beans",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@ -132,7 +132,7 @@ public class SampleMethodSecurityApplicationTests {
"user", "user");
this.restTemplate.getRestTemplate().getInterceptors().add(basicAuthInterceptor);
try {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/beans",
ResponseEntity<String> entity = this.restTemplate.getForEntity("/application/beans",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}

Loading…
Cancel
Save