Add additional Smoke Tests asserting Apache Geode logging configuration with the use of Spring Boot application.properties as well as JVM System Properties.

Effectively, these tests test the SBDG GeodeLoggingApplicationListener registration and function.

Resolves gh-73.
This commit is contained in:
John Blum
2020-02-14 15:11:30 -08:00
parent 1969f89492
commit 562dc6c6ed
7 changed files with 353 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.context.logging;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.geode.logging.slf4j.logback.StringAppender;
import org.springframework.geode.logging.slf4j.logback.support.LogbackSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstract base class containing functionality common to all Spring {@literal log-level} property Integration Tests.
*
* @author John Blum
* @see org.slf4j.Logger
* @see org.slf4j.LoggerFactory
* @see org.springframework.boot.ApplicationRunner
* @see org.springframework.boot.autoconfigure.SpringBootApplication
* @see org.springframework.context.annotation.Bean
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.geode.logging.slf4j.logback.StringAppender
* @since 1.3.0
*/
@SuppressWarnings("unused")
public abstract class AbstractSpringConfiguredLogLevelPropertyIntegrationTests extends IntegrationTestsSupport {
@Test
public void debugLogStatementsIsLogged() {
assertThat(getStringAppender().getLogOutput()).containsSequence("DEBUG TEST");
}
@Test
public void traceLogStatementIsNotLogged() {
assertThat(getStringAppender().getLogOutput()).doesNotContain("TRACE TEST");
}
protected Logger getOrgApacheGeodeLogger() {
return GeodeConfiguration.logger;
}
protected StringAppender getStringAppender() {
return GeodeConfiguration.stringAppender;
}
@SpringBootApplication
@EnableGemFireMockObjects
static class GeodeConfiguration {
// NOTE: The 'org.apache.geode' Logger declaration must be in this GeodeConfiguration class so Spring Boot
// LoggingSystem auto-configuration has a opportunity to configure logging and the logging provider first!
// This is needed by SBDG since the GeodeLoggingApplicationListener must also run!
private static final Logger logger = LoggerFactory.getLogger("org.apache.geode");
private static final StringAppender stringAppender = new StringAppender.Builder().buildAndStart();
static {
LogbackSupport.toLogbackLogger(logger).ifPresent(it -> {
LogbackSupport.removeConsoleAppender(it);
LogbackSupport.addAppender(it, stringAppender);
});
}
@Bean
ApplicationRunner runner() {
return args -> {
logger.debug("DEBUG TEST");
logger.trace("TRACE TEST");
};
}
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.context.logging;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for Apache Geode Logging configured with the {@literal spring.boot.data.gemfire.log.level} property
* in Spring Boot {@literal application.properties}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.boot.test.context.SpringBootTest
* @see AbstractSpringConfiguredLogLevelPropertyIntegrationTests
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.3.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
"spring.boot.data.gemfire.log.level=DEBUG",
"spring.data.gemfire.logging.level=TRACE",
"spring.data.gemfire.cache.log-level=ERROR",
})
public class SpringBootDataGemFireLogLevelApplicationPropertyIntegrationTests
extends AbstractSpringConfiguredLogLevelPropertyIntegrationTests {
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.context.logging;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for Apache Geode Logging configured with the {@literal spring.boot.data.gemfire.log.level} property
* in JVM {@link System} {@link System#getProperties() Properties}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.boot.test.context.SpringBootTest
* @see AbstractSpringConfiguredLogLevelPropertyIntegrationTests
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.3.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootDataGemFireLogLevelSystemPropertyIntegrationTests
extends AbstractSpringConfiguredLogLevelPropertyIntegrationTests {
@BeforeClass
public static void setup() {
System.setProperty("spring.boot.data.gemfire.log.level", "DEBUG");
System.setProperty("spring.data.gemfire.logging.level", "TRACE");
System.setProperty("spring.data.gemfire.cache.log-level", "ERROR");
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.context.logging;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for Apache Geode Logging configured with the {@literal spring.data.gemfire.cache.log-level} property
* in Spring Boot {@literal application.properties}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.boot.test.context.SpringBootTest
* @see AbstractSpringConfiguredLogLevelPropertyIntegrationTests
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.3.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.data.gemfire.cache.log-level=DEBUG")
public class SpringDataGemFireCacheLogLevelApplicationPropertyIntegrationTests
extends AbstractSpringConfiguredLogLevelPropertyIntegrationTests {
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.context.logging;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for Apache Geode Logging configured with the {@literal spring.data.gemfire.cache.log-level} property
* in JVM {@link System} {@link System#getProperties() Properties}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.boot.test.context.SpringBootTest
* @see AbstractSpringConfiguredLogLevelPropertyIntegrationTests
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.3.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringDataGemFireCacheLogLevelSystemPropertyIntegrationTests
extends AbstractSpringConfiguredLogLevelPropertyIntegrationTests {
@BeforeClass
public static void setup() {
System.setProperty("spring.data.gemfire.cache.log-level", "DEBUG");
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.context.logging;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for Apache Geode Logging configured with the {@literal spring.data.gemfire.logging.level} property
* in Spring Boot {@literal application.properties}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.boot.test.context.SpringBootTest
* @see AbstractSpringConfiguredLogLevelPropertyIntegrationTests
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.3.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
"spring.data.gemfire.logging.level=DEBUG",
"spring.data.gemfire.cache.log-level=TRACE",
})
public class SpringDataGemFireLoggingLevelApplicationPropertyIntegrationTests
extends AbstractSpringConfiguredLogLevelPropertyIntegrationTests {
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.springframework.geode.context.logging;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for Apache Geode Logging configured with the {@literal spring.data.gemfire.logging.level} property
* in JVM {@link System} {@link System#getProperties() Properties}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.boot.test.context.SpringBootTest
* @see AbstractSpringConfiguredLogLevelPropertyIntegrationTests
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.3.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringDataGemFireLoggingLevelSystemPropertyIntegrationTests
extends AbstractSpringConfiguredLogLevelPropertyIntegrationTests {
@BeforeClass
public static void setup() {
System.setProperty("spring.data.gemfire.logging.level", "DEBUG");
System.setProperty("spring.data.gemfire.cache.log-level", "TRACE");
}
}