From b07e0e7b6ca8d751516c723a52b553de2dfe14a6 Mon Sep 17 00:00:00 2001 From: John Blum Date: Tue, 20 Sep 2022 14:34:59 -0700 Subject: [PATCH] Cleanup Java EE CDI integration tests. Rename the jakarta.enterprise.inject.spi.Extension META-INF/services file to javax.enterprise.inject.spi.Extension. Resolves #623. --- .../repository/cdi/GemfireRepositoryBean.java | 27 ++++++++++++------- .../cdi/GemfireRepositoryExtension.java | 22 +++++++++------ ... => javax.enterprise.inject.spi.Extension} | 0 .../cdi/CdiExtensionIntegrationTest.java | 24 ++++++++++------- .../cdi/CustomPersonRepository.java | 6 ++--- .../cdi/CustomPersonRepositoryImpl.java | 6 ++--- .../repository/cdi/RepositoryClient.java | 8 +++--- .../cdi/SamplePersonRepository.java | 5 ++-- 8 files changed, 57 insertions(+), 41 deletions(-) rename spring-data-geode/src/main/resources/META-INF/services/{jakarta.enterprise.inject.spi.Extension => javax.enterprise.inject.spi.Extension} (100%) diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java index b43da674..e0fdb04c 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryBean.java @@ -16,6 +16,8 @@ */ package org.springframework.data.gemfire.repository.cdi; +import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException; + import java.lang.annotation.Annotation; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -30,21 +32,25 @@ import javax.enterprise.inject.spi.BeanManager; import org.apache.geode.cache.Region; import org.springframework.data.gemfire.mapping.GemfireMappingContext; +import org.springframework.data.gemfire.repository.GemfireRepository; import org.springframework.data.gemfire.repository.support.GemfireRepositoryFactory; +import org.springframework.data.repository.Repository; import org.springframework.data.repository.cdi.CdiRepositoryBean; import org.springframework.data.repository.config.CustomRepositoryImplementationDetector; /** - * A CDI-based bean that represents a GemFire Repository. + * A CDI-based bean that represents an Apache Geode {@link Repository}. * * @author John Blum * @author Mark Paluch - * @param class type of the Repository. + * @param {@link Class type} of the {@link Repository}. * @see javax.enterprise.context.spi.CreationalContext * @see javax.enterprise.inject.spi.Bean * @see javax.enterprise.inject.spi.BeanManager * @see org.springframework.data.gemfire.mapping.GemfireMappingContext + * @see org.springframework.data.gemfire.repository.GemfireRepository * @see org.springframework.data.gemfire.repository.support.GemfireRepositoryFactory + * @see org.springframework.data.repository.Repository * @see org.springframework.data.repository.cdi.CdiRepositoryBean * @see org.springframework.data.repository.config.CustomRepositoryImplementationDetector * @see org.apache.geode.cache.Region @@ -110,9 +116,8 @@ class GemfireRepositoryBean extends CdiRepositoryBean { } } - throw new IllegalStateException(String.format( - "unable to resolve bean instance of type [%1$s] from bean definition [%2$s]", - targetType, bean)); + throw newIllegalStateException("unable to resolve bean instance of type [%1$s] from bean definition [%2$s]", + targetType, bean); } Iterable> resolveGemfireRegions() { @@ -127,9 +132,10 @@ class GemfireRepositoryBean extends CdiRepositoryBean { } GemfireMappingContext resolveGemfireMappingContext() { - return (gemfireMappingContextBean != null - ? getDependencyInstance(gemfireMappingContextBean, GemfireMappingContext.class) - : DEFAULT_GEMFIRE_MAPPING_CONTEXT); + + return this.gemfireMappingContextBean != null + ? getDependencyInstance(this.gemfireMappingContextBean, GemfireMappingContext.class) + : DEFAULT_GEMFIRE_MAPPING_CONTEXT; } GemfireRepositoryFactory newGemfireRepositoryFactory() { @@ -137,11 +143,12 @@ class GemfireRepositoryBean extends CdiRepositoryBean { } /** - * Creates an instance of the given Repository type as a bean instance in the CDI container. + * Creates an instance of the given {@link Repository} {@link Class type} as a bean instance in the CDI container. * * @param creationalContext operations used by the {@link javax.enterprise.context.spi.Contextual} implementation * during creation of the bean instance. - * @param repositoryType the actual class type of the SD (GemFire) Repository. + * @param repositoryType the actual {@link Class type} of the Spring Data {@link Repository}; + * for example {@link GemfireRepository}. * @see javax.enterprise.context.spi.Contextual#create(javax.enterprise.context.spi.CreationalContext) * @see #newGemfireRepositoryFactory() */ diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryExtension.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryExtension.java index a8fb82a0..77924fba 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryExtension.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/repository/cdi/GemfireRepositoryExtension.java @@ -33,6 +33,8 @@ import javax.enterprise.inject.spi.ProcessBean; import org.apache.geode.cache.Region; import org.springframework.data.gemfire.mapping.GemfireMappingContext; +import org.springframework.data.gemfire.repository.GemfireRepository; +import org.springframework.data.repository.Repository; import org.springframework.data.repository.cdi.CdiRepositoryBean; import org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport; @@ -40,7 +42,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The GemfireRepositoryExtension class... + * {@link CdiRepositoryExtensionSupport} to process declared Apache Geode {@link GemfireRepository} beans. * * @author John Blum * @see org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport @@ -60,8 +62,9 @@ public class GemfireRepositoryExtension extends CdiRepositoryExtensionSupport { } /** - * Implementation of an observer that captures GemFire Region beans defined in the CDI container, storing them - * along with any defined GemfireMappingContexts for later construction of the Repository beans. + * Implementation of an {@literal Observer} that captures Apache Geode {@link Region} beans defined in + * the CDI container, storing them along with any defined {@link GemfireMappingContext} for later construction + * of the {@link GemfireRepository} beans. * * @param class type of the bean instance. * @param processBean annotated type as defined by CDI. @@ -75,7 +78,9 @@ public class GemfireRepositoryExtension extends CdiRepositoryExtensionSupport { for (Type type : bean.getTypes()) { - Type resolvedType = type instanceof ParameterizedType ? ((ParameterizedType) type).getRawType() : type; + Type resolvedType = type instanceof ParameterizedType + ? ((ParameterizedType) type).getRawType() + : type; if (resolvedType instanceof Class) { @@ -99,12 +104,13 @@ public class GemfireRepositoryExtension extends CdiRepositoryExtensionSupport { } /** - * Implementation of an observer that registers beans in the CDI container for the detected Spring Data - * Repositories. + * Implementation of an {@literal Observer} that registers beans in the CDI container for the detected Spring Data + * {@link Repository Repositories}. * - * Repository beans are associated to the appropriate GemfireMappingContexts based on their qualifiers. + * {@link Repository} beans are associated to the appropriate {@link GemfireMappingContext} + * based on their qualifiers. * - * @param beanManager the BeanManager instance. + * @param beanManager reference to the {@link BeanManager} instance. * @see javax.enterprise.inject.spi.AfterBeanDiscovery * @see javax.enterprise.inject.spi.BeanManager * @see javax.enterprise.event.Observes diff --git a/spring-data-geode/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension b/spring-data-geode/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension similarity index 100% rename from spring-data-geode/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension rename to spring-data-geode/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CdiExtensionIntegrationTest.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CdiExtensionIntegrationTest.java index 91aae8fe..1e397fe6 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CdiExtensionIntegrationTest.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CdiExtensionIntegrationTest.java @@ -66,7 +66,14 @@ public class CdiExtensionIntegrationTest { catch (CacheClosedException ignore) {} } - protected void assertIsExpectedPerson(Person actual, Person expected) { + private void assertPerson(Person person, Long id, String name) { + + assertThat(person).isNotNull(); + assertThat(person.getId()).isGreaterThan(id); + assertThat(person.getName()).isEqualTo(name); + } + + private void assertPerson(Person actual, Person expected) { assertThat(actual.getId()).isEqualTo(expected.getId()); assertThat(actual.getFirstname()).isEqualTo(expected.getFirstname()); @@ -78,24 +85,23 @@ public class CdiExtensionIntegrationTest { RepositoryClient repositoryClient = container.select(RepositoryClient.class).get(); + assertThat(repositoryClient).isNotNull(); assertThat(repositoryClient.getPersonRepository()).isNotNull(); Person expectedJonDoe = repositoryClient.newPerson("Jon", "Doe"); - assertThat(expectedJonDoe).isNotNull(); - assertThat(expectedJonDoe.getId()).isGreaterThan(0L); - assertThat(expectedJonDoe.getName()).isEqualTo("Jon Doe"); + assertPerson(expectedJonDoe, 0L, "Jon Doe"); Person savedJonDoe = repositoryClient.save(expectedJonDoe); - assertIsExpectedPerson(savedJonDoe, expectedJonDoe); + assertPerson(savedJonDoe, expectedJonDoe); - Person foundJonDoe = repositoryClient.find(expectedJonDoe.getId()); + Person queriedJonDoe = repositoryClient.find(expectedJonDoe.getId()); - assertIsExpectedPerson(foundJonDoe, expectedJonDoe); + assertPerson(queriedJonDoe, expectedJonDoe); - assertThat(repositoryClient.delete(foundJonDoe)).isTrue(); - assertThat(repositoryClient.find(foundJonDoe.getId())).isNull(); + assertThat(repositoryClient.delete(queriedJonDoe)).isTrue(); + assertThat(repositoryClient.find(queriedJonDoe.getId())).isNull(); } @Test // DATAGEODE-42 diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepository.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepository.java index 9fffc248..80362f37 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepository.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepository.java @@ -14,12 +14,12 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.repository.cdi; +import org.springframework.data.repository.Repository; + /** - * The CustomPersonRepository interface is an Spring Data Repository extension type specifying additional, "custom" - * data access operations on people. + * Spring Data {@link Repository} extension type specifying additional, "custom" data access operations (CRUD) on people. * * @author John Blum * @since 1.8.0 diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepositoryImpl.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepositoryImpl.java index 52d155f7..b97965b8 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepositoryImpl.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/CustomPersonRepositoryImpl.java @@ -14,12 +14,11 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.repository.cdi; /** - * The SamplePersonRepositoryImpl class is an implementation of the {@link CustomPersonRepository} extension interface - * supporting additional data access (CRUD) operations on people. + * Implementation of the {@link CustomPersonRepository} extension interface supporting additional data access operations + * (CRUD) on people. * * @author John Blum * @author Mark Paluch @@ -31,5 +30,4 @@ public class CustomPersonRepositoryImpl implements CustomPersonRepository { public int returnOne() { return 1; } - } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java index 2880c54d..96f492fb 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/RepositoryClient.java @@ -35,13 +35,13 @@ public class RepositoryClient { private static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); - @Inject @SuppressWarnings("all") + @Inject private SamplePersonRepository personRepository; protected SamplePersonRepository getPersonRepository() { - Assert.state(personRepository != null, "PersonRepository was not properly initialized"); - return personRepository; + Assert.state(this.personRepository != null, "PersonRepository was not properly initialized"); + return this.personRepository; } public Person newPerson(String firstName, String lastName) { @@ -58,6 +58,6 @@ public class RepositoryClient { public boolean delete(Person person) { getPersonRepository().delete(person); - return (find(person.getId()) == null); + return find(person.getId()) == null; } } diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java index 4eb604da..1cb9dd6f 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/repository/cdi/SamplePersonRepository.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.repository.cdi; import org.springframework.data.gemfire.mapping.annotation.Region; @@ -22,8 +21,8 @@ import org.springframework.data.gemfire.repository.GemfireRepository; import org.springframework.data.gemfire.repository.sample.Person; /** - * The SamplePersonRepository class is a {@link GemfireRepository} implementation for performing data access (CRUD) - * operations on instances of {@link Person}. + * {@link GemfireRepository} implementation used to perform basic data access operations (CRUD) + * and simple {@literal OQL queries} on instances of {@link Person}. * * @author John Blum * @see org.springframework.data.gemfire.repository.GemfireRepository