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 .assertj .core .api .Assertions .assertThat ;
38
41
import static org .springframework .restdocs .payload .PayloadDocumentation .beneathPath ;
@@ -49,23 +52,40 @@ class InfoEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
49
52
@ Test
50
53
void info () {
51
54
assertThat (this .mvc .get ().uri ("/actuator/info" )).hasStatusOk ()
52
- .apply (MockMvcRestDocumentation .document ("info" ,
53
- responseFields (beneathPath ("git" ),
54
- fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
55
- fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
56
- fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." )
57
- .type (JsonFieldType .VARIES ),
58
- fieldWithPath ("commit.id" ).description ("ID of the commit, if any." )),
59
- responseFields (beneathPath ("build" ),
60
- fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
61
- fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
62
- fieldWithPath ("name" ).description ("Name of the application, if any." )
63
- .type (JsonFieldType .STRING )
64
- .optional (),
65
- fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
66
- fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
67
- .type (JsonFieldType .VARIES )
68
- .optional ())));
55
+ .apply (MockMvcRestDocumentation .document ("info" , gitInfo (), buildInfo (), osInfo ()));
56
+ }
57
+
58
+ private ResponseFieldsSnippet gitInfo () {
59
+ return responseFields (beneathPath ("git" ),
60
+ fieldWithPath ("branch" ).description ("Name of the Git branch, if any." ),
61
+ fieldWithPath ("commit" ).description ("Details of the Git commit, if any." ),
62
+ fieldWithPath ("commit.time" ).description ("Timestamp of the commit, if any." ).type (JsonFieldType .VARIES ),
63
+ fieldWithPath ("commit.id" ).description ("ID of the commit, if any." ));
64
+ }
65
+
66
+ private ResponseFieldsSnippet buildInfo () {
67
+ return responseFields (beneathPath ("build" ),
68
+ fieldWithPath ("artifact" ).description ("Artifact ID of the application, if any." ).optional (),
69
+ fieldWithPath ("group" ).description ("Group ID of the application, if any." ).optional (),
70
+ fieldWithPath ("name" ).description ("Name of the application, if any." )
71
+ .type (JsonFieldType .STRING )
72
+ .optional (),
73
+ fieldWithPath ("version" ).description ("Version of the application, if any." ).optional (),
74
+ fieldWithPath ("time" ).description ("Timestamp of when the application was built, if any." )
75
+ .type (JsonFieldType .VARIES )
76
+ .optional ());
77
+ }
78
+
79
+ private ResponseFieldsSnippet osInfo () {
80
+ return responseFields (beneathPath ("os" ), osInfoField ("name" , "Name" ), osInfoField ("version" , "Version" ),
81
+ osInfoField ("arch" , "Architecture" ));
82
+ }
83
+
84
+ private FieldDescriptor osInfoField (String field , String desc ) {
85
+ return fieldWithPath (field )
86
+ .description ("Operating System " + desc + " (as obtained from the 'os." + field + "' system property)." )
87
+ .type (JsonFieldType .STRING )
88
+ .optional ();
69
89
}
70
90
71
91
@ Configuration (proxyBeanMethods = false )
@@ -97,6 +117,11 @@ BuildInfoContributor buildInfoContributor() {
97
117
return new BuildInfoContributor (buildProperties );
98
118
}
99
119
120
+ @ Bean
121
+ OsInfoContributor osInfoContributor () {
122
+ return new OsInfoContributor ();
123
+ }
124
+
100
125
}
101
126
102
127
}
0 commit comments