DATAGEODE-111 - Add ability to configure SecurityManager on CacheFactoryBean.
This commit is contained in:
@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -99,8 +100,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
final AtomicBoolean postProcessBeforeCacheInitializationCalled = new AtomicBoolean(false);
|
||||
final Properties gemfireProperties = new Properties();
|
||||
|
||||
AtomicBoolean postProcessBeforeCacheInitializationCalled = new AtomicBoolean(false);
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
|
||||
@@ -119,6 +122,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationUsingDefaults() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
new CacheFactoryBean().postProcessBeforeCacheInitialization(gemfireProperties);
|
||||
@@ -132,7 +136,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationDisabled() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
@@ -148,7 +154,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationEnabled() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(true);
|
||||
@@ -164,7 +172,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectDisabledAndClusterConfigurationEnabled() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
@@ -180,9 +190,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectCallsInit() throws Exception {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
final AtomicBoolean initCalled = new AtomicBoolean(false);
|
||||
AtomicBoolean initCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override Cache init() {
|
||||
@@ -199,7 +210,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectReturnsExistingCache() throws Exception {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -323,9 +336,11 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveCacheCallsFetchCacheReturnsMock() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
|
||||
@Override @SuppressWarnings("unchecked ")
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
return (T) mockCache;
|
||||
@@ -339,13 +354,17 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveCacheCreatesCacheWhenFetchCacheThrowsCacheClosedException() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
final CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
|
||||
@Override
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
throw new CacheClosedException("test");
|
||||
}
|
||||
|
||||
@@ -364,7 +383,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void fetchExistingCache() throws Exception {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -378,7 +399,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveProperties() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(gemfireProperties);
|
||||
@@ -388,6 +411,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenNull() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(null);
|
||||
@@ -400,7 +424,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createFactory() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
Object cacheFactoryReference = new CacheFactoryBean().createFactory(gemfireProperties);
|
||||
|
||||
assertThat(cacheFactoryReference, is(instanceOf(CacheFactory.class)));
|
||||
@@ -415,10 +441,45 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithUnspecifiedPdxOptions() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializesFactoryWitCacheFactoryInitializer() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(new CacheFactoryBean().prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
CacheFactoryBean.CacheFactoryInitializer<Object> mockCacheFactoryInitializer =
|
||||
mock(CacheFactoryBean.CacheFactoryInitializer.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCacheFactoryInitializer(mockCacheFactoryInitializer);
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheFactoryInitializer(), is(equalTo(mockCacheFactoryInitializer)));
|
||||
assertThat(cacheFactoryBean.initializeFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactoryInitializer, times(1)).initialize(eq(mockCacheFactory));
|
||||
verifyZeroInteractions(mockCacheFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeFactoryWhenNoCacheFactoryInitializerIsPresentIsNullSafe() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheFactoryInitializer(),
|
||||
is(nullValue(CacheFactoryBean.CacheFactoryInitializer.class)));
|
||||
assertThat(cacheFactoryBean.initializeFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verifyZeroInteractions(mockCacheFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureFactoryWithUnspecifiedPdxOptions() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(new CacheFactoryBean().configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
|
||||
verify(mockCacheFactory, never()).setPdxIgnoreUnreadFields(any(Boolean.class));
|
||||
@@ -428,7 +489,8 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithSpecificPdxOptions() {
|
||||
public void configureFactoryWithSpecificPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxSerializer(mock(PdxSerializer.class));
|
||||
@@ -437,7 +499,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(cacheFactoryBean.prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
assertThat(cacheFactoryBean.configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
|
||||
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
|
||||
@@ -447,7 +509,8 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithAllPdxOptions() {
|
||||
public void configureFactoryWithAllPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxDiskStoreName("testPdxDiskStoreName");
|
||||
@@ -458,7 +521,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(cacheFactoryBean.prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
assertThat(cacheFactoryBean.configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setPdxDiskStore(eq("testPdxDiskStoreName"));
|
||||
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
|
||||
@@ -468,24 +531,44 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithExistingCache() throws Exception {
|
||||
public void configureFactoryWithSecurityManager() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
org.apache.geode.security.SecurityManager mockSecurityManager =
|
||||
mock(org.apache.geode.security.SecurityManager.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
cacheFactoryBean.setSecurityManager(mockSecurityManager);
|
||||
|
||||
assertThat(cacheFactoryBean.getCache(), is(sameInstance(mockCache)));
|
||||
assertThat(cacheFactoryBean.getSecurityManager(), is(sameInstance(mockSecurityManager)));
|
||||
assertThat(cacheFactoryBean.configureFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setSecurityManager(eq(mockSecurityManager));
|
||||
verifyZeroInteractions(mockSecurityManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithCacheFactory() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
Cache actualCache = cacheFactoryBean.createCache(mockCacheFactory);
|
||||
|
||||
assertThat(actualCache, is(sameInstance(mockCache)));
|
||||
assertThat(actualCache, is(equalTo(mockCache)));
|
||||
|
||||
verify(mockCacheFactory, never()).create();
|
||||
verify(mockCacheFactory, times(1)).create();
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithNoExistingCache() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
@@ -502,7 +585,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidCriticalHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCriticalHeapPercentage(200.0f);
|
||||
@@ -521,7 +606,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidCriticalOffHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCriticalOffHeapPercentage(200.0f);
|
||||
@@ -540,7 +627,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidEvictionHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEvictionHeapPercentage(-75.0f);
|
||||
@@ -559,7 +648,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidEvictionOffHeapPercentage() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEvictionOffHeapPercentage(-75.0f);
|
||||
@@ -584,7 +675,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectTypeWithExistingCache() {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -600,8 +693,10 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroy() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
final Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
GemfireBeanFactoryLocator mockGemfireBeanFactoryLocator = mock(GemfireBeanFactoryLocator.class);
|
||||
|
||||
@@ -631,7 +726,8 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroyWhenCacheIsNull() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -650,8 +746,10 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroyWhenCacheClosedIsTrue() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
final Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override @SuppressWarnings("unchecked") protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -672,6 +770,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void closeCache() {
|
||||
|
||||
GemFireCache mockCache = mock(GemFireCache.class, "testCloseCache.MockCache");
|
||||
|
||||
new CacheFactoryBean().close(mockCache);
|
||||
|
||||
@@ -273,7 +273,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(clientCacheFactoryBean.prepareFactory(mockClientCacheFactory),
|
||||
assertThat(clientCacheFactoryBean.configureFactory(mockClientCacheFactory),
|
||||
is(sameInstance(mockClientCacheFactory)));
|
||||
assertThat(initializePdxCalled.get(), is(true));
|
||||
assertThat(initializePoolCalled.get(), is(true));
|
||||
|
||||
Reference in New Issue
Block a user