Skip to content

Commit 9166bb5

Browse files
committed
Polish
1 parent 75f8e8a commit 9166bb5

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/LoggersMvcEndpointTests.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
@TestPropertySource(properties = "management.security.enabled=false")
7171
public class LoggersMvcEndpointTests {
7272

73+
private static final String PATH = "/application/loggers";
74+
7375
@Autowired
7476
private WebApplicationContext context;
7577

@@ -99,65 +101,62 @@ public void getLoggerShouldReturnAllLoggerConfigurations() throws Exception {
99101
.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
100102
String expected = "{\"levels\":[\"OFF\",\"FATAL\",\"ERROR\",\"WARN\",\"INFO\",\"DEBUG\",\"TRACE\"],"
101103
+ "\"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())
103105
.andExpect(content().json(expected));
104106
}
105107

106108
@Test
107109
public void getLoggersWhenDisabledShouldReturnNotFound() throws Exception {
108110
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());
110112
}
111113

112114
@Test
113115
public void getLoggerShouldReturnLogLevels() throws Exception {
114116
given(this.loggingSystem.getLoggerConfiguration("ROOT"))
115117
.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())
117119
.andExpect(content().string(equalTo(
118-
"{\"configuredLevel\":null," + "\"effectiveLevel\":\"DEBUG\"}")));
120+
"{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}")));
119121
}
120122

121123
@Test
122124
public void getLoggersRootWhenDisabledShouldReturnNotFound() throws Exception {
123125
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());
126127
}
127128

128129
@Test
129130
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"))
131132
.andExpect(status().isNotFound());
132133
}
133134

134135
@Test
135136
public void contentTypeForGetDefaultsToActuatorV2Json() throws Exception {
136-
this.mvc.perform(get("/application/loggers")).andExpect(status().isOk())
137+
this.mvc.perform(get(PATH + "")).andExpect(status().isOk())
137138
.andExpect(header().string("Content-Type",
138139
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
139140
}
140141

141142
@Test
142143
public void contentTypeForGetCanBeApplicationJson() throws Exception {
143-
this.mvc.perform(get("/application/loggers").header(HttpHeaders.ACCEPT,
144+
this.mvc.perform(get(PATH + "").header(HttpHeaders.ACCEPT,
144145
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
145146
.andExpect(header().string("Content-Type",
146147
MediaType.APPLICATION_JSON_UTF8_VALUE));
147148
}
148149

149150
@Test
150151
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());
155154
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
156155
}
157156

158157
@Test
159158
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
160-
this.mvc.perform(post("/application/loggers/ROOT")
159+
this.mvc.perform(post(PATH + "/ROOT")
161160
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
162161
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
163162
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
@@ -166,18 +165,16 @@ public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
166165
@Test
167166
public void setLoggerWhenDisabledShouldReturnNotFound() throws Exception {
168167
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\"}"))
172170
.andExpect(status().isNotFound());
173171
verifyZeroInteractions(this.loggingSystem);
174172
}
175173

176174
@Test
177175
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\"}"))
181178
.andExpect(status().is4xxClientError());
182179
verifyZeroInteractions(this.loggingSystem);
183180
}
@@ -187,9 +184,9 @@ public void logLevelForLoggerWithNameThatCouldBeMistakenForAPathExtension()
187184
throws Exception {
188185
given(this.loggingSystem.getLoggerConfiguration("com.png"))
189186
.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())
191188
.andExpect(content().string(equalTo(
192-
"{\"configuredLevel\":null," + "\"effectiveLevel\":\"DEBUG\"}")));
189+
"{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}")));
193190
}
194191

195192
@Configuration

0 commit comments

Comments
 (0)