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

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

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

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

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

@ -22,6 +22,7 @@ import org.springframework.http.MediaType;
* {@link MediaType MediaTypes} that can be consumed and produced by Actuator endpoints.
*
* @author Andy Wilkinson
* @author Madhura Bhave
* @since 1.5.0
*/
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";
/**
* {@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.
*/
public static final MediaType APPLICATION_ACTUATOR_V1_JSON = MediaType
.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() {
}

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

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

@ -73,10 +73,10 @@ public class AuditEventsMvcEndpointTests {
}
@Test
public void contentTypeDefaultsToActuatorV1Json() throws Exception {
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/auditevents")).andExpect(status().isOk())
.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

@ -79,10 +79,10 @@ public class EnvironmentMvcEndpointTests {
}
@Test
public void homeContentTypeDefaultsToActuatorV1Json() throws Exception {
public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/env")).andExpect(status().isOk())
.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
@ -94,10 +94,10 @@ public class EnvironmentMvcEndpointTests {
}
@Test
public void subContentTypeDefaultsToActuatorV1Json() throws Exception {
public void subContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/env/foo")).andExpect(status().isOk())
.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

@ -83,10 +83,10 @@ public class InfoMvcEndpointTests {
}
@Test
public void contentTypeDefaultsToActuatorV1Json() throws Exception {
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/info")).andExpect(status().isOk())
.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

@ -130,10 +130,10 @@ public class LoggersMvcEndpointTests {
}
@Test
public void contentTypeForGetDefaultsToActuatorV1Json() throws Exception {
public void contentTypeForGetDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/loggers")).andExpect(status().isOk())
.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
@ -152,9 +152,9 @@ public class LoggersMvcEndpointTests {
}
@Test
public void setLoggerUsingActuatorV1JsonShouldSetLogLevel() throws Exception {
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
this.mvc.perform(post("/loggers/ROOT")
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V1_JSON)
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
}

@ -83,10 +83,10 @@ public class MetricsMvcEndpointTests {
}
@Test
public void homeContentTypeDefaultsToActuatorV1Json() throws Exception {
public void homeContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/metrics")).andExpect(status().isOk())
.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
@ -98,10 +98,10 @@ public class MetricsMvcEndpointTests {
}
@Test
public void specificMetricContentTypeDefaultsToActuatorV1Json() throws Exception {
public void specificMetricContentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(get("/metrics/foo")).andExpect(status().isOk())
.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

@ -74,10 +74,10 @@ public class ShutdownMvcEndpointTests {
}
@Test
public void contentTypeDefaultsToActuatorV1Json() throws Exception {
public void contentTypeDefaultsToActuatorV2Json() throws Exception {
this.mvc.perform(post("/shutdown")).andExpect(status().isOk())
.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))
.isTrue();
}

Loading…
Cancel
Save