Add Integration Tests testing the auto-configuration of an Apache Geode ClientCache instance.

This commit is contained in:
John Blum
2018-01-25 16:34:09 -08:00
parent 8aa1a00571
commit 7b4e9d9b34

View File

@@ -0,0 +1,86 @@
/*
* 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.boot.data.geode.cache.client;
import static org.assertj.core.api.Assertions.assertThat;
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.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
import org.springframework.data.gemfire.util.RegionUtils;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration test testing the auto-configuration of an Apache Geode {@link ClientCache} instance.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.client.ClientCache
* @see org.springframework.boot.test.context.SpringBootTest
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.0.0
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@SuppressWarnings("unused")
public class SpringBootApacheGeodeCacheClientApplicationTests {
@Autowired
private ClientCache clientCache;
@Test
public void clientCacheAndClientRegionAreAvailable() {
assertThat(this.clientCache).isNotNull();
Region<Object, Object> example = this.clientCache.getRegion("Example");
assertThat(example).isNotNull();
assertThat(example.getName()).isEqualTo("Example");
assertThat(example.getFullPath()).isEqualTo(RegionUtils.toRegionPath("Example"));
example.put(1, "test");
assertThat(example.get(1)).isEqualTo("test");
}
@SpringBootApplication
static class TestConfiguration {
@Bean("Example")
public ClientRegionFactoryBean<Object, Object> exampleRegion(GemFireCache gemfireCache) {
ClientRegionFactoryBean<Object, Object> clientRegion = new ClientRegionFactoryBean<>();
clientRegion.setCache(gemfireCache);
clientRegion.setClose(false);
clientRegion.setShortcut(ClientRegionShortcut.LOCAL);
return clientRegion;
}
}
}