diff --git a/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/AbstractSpringConfiguredLogLevelPropertyIntegrationTests.java b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/AbstractSpringConfiguredLogLevelPropertyIntegrationTests.java new file mode 100644 index 00000000..6928949f --- /dev/null +++ b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/AbstractSpringConfiguredLogLevelPropertyIntegrationTests.java @@ -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"); + }; + } + } +} diff --git a/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringBootDataGemFireLogLevelApplicationPropertyIntegrationTests.java b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringBootDataGemFireLogLevelApplicationPropertyIntegrationTests.java new file mode 100644 index 00000000..a4c29e72 --- /dev/null +++ b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringBootDataGemFireLogLevelApplicationPropertyIntegrationTests.java @@ -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 { + +} diff --git a/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringBootDataGemFireLogLevelSystemPropertyIntegrationTests.java b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringBootDataGemFireLogLevelSystemPropertyIntegrationTests.java new file mode 100644 index 00000000..c4fc37f6 --- /dev/null +++ b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringBootDataGemFireLogLevelSystemPropertyIntegrationTests.java @@ -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"); + } +} diff --git a/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireCacheLogLevelApplicationPropertyIntegrationTests.java b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireCacheLogLevelApplicationPropertyIntegrationTests.java new file mode 100644 index 00000000..9c8a1dd9 --- /dev/null +++ b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireCacheLogLevelApplicationPropertyIntegrationTests.java @@ -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 { + +} diff --git a/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireCacheLogLevelSystemPropertyIntegrationTests.java b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireCacheLogLevelSystemPropertyIntegrationTests.java new file mode 100644 index 00000000..037cb04f --- /dev/null +++ b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireCacheLogLevelSystemPropertyIntegrationTests.java @@ -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"); + } +} diff --git a/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireLoggingLevelApplicationPropertyIntegrationTests.java b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireLoggingLevelApplicationPropertyIntegrationTests.java new file mode 100644 index 00000000..8cf7b039 --- /dev/null +++ b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireLoggingLevelApplicationPropertyIntegrationTests.java @@ -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 { + +} diff --git a/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireLoggingLevelSystemPropertyIntegrationTests.java b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireLoggingLevelSystemPropertyIntegrationTests.java new file mode 100644 index 00000000..499b2201 --- /dev/null +++ b/spring-geode-tests/smoke-tests/logging/src/test/java/org/springframework/geode/context/logging/SpringDataGemFireLoggingLevelSystemPropertyIntegrationTests.java @@ -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"); + } +}