Add v2 content type to actuator endpoints

Closes gh-7968
pull/6728/merge
Madhura Bhave 8 years ago
parent 28a4d5e01b
commit 8bfd42e3f1

@ -124,7 +124,7 @@ public class EndpointDocumentation {
public void setLogger() throws Exception { public void setLogger() throws Exception {
this.mockMvc this.mockMvc
.perform(post("/loggers/org.springframework.boot") .perform(post("/loggers/org.springframework.boot")
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON) .contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
.content("{\"configuredLevel\": \"DEBUG\"}")) .content("{\"configuredLevel\": \"DEBUG\"}"))
.andExpect(status().isOk()).andDo(document("set-logger")); .andExpect(status().isOk()).andDo(document("set-logger"));
} }
@ -133,7 +133,7 @@ public class EndpointDocumentation {
public void auditEvents() throws Exception { public void auditEvents() throws Exception {
this.mockMvc this.mockMvc
.perform(get("/auditevents").param("after", "2016-11-01T10:00:00+0000") .perform(get("/auditevents").param("after", "2016-11-01T10:00:00+0000")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON)) .accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()).andDo(document("auditevents")); .andExpect(status().isOk()).andDo(document("auditevents"));
} }
@ -142,7 +142,7 @@ public class EndpointDocumentation {
this.mockMvc this.mockMvc
.perform(get("/auditevents").param("principal", "admin") .perform(get("/auditevents").param("principal", "admin")
.param("after", "2016-11-01T10:00:00+0000") .param("after", "2016-11-01T10:00:00+0000")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON)) .accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andDo(document("auditevents/filter-by-principal")); .andDo(document("auditevents/filter-by-principal"));
} }
@ -153,7 +153,7 @@ public class EndpointDocumentation {
.perform(get("/auditevents").param("principal", "admin") .perform(get("/auditevents").param("principal", "admin")
.param("after", "2016-11-01T10:00:00+0000") .param("after", "2016-11-01T10:00:00+0000")
.param("type", "AUTHENTICATION_SUCCESS") .param("type", "AUTHENTICATION_SUCCESS")
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON)) .accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andDo(document("auditevents/filter-by-principal-and-type")); .andDo(document("auditevents/filter-by-principal-and-type"));
} }
@ -172,7 +172,7 @@ public class EndpointDocumentation {
output = output.length() > 0 ? output : "./"; output = output.length() > 0 ? output : "./";
this.mockMvc this.mockMvc
.perform(get(endpointPath) .perform(get(endpointPath)
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON)) .accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON))
.andExpect(status().isOk()).andDo(document(output)) .andExpect(status().isOk()).andDo(document(output))
.andDo(new ResultHandler() { .andDo(new ResultHandler() {

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

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

@ -250,7 +250,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
if (messageConverter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) { if (messageConverter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
List<MediaType> supportedMediaTypes = new ArrayList<>( List<MediaType> supportedMediaTypes = new ArrayList<>(
messageConverter.getSupportedMediaTypes()); messageConverter.getSupportedMediaTypes());
supportedMediaTypes.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON); supportedMediaTypes.add(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON);
((AbstractHttpMessageConverter<?>) messageConverter) ((AbstractHttpMessageConverter<?>) messageConverter)
.setSupportedMediaTypes(supportedMediaTypes); .setSupportedMediaTypes(supportedMediaTypes);
} }

@ -38,7 +38,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@RequestMapping(method = RequestMethod.GET, produces = { @RequestMapping(method = RequestMethod.GET, produces = {
ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
@interface ActuatorGetMapping { @interface ActuatorGetMapping {

@ -22,6 +22,7 @@ import org.springframework.http.MediaType;
* {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints. * {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Madhura Bhave
* @since 1.5.0 * @since 1.5.0
*/ */
public final class ActuatorMediaTypes { public final class ActuatorMediaTypes {
@ -31,12 +32,23 @@ public final class ActuatorMediaTypes {
*/ */
public static final String APPLICATION_ACTUATOR_V1_JSON_VALUE = "application/vnd.spring-boot.actuator.v1+json"; public static final String APPLICATION_ACTUATOR_V1_JSON_VALUE = "application/vnd.spring-boot.actuator.v1+json";
/**
* {@link String} equivalent of {@link #APPLICATION_ACTUATOR_V2_JSON}.
*/
public static final String APPLICATION_ACTUATOR_V2_JSON_VALUE = "application/vnd.spring-boot.actuator.v2+json";
/** /**
* The {@code application/vnd.spring-boot.actuator.v1+json} media type. * The {@code application/vnd.spring-boot.actuator.v1+json} media type.
*/ */
public static final MediaType APPLICATION_ACTUATOR_V1_JSON = MediaType public static final MediaType APPLICATION_ACTUATOR_V1_JSON = MediaType
.valueOf(APPLICATION_ACTUATOR_V1_JSON_VALUE); .valueOf(APPLICATION_ACTUATOR_V1_JSON_VALUE);
/**
* The {@code application/vnd.spring-boot.actuator.v2+json} media type.
*/
public static final MediaType APPLICATION_ACTUATOR_V2_JSON = MediaType
.valueOf(APPLICATION_ACTUATOR_V2_JSON_VALUE);
private ActuatorMediaTypes() { private ActuatorMediaTypes() {
} }

@ -40,9 +40,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@RequestMapping(method = RequestMethod.POST, consumes = { @RequestMapping(method = RequestMethod.POST, consumes = {
ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE }, produces = {
ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
@interface ActuatorPostMapping { @interface ActuatorPostMapping {

@ -38,7 +38,7 @@ public class ShutdownMvcEndpoint extends EndpointMvcAdapter {
super(delegate); super(delegate);
} }
@PostMapping(produces = { ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON_VALUE, @PostMapping(produces = { ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }) MediaType.APPLICATION_JSON_VALUE })
@ResponseBody @ResponseBody
@Override @Override

@ -73,10 +73,10 @@ public class AuditEventsMvcEndpointTests {
} }
@Test @Test
public void contentTypeDefaultsToActuatorV1Json() throws Exception { public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/auditevents")).andExpect(status().isOk()) this.mvc.perform(get("/auditevents")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
} }
@Test @Test

@ -79,10 +79,10 @@ public class EnvironmentMvcEndpointTests {
} }
@Test @Test
public void homeContentTypeDefaultsToActuatorV1Json() throws Exception { public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/env")).andExpect(status().isOk()) this.mvc.perform(get("/env")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
} }
@Test @Test
@ -94,10 +94,10 @@ public class EnvironmentMvcEndpointTests {
} }
@Test @Test
public void subContentTypeDefaultsToActuatorV1Json() throws Exception { public void subContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/env/foo")).andExpect(status().isOk()) this.mvc.perform(get("/env/foo")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
} }
@Test @Test

@ -83,10 +83,10 @@ public class InfoMvcEndpointTests {
} }
@Test @Test
public void contentTypeDefaultsToActuatorV1Json() throws Exception { public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/info")).andExpect(status().isOk()) this.mvc.perform(get("/info")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
} }
@Test @Test

@ -130,10 +130,10 @@ public class LoggersMvcEndpointTests {
} }
@Test @Test
public void contentTypeForGetDefaultsToActuatorV1Json() throws Exception { public void contentTypeForGetDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/loggers")).andExpect(status().isOk()) this.mvc.perform(get("/loggers")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
} }
@Test @Test
@ -152,9 +152,9 @@ public class LoggersMvcEndpointTests {
} }
@Test @Test
public void setLoggerUsingActuatorV1JsonShouldSetLogLevel() throws Exception { public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
this.mvc.perform(post("/loggers/ROOT") this.mvc.perform(post("/loggers/ROOT")
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON) .contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk()); .content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
} }

@ -83,10 +83,10 @@ public class MetricsMvcEndpointTests {
} }
@Test @Test
public void homeContentTypeDefaultsToActuatorV1Json() throws Exception { public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/metrics")).andExpect(status().isOk()) this.mvc.perform(get("/metrics")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
} }
@Test @Test
@ -98,10 +98,10 @@ public class MetricsMvcEndpointTests {
} }
@Test @Test
public void specificMetricContentTypeDefaultsToActuatorV1Json() throws Exception { public void specificMetricContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/metrics/foo")).andExpect(status().isOk()) this.mvc.perform(get("/metrics/foo")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
} }
@Test @Test

@ -74,10 +74,10 @@ public class ShutdownMvcEndpointTests {
} }
@Test @Test
public void contentTypeDefaultsToActuatorV1Json() throws Exception { public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(post("/shutdown")).andExpect(status().isOk()) this.mvc.perform(post("/shutdown")).andExpect(status().isOk())
.andExpect(header().string("Content-Type", .andExpect(header().string("Content-Type",
"application/vnd.spring-boot.actuator.v1+json;charset=UTF-8")); "application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
assertThat(this.context.getBean(CountDownLatch.class).await(30, TimeUnit.SECONDS)) assertThat(this.context.getBean(CountDownLatch.class).await(30, TimeUnit.SECONDS))
.isTrue(); .isTrue();
} }

Loading…
Cancel
Save