Rename spring-test-data-gemfire module to spring-data-gemfire-test.

Rename spring-test-data-geode module to spring-data-geode-test.
This commit is contained in:
John Blum
2018-06-01 18:20:33 -07:00
parent 827383e5f2
commit 1195c89ad0
41 changed files with 10 additions and 13 deletions

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2018 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
*
* http://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.data.gemfire;
import static org.assertj.core.api.Assertions.assertThat;
import javax.annotation.Resource;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.data.gemfire.util.RegionUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests for an Apache Geode {@link ClientCache} application using mock objects.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cahce.Region
* @see org.apache.geode.cache.client.ClientCache
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.0.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("all")
public class MockClientCacheApplicationIntegrationTests {
@Resource(name = "Example")
private Region<Object, Object> example;
@Test
public void exampleRegionIsMocked() {
assertThat(this.example).isNotNull();
assertThat(this.example.getFullPath()).isEqualTo(RegionUtils.toRegionPath("Example"));
assertThat(this.example.getName()).isEqualTo("Example");
assertThat(this.example.put(1, "test")).isNull();
assertThat(this.example.get(1)).isEqualTo("test");
}
@EnableGemFireMockObjects
@ClientCacheApplication
static class TestConfiguration {
@Bean("Example")
public ClientRegionFactoryBean<Object, Object> exampleRegion(GemFireCache gemfireCache) {
ClientRegionFactoryBean<Object, Object> exampleRegion = new ClientRegionFactoryBean<>();
exampleRegion.setCache(gemfireCache);
exampleRegion.setClose(false);
exampleRegion.setShortcut(ClientRegionShortcut.LOCAL);
return exampleRegion;
}
}
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright 2018 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
*
* http://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.data.gemfire.tests.mock;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.support.AbstractSecurityManager;
/**
* Integration tests for {@link GemFireMockObjectsSupport}.
*
* @author John Blum
* @see java.util.Properties
* @see org.junit.Test
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.CacheFactory
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.GemFireMockObjectsSupport
* @since 1.0.0
*/
public class GemFireMockObjectsSupportIntegrationTests extends IntegrationTestsSupport {
@After
public void tearDown() {
GemFireMockObjectsSupport.destroy();
TestSecurityManager.constructed.set(false);
TestSecurityManager.destroyed.set(false);
TestSecurityPostProcessor.constructed.set(false);
}
@Test
public void constructsGemFireObjectsFromPropertiesSuccessfully() {
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("name", "TestConstructsGemFireObjectsFromPropertiesSuccessfully");
gemfireProperties.setProperty("security-manager", TestSecurityManager.class.getName());
assertThat(TestSecurityManager.constructed.get()).isFalse();
GemFireMockObjectsSupport.spyOn(new CacheFactory(gemfireProperties)).create();
assertThat(TestSecurityManager.constructed.get()).isTrue();
}
@Test
public void destroysConstructedGemFireObjectsFromPropertiesSuccessfully() {
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("name", "TestConstructsGemFireObjectsFromPropertiesSuccessfully");
gemfireProperties.setProperty("security-manager", TestSecurityManager.class.getName());
gemfireProperties.setProperty("security-post-processor", TestSecurityPostProcessor.class.getName());
assertThat(TestSecurityManager.constructed.get()).isFalse();
assertThat(TestSecurityManager.destroyed.get()).isFalse();
assertThat(TestSecurityPostProcessor.constructed.get()).isFalse();
GemFireMockObjectsSupport.spyOn(new CacheFactory(gemfireProperties)).create();
assertThat(TestSecurityManager.constructed.get()).isTrue();
assertThat(TestSecurityManager.destroyed.get()).isFalse();
assertThat(TestSecurityPostProcessor.constructed.get()).isTrue();
GemFireMockObjectsSupport.destroyGemFireObjects();
assertThat(TestSecurityManager.destroyed.get()).isTrue();
}
@Test
public void storesGemFirePropertiesSuccessfully() {
try {
System.setProperty("gemfire.name", "TestStoresGemFirePropertiesSuccessfully");
System.setProperty("gemfire.log-level", "config");
System.setProperty("gemfire.locators", "skullbox[12345]");
System.setProperty("non-gemfire.property", "test");
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("log-level", "info");
gemfireProperties.setProperty("jmx-manager-port", "1199");
gemfireProperties.setProperty("groups", "test,mock");
CacheFactory mockCacheFactory =
GemFireMockObjectsSupport.spyOn(new CacheFactory(gemfireProperties));
mockCacheFactory.set("groups", "qa,test,testers");
mockCacheFactory.set("conserve-sockets", "true");
Cache mockCache = mockCacheFactory.create();
assertThat(mockCache).isNotNull();
assertThat(mockCache.getDistributedSystem()).isNotNull();
Properties actualGemFireProperties = mockCache.getDistributedSystem().getProperties();
assertThat(actualGemFireProperties).isNotNull();
assertThat(actualGemFireProperties).hasSize(6);
assertThat(actualGemFireProperties.getProperty("name")).isEqualTo("TestStoresGemFirePropertiesSuccessfully");
assertThat(actualGemFireProperties.getProperty("log-level")).isEqualTo("config");
assertThat(actualGemFireProperties.getProperty("locators")).isEqualTo("skullbox[12345]");
assertThat(actualGemFireProperties.getProperty("jmx-manager-port")).isEqualTo("1199");
assertThat(actualGemFireProperties.getProperty("groups")).isEqualTo("qa,test,testers");
assertThat(actualGemFireProperties.getProperty("conserve-sockets")).isEqualTo("true");
}
finally {
System.clearProperty("gemfire.name");
System.clearProperty("gemfire.log-level");
System.clearProperty("non-gemfire.property");
}
}
public static final class TestSecurityManager extends AbstractSecurityManager implements DisposableBean {
private static final AtomicBoolean constructed = new AtomicBoolean(false);
private static final AtomicBoolean destroyed = new AtomicBoolean(false);
public TestSecurityManager() {
constructed.set(true);
}
@Override
public void destroy() throws Exception {
destroyed.set(true);
}
}
public static final class TestSecurityPostProcessor {
private static final AtomicBoolean constructed = new AtomicBoolean(false);
public TestSecurityPostProcessor() {
constructed.set(true);
}
}
}