Add support for configuring logging groups via endpoint

See gh-17515
This commit is contained in:
HaiTao Zhang
2019-07-19 18:18:07 -07:00
committed by Madhura Bhave
parent 8197feac15
commit b9047c22e0
8 changed files with 482 additions and 29 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.logging;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NavigableSet;
import java.util.Set;
@@ -30,6 +31,7 @@ import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggerConfiguration;
import org.springframework.boot.logging.LoggingGroups;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -39,6 +41,7 @@ import org.springframework.util.Assert;
*
* @author Ben Hale
* @author Phillip Webb
* @author HaiTao Zhang
* @since 2.0.0
*/
@Endpoint(id = "loggers")
@@ -46,13 +49,17 @@ public class LoggersEndpoint {
private final LoggingSystem loggingSystem;
private final LoggingGroups loggingGroups;
/**
* Create a new {@link LoggersEndpoint} instance.
* @param loggingSystem the logging system to expose
* @param loggingGroups the logging group to expose if it exists
*/
public LoggersEndpoint(LoggingSystem loggingSystem) {
public LoggersEndpoint(LoggingSystem loggingSystem, LoggingGroups loggingGroups) {
Assert.notNull(loggingSystem, "LoggingSystem must not be null");
this.loggingSystem = loggingSystem;
this.loggingGroups = loggingGroups;
}
@ReadOperation
@@ -64,19 +71,32 @@ public class LoggersEndpoint {
Map<String, Object> result = new LinkedHashMap<>();
result.put("levels", getLevels());
result.put("loggers", getLoggers(configurations));
if (this.loggingGroups != null && this.loggingGroups.getLoggerGroupNames() != null) {
Set<String> groups = this.loggingGroups.getLoggerGroupNames();
result.put("groups", getLoggerGroups(groups));
}
return result;
}
@ReadOperation
public LoggerLevels loggerLevels(@Selector String name) {
Assert.notNull(name, "Name must not be null");
if (this.loggingGroups != null && this.loggingGroups.isGroup(name)) {
List<String> members = this.loggingGroups.getLoggerGroup(name);
LogLevel groupConfiguredLevel = this.loggingGroups.getLoggerGroupConfiguredLevel(name);
return new GroupLoggerLevels(groupConfiguredLevel, members);
}
LoggerConfiguration configuration = this.loggingSystem.getLoggerConfiguration(name);
return (configuration != null) ? new LoggerLevels(configuration) : null;
return (configuration != null) ? new SingleLoggerLevels(configuration) : null;
}
@WriteOperation
public void configureLogLevel(@Selector String name, @Nullable LogLevel configuredLevel) {
Assert.notNull(name, "Name must not be empty");
if (this.loggingGroups != null && this.loggingGroups.isGroup(name)) {
this.loggingGroups.setLoggerGroupLevel(name, configuredLevel);
return;
}
this.loggingSystem.setLogLevel(name, configuredLevel);
}
@@ -88,11 +108,21 @@ public class LoggersEndpoint {
private Map<String, LoggerLevels> getLoggers(Collection<LoggerConfiguration> configurations) {
Map<String, LoggerLevels> loggers = new LinkedHashMap<>(configurations.size());
for (LoggerConfiguration configuration : configurations) {
loggers.put(configuration.getName(), new LoggerLevels(configuration));
loggers.put(configuration.getName(), new SingleLoggerLevels(configuration));
}
return loggers;
}
private Map<String, LoggerLevels> getLoggerGroups(Set<String> groups) {
Map<String, LoggerLevels> loggerGroups = new LinkedHashMap<>(groups.size());
for (String name : groups) {
List<String> members = this.loggingGroups.getLoggerGroup(name);
LogLevel groupConfiguredLevel = this.loggingGroups.getLoggerGroupConfiguredLevel(name);
loggerGroups.put(name, new GroupLoggerLevels(groupConfiguredLevel, members));
}
return loggerGroups;
}
/**
* Levels configured for a given logger exposed in a JSON friendly way.
*/
@@ -100,11 +130,8 @@ public class LoggersEndpoint {
private String configuredLevel;
private String effectiveLevel;
public LoggerLevels(LoggerConfiguration configuration) {
this.configuredLevel = getName(configuration.getConfiguredLevel());
this.effectiveLevel = getName(configuration.getEffectiveLevel());
public LoggerLevels(LogLevel configuredLevel) {
this.configuredLevel = getName(configuredLevel);
}
private String getName(LogLevel level) {
@@ -113,6 +140,33 @@ public class LoggersEndpoint {
public String getConfiguredLevel() {
return this.configuredLevel;
}
}
public static class GroupLoggerLevels extends LoggerLevels {
private List<String> members;
public GroupLoggerLevels(LogLevel configuredLevel, List<String> members) {
super(configuredLevel);
this.members = members;
}
public List<String> getMembers() {
return this.members;
}
}
public static class SingleLoggerLevels extends LoggerLevels {
private String effectiveLevel;
public SingleLoggerLevels(LoggerConfiguration configuration) {
super(configuration.getConfiguredLevel());
this.effectiveLevel = super.getName(configuration.getEffectiveLevel());
}
public String getEffectiveLevel() {

View File

@@ -23,9 +23,12 @@ import java.util.Set;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.logging.LoggersEndpoint.GroupLoggerLevels;
import org.springframework.boot.actuate.logging.LoggersEndpoint.LoggerLevels;
import org.springframework.boot.actuate.logging.LoggersEndpoint.SingleLoggerLevels;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggerConfiguration;
import org.springframework.boot.logging.LoggingGroups;
import org.springframework.boot.logging.LoggingSystem;
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,46 +41,110 @@ import static org.mockito.Mockito.verify;
*
* @author Ben Hale
* @author Andy Wilkinson
* @author HaiTao Zhang
*/
class LoggersEndpointTests {
private final LoggingSystem loggingSystem = mock(LoggingSystem.class);
private final LoggingGroups loggingGroups = mock(LoggingGroups.class);
@Test
@SuppressWarnings("unchecked")
void loggersShouldReturnLoggerConfigurations() {
void loggersShouldReturnLoggerConfigurationsWithNoLoggerGroups() {
given(this.loggingSystem.getLoggerConfigurations())
.willReturn(Collections.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
given(this.loggingSystem.getSupportedLogLevels()).willReturn(EnumSet.allOf(LogLevel.class));
Map<String, Object> result = new LoggersEndpoint(this.loggingSystem).loggers();
given(this.loggingGroups.getLoggerGroupNames()).willReturn(null);
Map<String, Object> result = new LoggersEndpoint(this.loggingSystem, this.loggingGroups).loggers();
Map<String, LoggerLevels> loggers = (Map<String, LoggerLevels>) result.get("loggers");
Set<LogLevel> levels = (Set<LogLevel>) result.get("levels");
LoggerLevels rootLevels = loggers.get("ROOT");
SingleLoggerLevels rootLevels = (SingleLoggerLevels) loggers.get("ROOT");
assertThat(rootLevels.getConfiguredLevel()).isNull();
assertThat(rootLevels.getEffectiveLevel()).isEqualTo("DEBUG");
assertThat(levels).containsExactly(LogLevel.OFF, LogLevel.FATAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO,
LogLevel.DEBUG, LogLevel.TRACE);
assertThat(result.get("groups")).isNull();
}
@Test
@SuppressWarnings("unchecked")
void loggersShouldReturnLoggerConfigurationsWithLoggerGroups() {
given(this.loggingSystem.getLoggerConfigurations())
.willReturn(Collections.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
given(this.loggingSystem.getSupportedLogLevels()).willReturn(EnumSet.allOf(LogLevel.class));
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Collections.singletonList("test.member"));
given(this.loggingGroups.getLoggerGroupNames()).willReturn(Collections.singleton("test"));
given(this.loggingGroups.getLoggerGroupConfiguredLevel("test")).willReturn(LogLevel.DEBUG);
Map<String, Object> result = new LoggersEndpoint(this.loggingSystem, this.loggingGroups).loggers();
Map<String, LoggerLevels> loggerGroups = (Map<String, LoggerLevels>) result.get("groups");
GroupLoggerLevels testLoggerLevel = (GroupLoggerLevels) loggerGroups.get("test");
Map<String, LoggerLevels> loggers = (Map<String, LoggerLevels>) result.get("loggers");
Set<LogLevel> levels = (Set<LogLevel>) result.get("levels");
SingleLoggerLevels rootLevels = (SingleLoggerLevels) loggers.get("ROOT");
assertThat(rootLevels.getConfiguredLevel()).isNull();
assertThat(rootLevels.getEffectiveLevel()).isEqualTo("DEBUG");
assertThat(levels).containsExactly(LogLevel.OFF, LogLevel.FATAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO,
LogLevel.DEBUG, LogLevel.TRACE);
assertThat(loggerGroups).isNotNull();
assertThat(testLoggerLevel).isNotNull();
assertThat(testLoggerLevel.getConfiguredLevel()).isEqualTo("DEBUG");
assertThat(testLoggerLevel.getMembers()).isEqualTo(Collections.singletonList("test.member"));
}
@Test
void loggerLevelsWhenNameSpecifiedShouldReturnLevels() {
given(this.loggingGroups.isGroup("ROOT")).willReturn(false);
given(this.loggingSystem.getLoggerConfiguration("ROOT"))
.willReturn(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG));
LoggerLevels levels = new LoggersEndpoint(this.loggingSystem).loggerLevels("ROOT");
SingleLoggerLevels levels = (SingleLoggerLevels) new LoggersEndpoint(this.loggingSystem, this.loggingGroups)
.loggerLevels("ROOT");
assertThat(levels.getConfiguredLevel()).isNull();
assertThat(levels.getEffectiveLevel()).isEqualTo("DEBUG");
}
@Test
void groupNameSpecifiedShouldReturnConfiguredLevelAndMembers() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Collections.singletonList("test.member"));
given(this.loggingGroups.getLoggerGroupConfiguredLevel("test")).willReturn(LogLevel.DEBUG);
GroupLoggerLevels levels = (GroupLoggerLevels) new LoggersEndpoint(this.loggingSystem, this.loggingGroups)
.loggerLevels("test");
assertThat(levels.getConfiguredLevel()).isEqualTo("DEBUG");
assertThat(levels.getMembers()).isEqualTo(Collections.singletonList("test.member"));
}
@Test
void configureLogLevelShouldSetLevelOnLoggingSystem() {
new LoggersEndpoint(this.loggingSystem).configureLogLevel("ROOT", LogLevel.DEBUG);
given(this.loggingGroups.getLoggerGroup("ROOT")).willReturn(null);
new LoggersEndpoint(this.loggingSystem, this.loggingGroups).configureLogLevel("ROOT", LogLevel.DEBUG);
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
}
@Test
void configureLogLevelWithNullSetsLevelOnLoggingSystemToNull() {
new LoggersEndpoint(this.loggingSystem).configureLogLevel("ROOT", null);
given(this.loggingGroups.getLoggerGroup("ROOT")).willReturn(null);
new LoggersEndpoint(this.loggingSystem, this.loggingGroups).configureLogLevel("ROOT", null);
verify(this.loggingSystem).setLogLevel("ROOT", null);
}
@Test
void configureLogLevelInLoggerGroupShouldSetLevelOnLoggingSystem() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Collections.singletonList("test.member"));
new LoggersEndpoint(this.loggingSystem, this.loggingGroups).configureLogLevel("test", LogLevel.DEBUG);
verify(this.loggingGroups).setLoggerGroupLevel("test", LogLevel.DEBUG);
}
@Test
void configureLogLevelWithNullInLoggerGroupShouldSetLevelOnLoggingSystem() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Collections.singletonList("test.member"));
new LoggersEndpoint(this.loggingSystem, this.loggingGroups).configureLogLevel("test", null);
verify(this.loggingGroups).setLoggerGroupLevel("test", null);
}
// @Test
// void
}

View File

@@ -21,14 +21,17 @@ import java.util.Collections;
import java.util.EnumSet;
import net.minidev.json.JSONArray;
import org.hamcrest.collection.IsIterableContainingInAnyOrder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggerConfiguration;
import org.springframework.boot.logging.LoggingGroups;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -50,6 +53,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author HaiTao Zhang
*/
class LoggersEndpointWebIntegrationTests {
@@ -57,17 +61,26 @@ class LoggersEndpointWebIntegrationTests {
private LoggingSystem loggingSystem;
private LoggingGroups loggingGroups;
private ObjectProvider<LoggingGroups> loggingGroupsObjectProvider;
@BeforeEach
@AfterEach
void resetMocks(ConfigurableApplicationContext context, WebTestClient client) {
this.client = client;
this.loggingSystem = context.getBean(LoggingSystem.class);
this.loggingGroups = context.getBean(LoggingGroups.class);
this.loggingGroupsObjectProvider = context.getBean(ObjectProvider.class);
Mockito.reset(this.loggingSystem);
Mockito.reset(this.loggingGroups);
given(this.loggingSystem.getSupportedLogLevels()).willReturn(EnumSet.allOf(LogLevel.class));
given(this.loggingGroupsObjectProvider.getIfAvailable()).willReturn(this.loggingGroups);
}
@WebEndpointTest
void getLoggerShouldReturnAllLoggerConfigurations() {
given(this.loggingGroups.getLoggerGroupNames()).willReturn(null);
given(this.loggingSystem.getLoggerConfigurations())
.willReturn(Collections.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
this.client.get().uri("/actuator/loggers").exchange().expectStatus().isOk().expectBody().jsonPath("$.length()")
@@ -78,8 +91,27 @@ class LoggersEndpointWebIntegrationTests {
.isEqualTo("DEBUG");
}
@WebEndpointTest
void getLoggerShouldReturnAllLoggerConfigurationsWithLoggerGroups() {
given(this.loggingGroups.getLoggerGroupNames()).willReturn(Collections.singleton("test"));
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Arrays.asList("test.member1", "test.member2"));
given(this.loggingGroups.getLoggerGroupConfiguredLevel("test")).willReturn(LogLevel.DEBUG);
given(this.loggingSystem.getLoggerConfigurations())
.willReturn(Collections.singletonList(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG)));
this.client.get().uri("/actuator/loggers").exchange().expectStatus().isOk().expectBody().jsonPath("$.length()")
.isEqualTo(3).jsonPath("levels")
.isEqualTo(jsonArrayOf("OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"))
.jsonPath("loggers.length()").isEqualTo(1).jsonPath("loggers.ROOT.length()").isEqualTo(2)
.jsonPath("loggers.ROOT.configuredLevel").isEqualTo(null).jsonPath("loggers.ROOT.effectiveLevel")
.isEqualTo("DEBUG").jsonPath("groups.length()").isEqualTo(1).jsonPath("groups.test.length()")
.isEqualTo(2).jsonPath("groups.test.configuredLevel").isEqualTo("DEBUG")
.jsonPath("groups.test.members.length()").isEqualTo(2).jsonPath("groups.test.members")
.value(IsIterableContainingInAnyOrder.containsInAnyOrder("test.member1", "test.member2"));
}
@WebEndpointTest
void getLoggerShouldReturnLogLevels() {
given(this.loggingGroups.isGroup("ROOT")).willReturn(false);
given(this.loggingSystem.getLoggerConfiguration("ROOT"))
.willReturn(new LoggerConfiguration("ROOT", null, LogLevel.DEBUG));
this.client.get().uri("/actuator/loggers/ROOT").exchange().expectStatus().isOk().expectBody()
@@ -88,12 +120,24 @@ class LoggersEndpointWebIntegrationTests {
}
@WebEndpointTest
void getLoggersWhenLoggerNotFoundShouldReturnNotFound() {
void getLoggersWhenLoggerAndLoggerGroupNotFoundShouldReturnNotFound() {
this.client.get().uri("/actuator/loggers/com.does.not.exist").exchange().expectStatus().isNotFound();
}
@WebEndpointTest
void getLoggerGroupShouldReturnConfiguredLogLevelAndMembers() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroupConfiguredLevel("test")).willReturn(LogLevel.DEBUG);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Arrays.asList("test.member1", "test.member2"));
this.client.get().uri("actuator/loggers/test").exchange().expectStatus().isOk().expectBody()
.jsonPath("$.length()").isEqualTo(2).jsonPath("members")
.value(IsIterableContainingInAnyOrder.containsInAnyOrder("test.member1", "test.member2"))
.jsonPath("configuredLevel").isEqualTo("DEBUG");
}
@WebEndpointTest
void setLoggerUsingApplicationJsonShouldSetLogLevel() {
given(this.loggingGroups.isGroup("ROOT")).willReturn(false);
this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
.body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent();
verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG);
@@ -101,6 +145,7 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
void setLoggerUsingActuatorV2JsonShouldSetLogLevel() {
given(this.loggingGroups.isGroup("ROOT")).willReturn(false);
this.client.post().uri("/actuator/loggers/ROOT")
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON))
.body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent();
@@ -108,7 +153,26 @@ class LoggersEndpointWebIntegrationTests {
}
@WebEndpointTest
void setLoggerWithWrongLogLevelResultInBadRequestResponse() {
void setLoggerGroupUsingActuatorV2JsonShouldSetLogLevel() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Arrays.asList("test.member1", "test.member2"));
this.client.post().uri("/actuator/loggers/test")
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON))
.body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent();
verify(this.loggingGroups).setLoggerGroupLevel("test", LogLevel.DEBUG);
}
@WebEndpointTest
void setLoggerGroupUsingApplicationJsonShouldSetLogLevel() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Arrays.asList("test.member1", "test.member2"));
this.client.post().uri("/actuator/loggers/test").contentType(MediaType.APPLICATION_JSON)
.body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent();
verify(this.loggingGroups).setLoggerGroupLevel("test", LogLevel.DEBUG);
}
@WebEndpointTest
void setLoggerOrLoggerGroupWithWrongLogLevelResultInBadRequestResponse() {
this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.APPLICATION_JSON)
.body(Collections.singletonMap("configuredLevel", "other")).exchange().expectStatus().isBadRequest();
verifyZeroInteractions(this.loggingSystem);
@@ -116,6 +180,7 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
void setLoggerWithNullLogLevel() {
given(this.loggingGroups.isGroup("ROOT")).willReturn(false);
this.client.post().uri("/actuator/loggers/ROOT")
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON))
.body(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent();
@@ -124,12 +189,33 @@ class LoggersEndpointWebIntegrationTests {
@WebEndpointTest
void setLoggerWithNoLogLevel() {
given(this.loggingGroups.isGroup("ROOT")).willReturn(false);
this.client.post().uri("/actuator/loggers/ROOT")
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)).body(Collections.emptyMap())
.exchange().expectStatus().isNoContent();
verify(this.loggingSystem).setLogLevel("ROOT", null);
}
@WebEndpointTest
void setLoggerGroupWithNullLogLevel() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Arrays.asList("test.member1", "test.member2"));
this.client.post().uri("/actuator/loggers/test")
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON))
.body(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent();
verify(this.loggingGroups).setLoggerGroupLevel("test", null);
}
@WebEndpointTest
void setLoggerGroupWithNoLogLevel() {
given(this.loggingGroups.isGroup("test")).willReturn(true);
given(this.loggingGroups.getLoggerGroup("test")).willReturn(Arrays.asList("test.member1", "test.member2"));
this.client.post().uri("/actuator/loggers/test")
.contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)).body(Collections.emptyMap())
.exchange().expectStatus().isNoContent();
verify(this.loggingGroups).setLoggerGroupLevel("test", null);
}
@WebEndpointTest
void logLevelForLoggerWithNameThatCouldBeMistakenForAPathExtension() {
given(this.loggingSystem.getLoggerConfiguration("com.png"))
@@ -139,6 +225,16 @@ class LoggersEndpointWebIntegrationTests {
.jsonPath("effectiveLevel").isEqualTo("DEBUG");
}
@WebEndpointTest
void logLevelForLoggerGroupWithNameThatCouldBeMistakenForAPathExtension() {
given(this.loggingGroups.isGroup("com.png")).willReturn(true);
given(this.loggingGroups.getLoggerGroupConfiguredLevel("com.png")).willReturn(LogLevel.DEBUG);
given(this.loggingGroups.getLoggerGroup("com.png")).willReturn(Arrays.asList("test.member1", "test.member2"));
this.client.get().uri("/actuator/loggers/com.png").exchange().expectStatus().isOk().expectBody()
.jsonPath("$.length()").isEqualTo(2).jsonPath("configuredLevel").isEqualTo("DEBUG").jsonPath("members")
.value(IsIterableContainingInAnyOrder.containsInAnyOrder("test.member1", "test.member2"));
}
private JSONArray jsonArrayOf(Object... entries) {
JSONArray array = new JSONArray();
array.addAll(Arrays.asList(entries));
@@ -154,8 +250,19 @@ class LoggersEndpointWebIntegrationTests {
}
@Bean
LoggersEndpoint endpoint(LoggingSystem loggingSystem) {
return new LoggersEndpoint(loggingSystem);
ObjectProvider<LoggingGroups> loggingGroupsObjectProvider() {
return mock(ObjectProvider.class);
}
@Bean
LoggingGroups loggingGroups() {
return mock(LoggingGroups.class);
}
@Bean
LoggersEndpoint endpoint(LoggingSystem loggingSystem,
ObjectProvider<LoggingGroups> loggingGroupsObjectProvider) {
return new LoggersEndpoint(loggingSystem, loggingGroupsObjectProvider.getIfAvailable());
}
}