70
70
@ TestPropertySource (properties = "management.security.enabled=false" )
71
71
public class LoggersMvcEndpointTests {
72
72
73
+ private static final String PATH = "/application/loggers" ;
74
+
73
75
@ Autowired
74
76
private WebApplicationContext context ;
75
77
@@ -99,65 +101,62 @@ public void getLoggerShouldReturnAllLoggerConfigurations() throws Exception {
99
101
.singletonList (new LoggerConfiguration ("ROOT" , null , LogLevel .DEBUG )));
100
102
String expected = "{\" levels\" :[\" OFF\" ,\" FATAL\" ,\" ERROR\" ,\" WARN\" ,\" INFO\" ,\" DEBUG\" ,\" TRACE\" ],"
101
103
+ "\" loggers\" :{\" ROOT\" :{\" configuredLevel\" :null,\" effectiveLevel\" :\" DEBUG\" }}}" ;
102
- this .mvc .perform (get ("/application/loggers " )).andExpect (status ().isOk ())
104
+ this .mvc .perform (get (PATH + " " )).andExpect (status ().isOk ())
103
105
.andExpect (content ().json (expected ));
104
106
}
105
107
106
108
@ Test
107
109
public void getLoggersWhenDisabledShouldReturnNotFound () throws Exception {
108
110
this .context .getBean (LoggersEndpoint .class ).setEnabled (false );
109
- this .mvc .perform (get ("/application/loggers " )).andExpect (status ().isNotFound ());
111
+ this .mvc .perform (get (PATH + " " )).andExpect (status ().isNotFound ());
110
112
}
111
113
112
114
@ Test
113
115
public void getLoggerShouldReturnLogLevels () throws Exception {
114
116
given (this .loggingSystem .getLoggerConfiguration ("ROOT" ))
115
117
.willReturn (new LoggerConfiguration ("ROOT" , null , LogLevel .DEBUG ));
116
- this .mvc .perform (get ("/application/loggers /ROOT" )).andExpect (status ().isOk ())
118
+ this .mvc .perform (get (PATH + " /ROOT" )).andExpect (status ().isOk ())
117
119
.andExpect (content ().string (equalTo (
118
- "{\" configuredLevel\" :null," + " \" effectiveLevel\" :\" DEBUG\" }" )));
120
+ "{\" configuredLevel\" :null,\" effectiveLevel\" :\" DEBUG\" }" )));
119
121
}
120
122
121
123
@ Test
122
124
public void getLoggersRootWhenDisabledShouldReturnNotFound () throws Exception {
123
125
this .context .getBean (LoggersEndpoint .class ).setEnabled (false );
124
- this .mvc .perform (get ("/application/loggers/ROOT" ))
125
- .andExpect (status ().isNotFound ());
126
+ this .mvc .perform (get (PATH + "/ROOT" )).andExpect (status ().isNotFound ());
126
127
}
127
128
128
129
@ Test
129
130
public void getLoggersWhenLoggerNotFoundShouldReturnNotFound () throws Exception {
130
- this .mvc .perform (get ("/application/loggers /com.does.not.exist" ))
131
+ this .mvc .perform (get (PATH + " /com.does.not.exist" ))
131
132
.andExpect (status ().isNotFound ());
132
133
}
133
134
134
135
@ Test
135
136
public void contentTypeForGetDefaultsToActuatorV2Json () throws Exception {
136
- this .mvc .perform (get ("/application/loggers " )).andExpect (status ().isOk ())
137
+ this .mvc .perform (get (PATH + " " )).andExpect (status ().isOk ())
137
138
.andExpect (header ().string ("Content-Type" ,
138
139
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8" ));
139
140
}
140
141
141
142
@ Test
142
143
public void contentTypeForGetCanBeApplicationJson () throws Exception {
143
- this .mvc .perform (get ("/application/loggers " ).header (HttpHeaders .ACCEPT ,
144
+ this .mvc .perform (get (PATH + " " ).header (HttpHeaders .ACCEPT ,
144
145
MediaType .APPLICATION_JSON_VALUE )).andExpect (status ().isOk ())
145
146
.andExpect (header ().string ("Content-Type" ,
146
147
MediaType .APPLICATION_JSON_UTF8_VALUE ));
147
148
}
148
149
149
150
@ Test
150
151
public void setLoggerUsingApplicationJsonShouldSetLogLevel () throws Exception {
151
- this .mvc .perform (
152
- post ("/application/loggers/ROOT" ).contentType (MediaType .APPLICATION_JSON )
153
- .content ("{\" configuredLevel\" :\" debug\" }" ))
154
- .andExpect (status ().isOk ());
152
+ this .mvc .perform (post (PATH + "/ROOT" ).contentType (MediaType .APPLICATION_JSON )
153
+ .content ("{\" configuredLevel\" :\" debug\" }" )).andExpect (status ().isOk ());
155
154
verify (this .loggingSystem ).setLogLevel ("ROOT" , LogLevel .DEBUG );
156
155
}
157
156
158
157
@ Test
159
158
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel () throws Exception {
160
- this .mvc .perform (post ("/application/loggers /ROOT" )
159
+ this .mvc .perform (post (PATH + " /ROOT" )
161
160
.contentType (ActuatorMediaTypes .APPLICATION_ACTUATOR_V2_JSON )
162
161
.content ("{\" configuredLevel\" :\" debug\" }" )).andExpect (status ().isOk ());
163
162
verify (this .loggingSystem ).setLogLevel ("ROOT" , LogLevel .DEBUG );
@@ -166,18 +165,16 @@ public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
166
165
@ Test
167
166
public void setLoggerWhenDisabledShouldReturnNotFound () throws Exception {
168
167
this .context .getBean (LoggersEndpoint .class ).setEnabled (false );
169
- this .mvc .perform (
170
- post ("/application/loggers/ROOT" ).contentType (MediaType .APPLICATION_JSON )
171
- .content ("{\" configuredLevel\" :\" DEBUG\" }" ))
168
+ this .mvc .perform (post (PATH + "/ROOT" ).contentType (MediaType .APPLICATION_JSON )
169
+ .content ("{\" configuredLevel\" :\" DEBUG\" }" ))
172
170
.andExpect (status ().isNotFound ());
173
171
verifyZeroInteractions (this .loggingSystem );
174
172
}
175
173
176
174
@ Test
177
175
public void setLoggerWithWrongLogLevel () throws Exception {
178
- this .mvc .perform (
179
- post ("/application/loggers/ROOT" ).contentType (MediaType .APPLICATION_JSON )
180
- .content ("{\" configuredLevel\" :\" other\" }" ))
176
+ this .mvc .perform (post (PATH + "/ROOT" ).contentType (MediaType .APPLICATION_JSON )
177
+ .content ("{\" configuredLevel\" :\" other\" }" ))
181
178
.andExpect (status ().is4xxClientError ());
182
179
verifyZeroInteractions (this .loggingSystem );
183
180
}
@@ -187,9 +184,9 @@ public void logLevelForLoggerWithNameThatCouldBeMistakenForAPathExtension()
187
184
throws Exception {
188
185
given (this .loggingSystem .getLoggerConfiguration ("com.png" ))
189
186
.willReturn (new LoggerConfiguration ("com.png" , null , LogLevel .DEBUG ));
190
- this .mvc .perform (get ("/application/loggers /com.png" )).andExpect (status ().isOk ())
187
+ this .mvc .perform (get (PATH + " /com.png" )).andExpect (status ().isOk ())
191
188
.andExpect (content ().string (equalTo (
192
- "{\" configuredLevel\" :null," + " \" effectiveLevel\" :\" DEBUG\" }" )));
189
+ "{\" configuredLevel\" :null,\" effectiveLevel\" :\" DEBUG\" }" )));
193
190
}
194
191
195
192
@ Configuration
0 commit comments