Polish 'Document the os info contribution'

See gh-45565
This commit is contained in:
Phillip Webb 2025-05-20 13:57:36 -07:00
parent 752135d068
commit 64aefcb658
1 changed files with 22 additions and 11 deletions

View File

@ -38,11 +38,10 @@ import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.restdocs.payload.ResponseFieldsSnippet; import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.restdocs.payload.PayloadDocumentation.beneathPath; import static org.springframework.restdocs.payload.PayloadDocumentation.beneathPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/** /**
* Tests for generating documentation describing the {@link InfoEndpoint}. * Tests for generating documentation describing the {@link InfoEndpoint}.
@ -52,10 +51,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
@Test @Test
void info() throws Exception { void info() {
this.mockMvc.perform(get("/actuator/info")) assertThat(this.mvc.get().uri("/actuator/info")).hasStatusOk()
.andExpect(status().isOk()) .apply(MockMvcRestDocumentation.document("info", gitInfo(), buildInfo(), osInfo(), processInfo()));
.andDo(MockMvcRestDocumentation.document("info", gitInfo(), buildInfo(), osInfo(), processInfo()));
} }
private ResponseFieldsSnippet gitInfo() { private ResponseFieldsSnippet gitInfo() {
@ -80,13 +78,13 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
} }
private ResponseFieldsSnippet osInfo() { private ResponseFieldsSnippet osInfo() {
return responseFields(beneathPath("os"), osInfoField("name", "Name"), osInfoField("version", "Version"), return responseFields(beneathPath("os"), osInfoField("name", "Name of the operating system"),
osInfoField("arch", "Architecture")); osInfoField("version", "Version of the operating system"),
osInfoField("arch", "Architecture of the operating system"));
} }
private FieldDescriptor osInfoField(String field, String desc) { private FieldDescriptor osInfoField(String field, String desc) {
return fieldWithPath(field) return fieldWithPath(field).description(desc + " (as obtained from the 'os." + field + "' system property).")
.description("Operating System " + desc + " (as obtained from the 'os." + field + "' system property).")
.type(JsonFieldType.STRING) .type(JsonFieldType.STRING)
.optional(); .optional();
} }
@ -97,7 +95,20 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
fieldWithPath("parentPid").description("Parent Process ID (or -1).").type(JsonFieldType.NUMBER), fieldWithPath("parentPid").description("Parent Process ID (or -1).").type(JsonFieldType.NUMBER),
fieldWithPath("owner").description("Process owner.").type(JsonFieldType.STRING), fieldWithPath("owner").description("Process owner.").type(JsonFieldType.STRING),
fieldWithPath("cpus").description("Number of CPUs available to the process.") fieldWithPath("cpus").description("Number of CPUs available to the process.")
.type(JsonFieldType.NUMBER)); .type(JsonFieldType.NUMBER),
fieldWithPath("memory").description("Memory information."),
fieldWithPath("memory.heap").description("Heap memory."),
fieldWithPath("memory.heap.init").description("The number of bytes initially requested by the JVM."),
fieldWithPath("memory.heap.used").description("The number of bytes currently being used."),
fieldWithPath("memory.heap.committed").description("The number of bytes committed for JVM use."),
fieldWithPath("memory.heap.max")
.description("The maximum number of bytes that can be used by the JVM (or -1)."),
fieldWithPath("memory.nonHeap").description("Non-heap memory."),
fieldWithPath("memory.nonHeap.init").description("The number of bytes initially requested by the JVM."),
fieldWithPath("memory.nonHeap.used").description("The number of bytes currently being used."),
fieldWithPath("memory.nonHeap.committed").description("The number of bytes committed for JVM use."),
fieldWithPath("memory.nonHeap.max")
.description("The maximum number of bytes that can be used by the JVM (or -1)."));
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)