Merge branch '1.4.x' into 1.5.x

This commit is contained in:
Stephane Nicoll
2016-10-30 10:59:02 +01:00
6 changed files with 36 additions and 10 deletions

View File

@@ -44,6 +44,11 @@
<artifactId>h2</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -81,6 +86,12 @@
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>

View File

@@ -57,13 +57,15 @@ HAL browser is not active).
== Hypermedia Support
If https://projects.spring.io/spring-hateoas[Spring HATEOAS] is enabled (i.e. if it is
on the classpath by default) then the Actuator endpoint responses are enhanced with
hypermedia in the form of "links". The default media type for responses is
http://stateless.co/hal_specification.html[HAL], resulting in each resource having an
extra property called "_links". You can change the media type to another one supported by
Spring HATEOAS by providing your own `@EnableHypermedia` annotation and custom providers
as necessary.
If `endpoints.hypermedia.enabled` is set to `true` and
https://projects.spring.io/spring-hateoas[Spring HATEOAS] is on the classpath (e.g.
through the `spring-boot-starter-hateoas` or if you are using
http://projects.spring.io/spring-data-rest[Spring Data REST]) then the Actuator endpoint
responses are enhanced with hypermedia in the form of "links". The default media type for
responses is http://stateless.co/hal_specification.html[HAL], resulting in each resource
having an extra property called "_links". You can change the media type to another one
supported by Spring HATEOAS by providing your own `@EnableHypermedia` annotation and
custom providers as necessary.
Example enhanced "/metrics" endpoint with additional "_links":

View File

@@ -33,12 +33,14 @@ import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = SpringBootHypermediaApplication.class, loader = SpringBootContextLoader.class)
@WebAppConfiguration
@TestPropertySource(properties = "spring.jackson.serialization.indent_output=true")
@TestPropertySource(properties = { "spring.jackson.serialization.indent_output=true",
"endpoints.hypermedia.enabled=true" })
@DirtiesContext
@AutoConfigureMockMvc
@AutoConfigureRestDocs("target/generated-snippets")
@@ -56,7 +58,10 @@ public class HypermediaEndpointDocumentation {
@Test
public void metrics() throws Exception {
this.mockMvc.perform(get("/metrics").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andDo(document("metrics/hypermedia"));
.andExpect(status().isOk())
.andExpect(jsonPath("$._links.self.href")
.value("http://localhost:8080/metrics"))
.andDo(document("metrics/hypermedia"));
}
@Test