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.
This commit is contained in:
@@ -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 <T> class type of the Repository.
|
||||
* @param <T> {@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<T> extends CdiRepositoryBean<T> {
|
||||
}
|
||||
}
|
||||
|
||||
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<Region<?, ?>> resolveGemfireRegions() {
|
||||
@@ -127,9 +132,10 @@ class GemfireRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
}
|
||||
|
||||
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<T> extends CdiRepositoryBean<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*/
|
||||
|
||||
@@ -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 <X> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user