Polish Actuator hypermedia support
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.hypermedia.test;
|
||||
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.RestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import groovy.text.Template;
|
||||
import groovy.text.TemplateEngine;
|
||||
|
||||
@@ -40,6 +52,11 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.RestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SpringBootHypermediaApplication.class)
|
||||
@WebAppConfiguration
|
||||
@@ -82,8 +99,7 @@ public class EndpointDocumentation {
|
||||
@Test
|
||||
public void logfile() throws Exception {
|
||||
this.mockMvc.perform(get("/logfile").accept(MediaType.TEXT_PLAIN))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("logfile"));
|
||||
.andExpect(status().isOk()).andDo(document("logfile"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,10 +114,10 @@ public class EndpointDocumentation {
|
||||
final String endpointPath = StringUtils.hasText(endpoint.getPath()) ? endpoint
|
||||
.getPath() : "/";
|
||||
|
||||
if (!endpointPath.equals("/docs") && !endpointPath.equals("/logfile")) {
|
||||
String output = endpointPath.substring(1);
|
||||
output = output.length() > 0 ? output : "./";
|
||||
this.mockMvc
|
||||
if (!endpointPath.equals("/docs") && !endpointPath.equals("/logfile")) {
|
||||
String output = endpointPath.substring(1);
|
||||
output = output.length() > 0 ? output : "./";
|
||||
this.mockMvc
|
||||
.perform(get(endpointPath).accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andDo(document(output))
|
||||
.andDo(new ResultHandler() {
|
||||
@@ -111,7 +127,7 @@ public class EndpointDocumentation {
|
||||
endpoints.add(endpoint);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
File file = new File(this.restdocsOutputDir + "/endpoints.adoc");
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.hypermedia.test;
|
||||
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.RestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import groovy.text.TemplateEngine;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -22,11 +34,16 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.RestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SpringBootHypermediaApplication.class)
|
||||
@WebAppConfiguration
|
||||
@TestPropertySource(properties = { "spring.jackson.serialization.indent_output=true",
|
||||
"endpoints.health.sensitive=false" })
|
||||
"endpoints.health.sensitive=false" })
|
||||
@DirtiesContext
|
||||
public class HealthEndpointDocumentation {
|
||||
|
||||
@@ -49,15 +66,13 @@ public class HealthEndpointDocumentation {
|
||||
System.setProperty("org.springframework.restdocs.outputDir",
|
||||
this.restdocsOutputDir);
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration())
|
||||
.build();
|
||||
.apply(documentationConfiguration()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void health() throws Exception {
|
||||
this.mockMvc.perform(get("/health").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("health/unsensitive"));
|
||||
.andExpect(status().isOk()).andDo(document("health/unsensitive"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.hypermedia.test;
|
||||
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.RestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import groovy.text.TemplateEngine;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -22,6 +34,11 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.restdocs.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.RestDocumentation.documentationConfiguration;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SpringBootHypermediaApplication.class)
|
||||
@WebAppConfiguration
|
||||
@@ -48,29 +65,25 @@ public class HypermediaEndpointDocumentation {
|
||||
System.setProperty("org.springframework.restdocs.outputDir",
|
||||
this.restdocsOutputDir);
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration())
|
||||
.build();
|
||||
.apply(documentationConfiguration()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beans() throws Exception {
|
||||
this.mockMvc.perform(get("/beans").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("beans/hypermedia"));
|
||||
.andExpect(status().isOk()).andDo(document("beans/hypermedia"));
|
||||
}
|
||||
|
||||
@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()).andDo(document("metrics/hypermedia"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void home() throws Exception {
|
||||
this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("admin"));
|
||||
.andExpect(status().isOk()).andDo(document("admin"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2015 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.hypermedia.test;
|
||||
|
||||
import groovy.text.GStringTemplateEngine;
|
||||
@@ -18,4 +34,5 @@ public class SpringBootHypermediaApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootHypermediaApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user