27
27
import org .springframework .boot .actuate .info .GitInfoContributor ;
28
28
import org .springframework .boot .actuate .info .InfoContributor ;
29
29
import org .springframework .boot .actuate .info .InfoEndpoint ;
30
+ import org .springframework .boot .actuate .info .OsInfoContributor ;
30
31
import org .springframework .boot .info .BuildProperties ;
31
32
import org .springframework .boot .info .GitProperties ;
32
33
import org .springframework .context .annotation .Bean ;
33
34
import org .springframework .context .annotation .Configuration ;
34
35
import org .springframework .restdocs .mockmvc .MockMvcRestDocumentation ;
36
+ import org .springframework .restdocs .payload .FieldDescriptor ;
35
37
import org .springframework .restdocs .payload .JsonFieldType ;
38
+ import org .springframework .restdocs .payload .ResponseFieldsSnippet ;
36
39
37
40
import static org .springframework .restdocs .payload .PayloadDocumentation .beneathPath ;
38
41
import static org .springframework .restdocs .payload .PayloadDocumentation .fieldWithPath ;
@@ -51,23 +54,40 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
51
54
void info () throws Exception {
52
55
this .mockMvc .perform (get ("/actuator/info" ))
53
56
.andExpect (status ().isOk ())
54
- .andDo (MockMvcRestDocumentation .document ("info" ,
55
- responseFields (beneathPath ("git" ),
56
- fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
57
- fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
58
- fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." )
59
- .type (JsonFieldType .VARIES ),
60
- fieldWithPath ("commit.id" ).description ("ID of the commit, if any." )),
61
- responseFields (beneathPath ("build" ),
62
- fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
63
- fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
64
- fieldWithPath ("name" ).description ("Name of the application, if any." )
65
- .type (JsonFieldType .STRING )
66
- .optional (),
67
- fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
68
- fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
69
- .type (JsonFieldType .VARIES )
70
- .optional ())));
57
+ .andDo (MockMvcRestDocumentation .document ("info" , gitInfo (), buildInfo (), osInfo ()));
58
+ }
59
+
60
+ private ResponseFieldsSnippet gitInfo () {
61
+ return responseFields (beneathPath ("git" ),
62
+ fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
63
+ fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
64
+ fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." ).type (JsonFieldType .VARIES ),
65
+ fieldWithPath ("commit.id" ).description ("ID of the commit, if any." ));
66
+ }
67
+
68
+ private ResponseFieldsSnippet buildInfo () {
69
+ return responseFields (beneathPath ("build" ),
70
+ fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
71
+ fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
72
+ fieldWithPath ("name" ).description ("Name of the application, if any." )
73
+ .type (JsonFieldType .STRING )
74
+ .optional (),
75
+ fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
76
+ fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
77
+ .type (JsonFieldType .VARIES )
78
+ .optional ());
79
+ }
80
+
81
+ private ResponseFieldsSnippet osInfo () {
82
+ return responseFields (beneathPath ("os" ), osInfoField ("name" , "Name" ), osInfoField ("version" , "Version" ),
83
+ osInfoField ("arch" , "Architecture" ));
84
+ }
85
+
86
+ private FieldDescriptor osInfoField (String field , String desc ) {
87
+ return fieldWithPath (field )
88
+ .description ("Operating System " + desc + " (as obtained from the 'os." + field + "' system property)." )
89
+ .type (JsonFieldType .STRING )
90
+ .optional ();
71
91
}
72
92
73
93
@ Configuration (proxyBeanMethods = false )
@@ -99,6 +119,11 @@ BuildInfoContributor buildInfoContributor() {
99
119
return new BuildInfoContributor (buildProperties );
100
120
}
101
121
122
+ @ Bean
123
+ OsInfoContributor osInfoContributor () {
124
+ return new OsInfoContributor ();
125
+ }
126
+
102
127
}
103
128
104
129
}
0 commit comments