DATAGEODE-180 - Switch from Apache Commons Logging to SLF4J.

This commit is contained in:
John Blum
2019-04-10 10:20:43 -07:00
parent 2b86f17096
commit ad8195a1a2
28 changed files with 235 additions and 230 deletions

View File

@@ -37,7 +37,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.query.Index;
@@ -52,6 +51,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
@@ -86,7 +86,7 @@ public class IndexFactoryBeanTest {
private IndexFactoryBean indexFactoryBean;
@Mock
private Log mockLog;
private Logger mockLogger;
@Mock
private QueryService mockQueryService;
@@ -98,6 +98,7 @@ public class IndexFactoryBeanTest {
@After
public void tearDown() {
indexFactoryBean.setBeanFactory(null);
indexFactoryBean.setCache(null);
indexFactoryBean.setDefine(false);
@@ -135,9 +136,10 @@ public class IndexFactoryBeanTest {
private IndexFactoryBean newIndexFactoryBean() {
IndexFactoryBean indexFactoryBean = spy(new IndexFactoryBean() {
@Override
protected Log newLog() {
return mockLog;
protected Logger newLog() {
return mockLogger;
}
});
@@ -732,7 +734,7 @@ public class IndexFactoryBeanTest {
Index mockIndex =
mockIndexWithDefinition("MockIndex", "id", "/Example", IndexType.PRIMARY_KEY);
when(mockLog.isWarnEnabled()).thenReturn(true);
when(mockLogger.isWarnEnabled()).thenReturn(true);
when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex));
@@ -755,7 +757,7 @@ public class IndexFactoryBeanTest {
verify(indexFactoryBean, times(1))
.createKeyIndex(eq(mockQueryService), eq("TestIndex"), eq("id"), eq("/Example"));
verify(mockLog, times(1)).warn(
verify(mockLogger, times(1)).warn(
eq(String.format("WARNING! You are choosing to ignore this Index [TestIndex] and return the existing Index"
+ " having the same basic definition [%s] but with a different name [MockIndex];"
+ " Make sure no OQL Query Hints refer to this Index by name [TestIndex]",
@@ -773,7 +775,7 @@ public class IndexFactoryBeanTest {
Index testIndex =
mockIndexWithDefinition("TestIndex", "id", "/Example", IndexType.PRIMARY_KEY);
when(mockLog.isWarnEnabled()).thenReturn(true);
when(mockLogger.isWarnEnabled()).thenReturn(true);
when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex));
@@ -796,7 +798,7 @@ public class IndexFactoryBeanTest {
verify(indexFactoryBean, times(2))
.createKeyIndex(eq(mockQueryService), eq("TestIndex"), eq("id"), eq("/Example"));
verify(mockLog, times(1)).warn(
verify(mockLogger, times(1)).warn(
eq(String.format("WARNING! You are attempting to 'override' an existing Index [MockIndex]"
+ " having the same basic definition [%s] as the Index that will be created by this"
+ " IndexFactoryBean [TestIndex]; 'Override' effectively 'renames' the existing Index [MockIndex]"
@@ -814,7 +816,7 @@ public class IndexFactoryBeanTest {
Index mockIndex =
mockIndexWithDefinition("MockIndex", "id", "/Example", IndexType.PRIMARY_KEY);
when(mockLog.isWarnEnabled()).thenReturn(true);
when(mockLogger.isWarnEnabled()).thenReturn(true);
when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex))
.thenReturn(Collections.emptyList());
@@ -858,7 +860,7 @@ public class IndexFactoryBeanTest {
verify(indexFactoryBean, times(2))
.createKeyIndex(eq(mockQueryService), eq("TestIndex"), eq("id"), eq("/Example"));
verify(mockLog, times(1)).warn(
verify(mockLogger, times(1)).warn(
eq(String.format("WARNING! You are attempting to 'override' an existing Index [MockIndex]"
+ " having the same basic definition [%s] as the Index that will be created by this"
+ " IndexFactoryBean [TestIndex]; 'Override' effectively 'renames' the existing Index [MockIndex]"
@@ -918,7 +920,7 @@ public class IndexFactoryBeanTest {
.createFunctionalIndex(eq(mockQueryService), eq("TestIndex"),
eq("id"), eq("/Example"), eq(null));
verifyZeroInteractions(mockLog);
verifyZeroInteractions(mockLogger);
verify(mockQueryService, times(1)).getIndexes();
}
@@ -966,7 +968,7 @@ public class IndexFactoryBeanTest {
.createFunctionalIndex(eq(mockQueryService), eq("TestIndex"),
eq("id"), eq("/Example"), eq(null));
verifyZeroInteractions(mockLog);
verifyZeroInteractions(mockLogger);
verify(mockQueryService, times(1)).getIndexes();
}
@@ -1000,7 +1002,7 @@ public class IndexFactoryBeanTest {
.createFunctionalIndex(eq(mockQueryService), eq("TestIndex"), eq("price"),
eq("/Orders"), eq(null));
verifyZeroInteractions(mockLog);
verifyZeroInteractions(mockLogger);
verify(mockQueryService, times(1)).getIndexes();
}
@@ -1011,7 +1013,7 @@ public class IndexFactoryBeanTest {
Index mockIndex =
mockIndexWithDefinition("TestIndex", "id", "/Orders", IndexType.PRIMARY_KEY);
when(mockLog.isWarnEnabled()).thenReturn(true);
when(mockLogger.isWarnEnabled()).thenReturn(true);
when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex));
@@ -1038,7 +1040,7 @@ public class IndexFactoryBeanTest {
.createFunctionalIndex(eq(mockQueryService), eq("TestIndex"), eq("price"),
eq("/Orders"), eq(null));
verify(mockLog, times(1)).warn(String.format(
verify(mockLogger, times(1)).warn(String.format(
"WARNING! Returning existing Index [TestIndex] having a definition [%1$s] that does not match"
+ " the Index defined [%2$s] by this IndexFactoryBean [TestIndex]",
existingIndexDefinition, indexFactoryBean.toBasicIndexDefinition()));
@@ -1082,7 +1084,7 @@ public class IndexFactoryBeanTest {
verify(indexFactoryBean, times(1))
.createKeyIndex(eq(mockQueryService), eq("TestIndex"), eq("id"), eq("/Example"));
verifyZeroInteractions(mockLog);
verifyZeroInteractions(mockLogger);
verify(mockQueryService, times(1)).getIndexes();
}
@@ -1098,7 +1100,7 @@ public class IndexFactoryBeanTest {
assertThat(mockIndex).isNotSameAs(testIndex);
when(mockLog.isWarnEnabled()).thenReturn(true);
when(mockLogger.isWarnEnabled()).thenReturn(true);
when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex));
@@ -1124,7 +1126,7 @@ public class IndexFactoryBeanTest {
verify(indexFactoryBean, times(2)).createHashIndex(eq(mockQueryService),
eq("TestIndex"), eq("purchaseDate"), eq("/Orders"), eq(null));
verify(mockLog, times(1)).warn(eq(String.format(
verify(mockLogger, times(1)).warn(eq(String.format(
"WARNING! Overriding existing Index [TestIndex] having a definition [%1$s] that does not match"
+ " the Index defined [%2$s] by this IndexFactoryBean [TestIndex]",
existingIndexDefinition, indexFactoryBean.toBasicIndexDefinition())));
@@ -1139,7 +1141,7 @@ public class IndexFactoryBeanTest {
mockIndexWithDefinition("MockIndex", "purchaseDate", "/Example",
IndexType.HASH);
when(mockLog.isWarnEnabled()).thenReturn(true);
when(mockLogger.isWarnEnabled()).thenReturn(true);
when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex))
.thenReturn(Collections.emptyList());
@@ -1186,7 +1188,7 @@ public class IndexFactoryBeanTest {
verify(indexFactoryBean, times(2))
.createKeyIndex(eq(mockQueryService), eq("MockIndex"), eq("id"), eq("/Example"));
verify(mockLog, times(1)).warn(eq(String.format(
verify(mockLogger, times(1)).warn(eq(String.format(
"WARNING! Overriding existing Index [MockIndex] having a definition [%1$s] that does not match"
+ " the Index defined [%2$s] by this IndexFactoryBean [MockIndex]",
existingIndexDefinition, indexFactoryBean.toBasicIndexDefinition())));

View File

@@ -16,11 +16,11 @@
package org.springframework.data.gemfire.config.support;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.Matchers.startsWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashMap;
import org.apache.commons.logging.Log;
import org.apache.geode.cache.query.MultiIndexCreationException;
import org.apache.geode.cache.query.QueryService;
import org.junit.Before;
@@ -38,6 +37,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
@@ -75,7 +75,7 @@ public class DefinedIndexesApplicationListenerUnitTests {
}
protected <K, V> HashMap<K, V> newHashMap(K key, V value) {
return new HashMap<K, V>(Collections.singletonMap(key, value));
return new HashMap<>(Collections.singletonMap(key, value));
}
protected MultiIndexCreationException newMultiIndexCreationException(String key, Exception cause) {
@@ -84,6 +84,7 @@ public class DefinedIndexesApplicationListenerUnitTests {
@Test
public void createDefinedIndexesCalledOnContextRefreshedEvent() throws Exception {
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true);
when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)))
.thenReturn(mockQueryService);
@@ -98,6 +99,7 @@ public class DefinedIndexesApplicationListenerUnitTests {
@Test
public void createDefinedIndexesNotCalledOnContextRefreshedEvent() throws Exception {
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(false);
listener.onApplicationEvent(mockEvent);
@@ -110,16 +112,17 @@ public class DefinedIndexesApplicationListenerUnitTests {
@Test
public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception {
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true);
when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)))
.thenReturn(mockQueryService);
when(mockQueryService.createDefinedIndexes())
.thenThrow(newMultiIndexCreationException("TestKey", new RuntimeException("TEST")));
final Log mockLog = mock(Log.class);
Logger mockLog = mock(Logger.class);
DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener() {
@Override Log initLogger() {
@Override Logger initLogger() {
return mockLog;
}
};

View File

@@ -27,9 +27,9 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.junit.Assume.assumeThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -49,7 +49,6 @@ import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.snapshot.CacheSnapshotService;
@@ -62,6 +61,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentMatchers;
import org.slf4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.gemfire.snapshot.event.ExportSnapshotApplicationEvent;
import org.springframework.data.gemfire.snapshot.event.ImportSnapshotApplicationEvent;
@@ -155,6 +155,7 @@ public class SnapshotServiceFactoryBeanTest {
@After
public void tearDown() {
factoryBean.setExports(null);
factoryBean.setImports(null);
factoryBean.setRegion(null);
@@ -425,7 +426,7 @@ public class SnapshotServiceFactoryBeanTest {
"MockSnapshotServiceAdapter");
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() throws Exception {
@Override public SnapshotServiceAdapter getObject() {
return mockSnapshotService;
}
};
@@ -439,7 +440,7 @@ public class SnapshotServiceFactoryBeanTest {
}
@Test
public void onApplicationEventWhenMatchUsingEventSnapshotMetadataPerformsExport() throws Exception {
public void onApplicationEventWhenMatchUsingEventSnapshotMetadataPerformsExport() {
Region mockRegion = mock(Region.class, "MockRegion");
@@ -456,7 +457,7 @@ public class SnapshotServiceFactoryBeanTest {
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(toArray(eventSnapshotMetadata));
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() throws Exception {
@Override public SnapshotServiceAdapter getObject() {
return mockSnapshotService;
}
};
@@ -476,7 +477,7 @@ public class SnapshotServiceFactoryBeanTest {
}
@Test
public void onApplicationEventWhenMatchUsingFactorySnapshotMetadataPerformsImport() throws Exception {
public void onApplicationEventWhenMatchUsingFactorySnapshotMetadataPerformsImport() {
SnapshotApplicationEvent mockSnapshotEvent = mock(ImportSnapshotApplicationEvent.class,
"MockImportSnapshotApplicationEvent");
@@ -491,7 +492,7 @@ public class SnapshotServiceFactoryBeanTest {
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null);
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() throws Exception {
@Override public SnapshotServiceAdapter getObject() {
return mockSnapshotService;
}
};
@@ -510,7 +511,7 @@ public class SnapshotServiceFactoryBeanTest {
}
@Test
public void onApplicationEventWhenNoMatchDoesNotPerformExport() throws Exception {
public void onApplicationEventWhenNoMatchDoesNotPerformExport() {
SnapshotApplicationEvent mockSnapshotEvent = mock(ExportSnapshotApplicationEvent.class,
"MockExportSnapshotApplicationEvent");
@@ -523,7 +524,7 @@ public class SnapshotServiceFactoryBeanTest {
mock(SnapshotServiceAdapter.class, "MockSnapshotServiceAdapter");
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() throws Exception {
@Override public SnapshotServiceAdapter getObject() {
return mockSnapshotService;
}
};
@@ -542,7 +543,7 @@ public class SnapshotServiceFactoryBeanTest {
}
@Test
public void onApplicationEventWhenNoMatchDoesNotPerformImport() throws Exception {
public void onApplicationEventWhenNoMatchDoesNotPerformImport() {
Region mockRegion = mock(Region.class, "MockRegion");
@@ -557,7 +558,7 @@ public class SnapshotServiceFactoryBeanTest {
when(mockSnapshotEvent.getSnapshotMetadata()).thenReturn(null);
SnapshotServiceFactoryBean factoryBean = new SnapshotServiceFactoryBean() {
@Override public SnapshotServiceAdapter getObject() throws Exception {
@Override public SnapshotServiceAdapter getObject() {
return mockSnapshotService;
}
};
@@ -1005,12 +1006,12 @@ public class SnapshotServiceFactoryBeanTest {
@Test
public void logDebugWhenDebugging() {
Log mockLog = mock(Log.class, "MockLog");
Logger mockLog = mock(Logger.class, "MockLog");
when(mockLog.isDebugEnabled()).thenReturn(true);
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
@Override Log createLog() {
@Override Logger createLog() {
return mockLog;
}
};
@@ -1026,12 +1027,12 @@ public class SnapshotServiceFactoryBeanTest {
@Test
public void logDebugWhenNotDebugging() {
Log mockLog = mock(Log.class, "MockLog");
Logger mockLog = mock(Logger.class, "MockLog");
when(mockLog.isDebugEnabled()).thenReturn(false);
TestSnapshotServiceAdapter snapshotService = new TestSnapshotServiceAdapter() {
@Override Log createLog() {
@Override Logger createLog() {
return mockLog;
}
};
@@ -1313,7 +1314,7 @@ public class SnapshotServiceFactoryBeanTest {
}
@Test
public void createSnapshotMetadataWithFileGemFireFormatAndNullFilter() throws Exception {
public void createSnapshotMetadataWithFileGemFireFormatAndNullFilter() {
SnapshotMetadata snapshotMetadata = new SnapshotMetadata(snapshotDat, SnapshotFormat.GEMFIRE, null);

View File

@@ -25,13 +25,13 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.apache.commons.logging.Log;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.springframework.beans.factory.BeanFactory;
/**
@@ -49,7 +49,7 @@ import org.springframework.beans.factory.BeanFactory;
public class AbstractFactoryBeanSupportUnitTests {
@Mock
private Log mockLog;
private Logger mockLog;
@Spy
private TestFactoryBeanSupport<?> factoryBeanSupport;
@@ -61,6 +61,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void setAndGetBeanClassLoader() {
assertThat(factoryBeanSupport.getBeanClassLoader()).isNull();
ClassLoader mockClassLoader = mock(ClassLoader.class);
@@ -82,6 +83,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void setAndGetBeanFactory() {
assertThat(factoryBeanSupport.getBeanFactory()).isNull();
BeanFactory mockBeanFactory = mock(BeanFactory.class);
@@ -97,6 +99,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void setAndGetBeanName() {
assertThat(factoryBeanSupport.getBeanName()).isNullOrEmpty();
factoryBeanSupport.setBeanName("test");
@@ -115,6 +118,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void logsDebugWhenDebugIsEnabled() {
when(mockLog.isDebugEnabled()).thenReturn(true);
factoryBeanSupport.logDebug("%s log test", "debug");
@@ -125,6 +129,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void logsInfoWhenInfoIsEnabled() {
when(mockLog.isInfoEnabled()).thenReturn(true);
factoryBeanSupport.logInfo("%s log test", "info");
@@ -135,6 +140,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void logsWarningWhenWarnIsEnabled() {
when(mockLog.isWarnEnabled()).thenReturn(true);
factoryBeanSupport.logWarning("%s log test", "warn");
@@ -145,6 +151,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void logsWarningWhenErrorIsEnabled() {
when(mockLog.isErrorEnabled()).thenReturn(true);
factoryBeanSupport.logError("%s log test", "error");
@@ -155,6 +162,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void suppressesDebugLoggingWhenDebugIsDisabled() {
when(mockLog.isDebugEnabled()).thenReturn(false);
factoryBeanSupport.logDebug(() -> "test");
@@ -165,6 +173,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void suppressesInfoLoggingWhenInfoIsDisabled() {
when(mockLog.isInfoEnabled()).thenReturn(false);
factoryBeanSupport.logInfo(() -> "test");
@@ -175,6 +184,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void suppressesWarnLoggingWhenWarnIsDisabled() {
when(mockLog.isWarnEnabled()).thenReturn(false);
factoryBeanSupport.logWarning(() -> "test");
@@ -185,6 +195,7 @@ public class AbstractFactoryBeanSupportUnitTests {
@Test
public void suppressesErrorLoggingWhenInfoIsDisabled() {
when(mockLog.isErrorEnabled()).thenReturn(false);
factoryBeanSupport.logError(() -> "test");
@@ -196,7 +207,7 @@ public class AbstractFactoryBeanSupportUnitTests {
private static class TestFactoryBeanSupport<T> extends AbstractFactoryBeanSupport<T> {
@Override
public T getObject() throws Exception {
public T getObject() {
return null;
}

View File

@@ -45,10 +45,10 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.geode.cache.Cache;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.ApplicationListener;
@@ -746,12 +746,12 @@ public class SpringContextBootstrappingInitializerTest {
@Test(expected = IllegalStateException.class)
public void testInitLogsErrors() throws Throwable {
Log mockLog = mock(Log.class, "testInitLogsErrors.MockLog");
Logger mockLog = mock(Logger.class, "testInitLogsErrors.MockLog");
SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer() {
@Override
protected Log initLogger() {
protected Logger initLogger() {
return mockLog;
}
@@ -829,8 +829,9 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void onContextRefreshedApplicationEvent() {
TestApplicationListener testApplicationListener = new TestApplicationListener(
"testOnContextRefreshedApplicationEvent");
TestApplicationListener testApplicationListener =
new TestApplicationListener("testOnContextRefreshedApplicationEvent");
try {
testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener);
@@ -853,8 +854,9 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void onContextStartedApplicationEvent() {
TestApplicationListener testApplicationListener = new TestApplicationListener(
"testOnContextStartedApplicationEvent");
TestApplicationListener testApplicationListener =
new TestApplicationListener("testOnContextStartedApplicationEvent");
try {
testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener);
@@ -875,8 +877,9 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void onContextStoppedApplicationEvent() {
TestApplicationListener testApplicationListener = new TestApplicationListener(
"testOnContextStartedApplicationEvent");
TestApplicationListener testApplicationListener =
new TestApplicationListener("testOnContextStartedApplicationEvent");
try {
testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener);
@@ -904,6 +907,7 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void onApplicationEventWithMultipleRegisteredApplicationListeners() {
TestApplicationListener testApplicationListenerOne = new TestApplicationListener("TestApplicationListener.1");
TestApplicationListener testApplicationListenerTwo = new TestApplicationListener("TestApplicationListener.2");
@@ -940,6 +944,7 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void onApplicationEventWithNoRegisteredApplicationListener() {
TestApplicationListener testApplicationListener = new TestApplicationListener("TestApplicationListener");
try {
@@ -960,6 +965,7 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void testNotifyOnExistingContextRefreshedEventBeforeApplicationContextExists() {
assertNull(SpringContextBootstrappingInitializer.contextRefreshedEvent);
TestApplicationListener testApplicationListener = new TestApplicationListener(
@@ -976,6 +982,7 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void testNotifyOnExistingContextRefreshedEventAfterContextRefreshed() {
ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(mock(ApplicationContext.class));
new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent);
@@ -994,6 +1001,7 @@ public class SpringContextBootstrappingInitializerTest {
@Test
public void testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent() {
ConfigurableApplicationContext mockApplicationContext = mock(ConfigurableApplicationContext.class,
"testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent");
@@ -1065,12 +1073,10 @@ public class SpringContextBootstrappingInitializerTest {
}
@Configuration
protected static class TestAppConfigOne {
}
protected static class TestAppConfigOne { }
@Configuration
protected static class TestAppConfigTwo {
}
protected static class TestAppConfigTwo { }
// TODO add additional multi-threaded test cases once MultithreadedTC test framework is added to the SDP project
// in order to properly test concurrency of notification and registration during Spring ApplicationContext creation.

View File

@@ -13,8 +13,8 @@
package org.springframework.data.gemfire.test;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.StringUtils;
@@ -33,18 +33,19 @@ public class GemfireTestApplicationContextInitializer implements ApplicationCont
public static final String GEMFIRE_TEST_RUNNER_DISABLED =
"org.springframework.data.gemfire.test.GemfireTestRunner.nomock";
protected final Log log = LogFactory.getLog(getClass());
protected final Logger logger = LoggerFactory.getLogger(getClass());
/**
* {@inheritDoc}
*/
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
String gemfireTestRunnerDisabled = System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED, Boolean.FALSE.toString());
if (isGemFireTestRunnerDisabled(gemfireTestRunnerDisabled)) {
log.warn(String.format("WARNING - Mocks disabled; Using real GemFire components (%1$s = %2$s)",
GEMFIRE_TEST_RUNNER_DISABLED, gemfireTestRunnerDisabled));
logger.warn("WARNING - Mocks disabled; Using real GemFire components [{} = {}]",
GEMFIRE_TEST_RUNNER_DISABLED, gemfireTestRunnerDisabled);
}
else {
applicationContext.getBeanFactory().addBeanPostProcessor(new GemfireTestBeanPostProcessor());

View File

@@ -12,8 +12,8 @@
*/
package org.springframework.data.gemfire.test;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.data.gemfire.CacheFactoryBean;
@@ -26,7 +26,7 @@ import org.springframework.data.gemfire.server.CacheServerFactoryBean;
*/
public class GemfireTestBeanPostProcessor implements BeanPostProcessor {
private static Log logger = LogFactory.getLog(GemfireTestBeanPostProcessor.class);
private static Logger logger = LoggerFactory.getLogger(GemfireTestBeanPostProcessor.class);
/*
* (non-Javadoc)
@@ -34,15 +34,17 @@ public class GemfireTestBeanPostProcessor implements BeanPostProcessor {
*/
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof CacheFactoryBean) {
String beanTypeName = bean.getClass().getName();
bean = (bean instanceof ClientCacheFactoryBean
? new MockClientCacheFactoryBean((ClientCacheFactoryBean) bean)
: new MockCacheFactoryBean((CacheFactoryBean) bean));
logger.info(String.format("Replacing the [%1$s] bean definition having type [%2$s] with mock [%3$s]...",
beanName, beanTypeName, bean.getClass().getName()));
logger.info("Replacing the [{}] bean definition having type [{}] with mock [{}]...",
beanName, beanTypeName, bean.getClass().getName());
}
else if (bean instanceof CacheServerFactoryBean) {
((CacheServerFactoryBean) bean).setCache(new StubCache());
@@ -59,5 +61,4 @@ public class GemfireTestBeanPostProcessor implements BeanPostProcessor {
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}