Polish
This commit is contained in:
@@ -70,6 +70,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@TestPropertySource(properties = "management.security.enabled=false")
|
||||
public class LoggersMvcEndpointTests {
|
||||
|
||||
private static final String PATH = "/application/loggers";
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
|
||||
@@ -99,48 +101,47 @@ public class LoggersMvcEndpointTests {
|
||||
.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
|
||||
String expected = "{\"levels\":[\"OFF\",\"FATAL\",\"ERROR\",\"WARN\",\"INFO\",\"DEBUG\",\"TRACE\"],"
|
||||
+ "\"loggers\":{\"ROOT\":{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}}}";
|
||||
this.mvc.perform(get("/application/loggers")).andExpect(status().isOk())
|
||||
this.mvc.perform(get(PATH + "")).andExpect(status().isOk())
|
||||
.andExpect(content().json(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLoggersWhenDisabledShouldReturnNotFound() throws Exception {
|
||||
this.context.getBean(LoggersEndpoint.class).setEnabled(false);
|
||||
this.mvc.perform(get("/application/loggers")).andExpect(status().isNotFound());
|
||||
this.mvc.perform(get(PATH + "")).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLoggerShouldReturnLogLevels() throws Exception {
|
||||
given(this.loggingSystem.getLoggerConfiguration("ROOT"))
|
||||
.willReturn(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG));
|
||||
this.mvc.perform(get("/application/loggers/ROOT")).andExpect(status().isOk())
|
||||
this.mvc.perform(get(PATH + "/ROOT")).andExpect(status().isOk())
|
||||
.andExpect(content().string(equalTo(
|
||||
"{\"configuredLevel\":null," + "\"effectiveLevel\":\"DEBUG\"}")));
|
||||
"{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLoggersRootWhenDisabledShouldReturnNotFound() throws Exception {
|
||||
this.context.getBean(LoggersEndpoint.class).setEnabled(false);
|
||||
this.mvc.perform(get("/application/loggers/ROOT"))
|
||||
.andExpect(status().isNotFound());
|
||||
this.mvc.perform(get(PATH + "/ROOT")).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLoggersWhenLoggerNotFoundShouldReturnNotFound() throws Exception {
|
||||
this.mvc.perform(get("/application/loggers/com.does.not.exist"))
|
||||
this.mvc.perform(get(PATH + "/com.does.not.exist"))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeForGetDefaultsToActuatorV2Json() throws Exception {
|
||||
this.mvc.perform(get("/application/loggers")).andExpect(status().isOk())
|
||||
this.mvc.perform(get(PATH + "")).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
"application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentTypeForGetCanBeApplicationJson() throws Exception {
|
||||
this.mvc.perform(get("/application/loggers").header(HttpHeaders.ACCEPT,
|
||||
this.mvc.perform(get(PATH + "").header(HttpHeaders.ACCEPT,
|
||||
MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk())
|
||||
.andExpect(header().string("Content-Type",
|
||||
MediaType.APPLICATION_JSON_UTF8_VALUE));
|
||||
@@ -148,16 +149,14 @@ public class LoggersMvcEndpointTests {
|
||||
|
||||
@Test
|
||||
public void setLoggerUsingApplicationJsonShouldSetLogLevel() throws Exception {
|
||||
this.mvc.perform(
|
||||
post("/application/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"configuredLevel\":\"debug\"}"))
|
||||
.andExpect(status().isOk());
|
||||
this.mvc.perform(post(PATH + "/ROOT").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
|
||||
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLoggerUsingActuatorV2JsonShouldSetLogLevel() throws Exception {
|
||||
this.mvc.perform(post("/application/loggers/ROOT")
|
||||
this.mvc.perform(post(PATH + "/ROOT")
|
||||
.contentType(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON)
|
||||
.content("{\"configuredLevel\":\"debug\"}")).andExpect(status().isOk());
|
||||
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
|
||||
@@ -166,18 +165,16 @@ public class LoggersMvcEndpointTests {
|
||||
@Test
|
||||
public void setLoggerWhenDisabledShouldReturnNotFound() throws Exception {
|
||||
this.context.getBean(LoggersEndpoint.class).setEnabled(false);
|
||||
this.mvc.perform(
|
||||
post("/application/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"configuredLevel\":\"DEBUG\"}"))
|
||||
this.mvc.perform(post(PATH + "/ROOT").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"configuredLevel\":\"DEBUG\"}"))
|
||||
.andExpect(status().isNotFound());
|
||||
verifyZeroInteractions(this.loggingSystem);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLoggerWithWrongLogLevel() throws Exception {
|
||||
this.mvc.perform(
|
||||
post("/application/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"configuredLevel\":\"other\"}"))
|
||||
this.mvc.perform(post(PATH + "/ROOT").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"configuredLevel\":\"other\"}"))
|
||||
.andExpect(status().is4xxClientError());
|
||||
verifyZeroInteractions(this.loggingSystem);
|
||||
}
|
||||
@@ -187,9 +184,9 @@ public class LoggersMvcEndpointTests {
|
||||
throws Exception {
|
||||
given(this.loggingSystem.getLoggerConfiguration("com.png"))
|
||||
.willReturn(new LoggerConfiguration("com.png", null, LogLevel.DEBUG));
|
||||
this.mvc.perform(get("/application/loggers/com.png")).andExpect(status().isOk())
|
||||
this.mvc.perform(get(PATH + "/com.png")).andExpect(status().isOk())
|
||||
.andExpect(content().string(equalTo(
|
||||
"{\"configuredLevel\":null," + "\"effectiveLevel\":\"DEBUG\"}")));
|
||||
"{\"configuredLevel\":null,\"effectiveLevel\":\"DEBUG\"}")));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
Reference in New Issue
Block a user