From 7b4e9d9b34ca724b684922f2fc980a3c3935e95b Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 25 Jan 2018 16:34:09 -0800 Subject: [PATCH] Add Integration Tests testing the auto-configuration of an Apache Geode ClientCache instance. --- ...pacheGeodeCacheClientApplicationTests.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 spring-boot-data-geode/src/test/java/org/springframework/boot/data/geode/cache/client/SpringBootApacheGeodeCacheClientApplicationTests.java diff --git a/spring-boot-data-geode/src/test/java/org/springframework/boot/data/geode/cache/client/SpringBootApacheGeodeCacheClientApplicationTests.java b/spring-boot-data-geode/src/test/java/org/springframework/boot/data/geode/cache/client/SpringBootApacheGeodeCacheClientApplicationTests.java new file mode 100644 index 00000000..33992a7e --- /dev/null +++ b/spring-boot-data-geode/src/test/java/org/springframework/boot/data/geode/cache/client/SpringBootApacheGeodeCacheClientApplicationTests.java @@ -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 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 exampleRegion(GemFireCache gemfireCache) { + + ClientRegionFactoryBean clientRegion = new ClientRegionFactoryBean<>(); + + clientRegion.setCache(gemfireCache); + clientRegion.setClose(false); + clientRegion.setShortcut(ClientRegionShortcut.LOCAL); + + return clientRegion; + } + } +}