Refactor tests for GemfireTemplate auto-configuration.

This commit is contained in:
John Blum
2021-08-18 14:09:59 -07:00
parent b473d80ed8
commit 389feac355
7 changed files with 32 additions and 11 deletions

View File

@@ -106,8 +106,11 @@ public class CachingDefinedRegionTemplateAutoConfigurationIntegrationTests exten
.collect(Collectors.toList())).containsExactly("BooksByAuthor", "BooksByYear", "CachedBooks");
assertThat(this.booksByAuthor).isNotNull();
assertThat(this.booksByAuthor.getName()).isEqualTo("BooksByAuthor");
assertThat(this.booksByTitle).isNotNull();
assertThat(this.booksByTitle.getName()).isEqualTo("CachedBooks");
assertThat(this.booksByYear).isNotNull();
assertThat(this.booksByYear.getName()).isEqualTo("BooksByYear");
}
@Test
@@ -131,18 +134,21 @@ public class CachingDefinedRegionTemplateAutoConfigurationIntegrationTests exten
assertThat(this.booksByYearTemplate.getRegion()).isEqualTo(this.booksByYear);
}
@EnableGemFireMockObjects
@EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL)
@SpringBootApplication(scanBasePackageClasses = { NonBeanType.class, LibraryService.class })
static class TestApplicationConfiguration {
@EnableCachingDefinedRegions(clientRegionShortcut = ClientRegionShortcut.LOCAL)
@EnableGemFireMockObjects
static class TestConfiguration {
@Bean
LibraryService libraryService() {
return new LibraryService();
}
// TODO: Cannot autowire/inject the "booksByAuthorTemplate" GemfireTemplate bean since the "BooksByAuthor"
// Region does not yet exist when processing the Java-based Spring configuration given the nature of
// the EnableCachingDefinedRegions annotation configuration bean creation.
//@Bean("TestBean")
Object testBean(@Qualifier("booksByAuthor") GemfireTemplate booksByAuthorTemplate) {
Object testBean(@Qualifier("booksByAuthorTemplate") GemfireTemplate booksByAuthorTemplate) {
return "TEST";
}
}

View File

@@ -43,7 +43,8 @@ import org.springframework.test.context.junit4.SpringRunner;
* Integration Tests for {@link RegionTemplateAutoConfiguration}.
*
* This Integration Test class tests that the {@link GemfireTemplate} is created regardless of whether
* the {@literal Example} client {@link Region} bean is actually referenced (injected) into application code.
* the {@literal Example} client {@link Region} bean is actually referenced (autowired/injected) into
* application code.
*
* @author John Blum
* @see org.junit.Test

View File

@@ -85,7 +85,7 @@ public class DeclaredRegionTemplateAutoConfigurationIntegrationTests extends Int
@SpringBootApplication
@EnableGemFireMockObjects
static class TestGemFireConfiguration {
static class TestConfiguration {
@Bean("Example")
ClientRegionFactoryBean<Long, String> exampleRegion(GemFireCache gemfireCache) {
@@ -97,5 +97,10 @@ public class DeclaredRegionTemplateAutoConfigurationIntegrationTests extends Int
return exampleRegion;
}
@Bean("TestBean")
public Object testBean(@Qualifier("exampleTemplate") GemfireTemplate exampleTemplate) {
return "TEST";
}
}
}

View File

@@ -98,7 +98,9 @@ public class EntityDefinedRegionTemplateAutoConfigurationIntegrationTests extend
.collect(Collectors.toList())).containsExactly("Authors", "Books");
assertThat(this.authors).isNotNull();
assertThat(this.authors.getName()).isEqualTo("Authors");
assertThat(this.books).isNotNull();
assertThat(this.books.getName()).isEqualTo("Books");
}
@Test
@@ -118,7 +120,7 @@ public class EntityDefinedRegionTemplateAutoConfigurationIntegrationTests extend
@SpringBootApplication
@EnableGemFireMockObjects
@EnableEntityDefinedRegions(basePackageClasses = Book.class, clientRegionShortcut = ClientRegionShortcut.LOCAL)
static class TestApplicationConfiguration {
static class TestConfiguration {
@Bean("TestBean")
Object testBean(@Qualifier("booksTemplate") GemfireTemplate booksTemplate) {

View File

@@ -83,7 +83,6 @@ public class ExistingRegionTemplateByNameAutoConfigurationIntegrationTests exten
ClientRegionFactoryBean<Object, Object> exampleRegion = new ClientRegionFactoryBean<>();
exampleRegion.setCache(gemfireCache);
exampleRegion.setClose(false);
exampleRegion.setShortcut(ClientRegionShortcut.LOCAL);
return exampleRegion;

View File

@@ -37,6 +37,7 @@ import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
import org.springframework.geode.boot.autoconfigure.RegionTemplateAutoConfiguration;
import org.springframework.geode.core.util.SpringExtensions;
import org.springframework.test.context.junit4.SpringRunner;
/**
@@ -69,11 +70,19 @@ public class ExistingRegionTemplateByRegionAutoConfigurationIntegrationTests ext
@Resource(name = "Example")
private Region<Object, Object> example;
private void printBeanDefinitionMetadata(String beanName) {
System.err.printf("BEAN DEFINITION METADATA [%s]%n",
SpringExtensions.getBeanDefinitionMetadata("exampleTemplate", this.applicationContext));
}
@Test
public void exampleTemplateIsPresentButIsNotGemfireTemplate() {
public void exampleTemplateIsPresentButIsNotAGemfireTemplate() {
assertThat(this.applicationContext.containsBean("exampleTemplate")).isTrue();
assertThat(this.applicationContext.getBean("exampleTemplate")).isNotInstanceOf(GemfireTemplate.class);
//printBeanDefinitionMetadata("exampleTemplate");
}
@Test
@@ -84,6 +93,7 @@ public class ExistingRegionTemplateByRegionAutoConfigurationIntegrationTests ext
@Test
public void testTemplateIsPresent() {
assertThat(this.example).isNotNull();
assertThat(this.testTemplate).isNotNull();
assertThat(this.testTemplate.getRegion()).isEqualTo(this.example);
}
@@ -98,7 +108,6 @@ public class ExistingRegionTemplateByRegionAutoConfigurationIntegrationTests ext
ClientRegionFactoryBean<Object, Object> clientRegion = new ClientRegionFactoryBean<>();
clientRegion.setCache(gemfireCache);
clientRegion.setClose(false);
clientRegion.setShortcut(ClientRegionShortcut.LOCAL);
return clientRegion;

View File

@@ -147,7 +147,6 @@ public class ServerDefinedRegionTemplateAutoConfigurationIntegrationTests
LocalRegionFactoryBean<Object, Object> exampleServerRegion = new LocalRegionFactoryBean<>();
exampleServerRegion.setCache(gemfireCache);
exampleServerRegion.setClose(false);
exampleServerRegion.setPersistent(false);
return exampleServerRegion;