From 5523c12abeb99f72a8d87b937e92060d18dbb01e Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 3 May 2017 11:19:17 -0700 Subject: [PATCH] DATAGEODE-4 - Polish. --- .../data/gemfire/GemfireCacheUtils.java | 7 ------ .../gemfire/repository/GemfireRepository.java | 4 +-- .../data/gemfire/repository/Wrapper.java | 6 +++-- .../DefaultGemfireEntityInformation.java | 5 ++-- .../query/GemfireEntityInformation.java | 5 +++- .../support/GemfireRepositoryFactory.java | 24 ++++++++++-------- .../support/SimpleGemfireRepository.java | 18 ++++++------- .../GemFireDataSourceIntegrationTests.java | 3 ++- .../sample/AnimalRepositoryTest.java | 14 +++++------ ...RegionKeyEntityIdAnimalRepositoryTest.java | 12 +++++---- .../sample/PlantRepositoryTest.java | 10 +++++--- .../SubRegionRepositoryIntegrationTest.java | 12 +++++---- .../GemfireRepositoryFactoryUnitTests.java | 4 +-- ...mpleGemfireRepositoryIntegrationTests.java | 6 ++--- ...epositoryTransactionalIntegrationTest.java | 25 ++++++++++--------- .../SimpleGemfireRepositoryUnitTests.java | 16 +++++++++--- 16 files changed, 92 insertions(+), 79 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java b/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java index 97b79d1d8..f37dfa194 100644 --- a/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java +++ b/src/main/java/org/springframework/data/gemfire/GemfireCacheUtils.java @@ -26,7 +26,6 @@ import org.apache.geode.IncompatibleSystemException; import org.apache.geode.InternalGemFireException; import org.apache.geode.InvalidValueException; -import org.apache.geode.LicenseException; import org.apache.geode.NoSystemException; import org.apache.geode.SystemConnectException; import org.apache.geode.SystemIsRunningException; @@ -194,9 +193,6 @@ public static DataAccessException convertGemfireAccessException(GemFireException if (ex instanceof CopyException) { return new GemfireSystemException(ex); } - if (ex instanceof org.apache.geode.cache.EntryNotFoundInRegion) { - return new DataRetrievalFailureException(ex.getMessage(), ex); - } if (ex instanceof FunctionException) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } @@ -224,9 +220,6 @@ public static DataAccessException convertGemfireAccessException(GemFireException if (ex instanceof LeaseExpiredException) { return new PessimisticLockingFailureException(ex.getMessage(), ex); } - if (ex instanceof LicenseException) { - return new GemfireSystemException(ex); - } if (ex instanceof NoSystemException) { return new GemfireSystemException(ex); } diff --git a/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java b/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java index db6b3257a..f72c9e7cb 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java +++ b/src/main/java/org/springframework/data/gemfire/repository/GemfireRepository.java @@ -13,17 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.data.gemfire.repository; import org.springframework.data.domain.Sort; import org.springframework.data.repository.CrudRepository; /** - * Gemfire-specific extension of the {@link CrudRepository} interface. + * GemFire specific extension of the Spring Data {@link CrudRepository} interface. * * @author Oliver Gierke * @author John Blum - * @see java.io.Serializable * @see org.springframework.data.repository.CrudRepository */ public interface GemfireRepository extends CrudRepository { diff --git a/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java b/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java index 699ab6da9..cf7f0d43e 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java +++ b/src/main/java/org/springframework/data/gemfire/repository/Wrapper.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.data.gemfire.repository; import lombok.NonNull; import lombok.Value; /** - * Simple value object to hold an entity alongside an external key the entity shall be stored under. - * + * Simple value object holding an entity along with the external key in which the entity will be mapped. + * * @author Oliver Gierke */ @Value @@ -28,4 +29,5 @@ public class Wrapper { T entity; @NonNull KEY key; + } diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java b/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java index e40c18ab8..fc6f6864e 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/DefaultGemfireEntityInformation.java @@ -21,8 +21,8 @@ import org.springframework.data.repository.core.support.PersistentEntityInformation; /** - * Implementation of {@link GemfireEntityInformation} to return the region name stored in the backing - * {@link PersistentEntity}. + * Implementation of {@link GemfireEntityInformation} and Spring Data's {@link PersistentEntityInformation} + * that returns the Region name associated with the {@link PersistentEntity}. * * @author Oliver Gierke * @author John Blum @@ -53,5 +53,4 @@ public DefaultGemfireEntityInformation(GemfirePersistentEntity entity) { public String getRegionName() { return entity.getRegionName(); } - } diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java index ecf8c4f60..a069c1e54 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireEntityInformation.java @@ -13,15 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.data.gemfire.repository.query; import org.apache.geode.cache.Region; import org.springframework.data.repository.core.EntityInformation; /** - * {@link EntityInformation} to capture Gemfire specific information. + * {@link EntityInformation} capturing GemFire specific information. * * @author Oliver Gierke + * @see org.springframework.data.repository.core.EntityInformation */ public interface GemfireEntityInformation extends EntityInformation { @@ -31,4 +33,5 @@ public interface GemfireEntityInformation extends EntityInformation> regions, @Override @SuppressWarnings("unchecked") public GemfireEntityInformation getEntityInformation(Class domainClass) { - + GemfirePersistentEntity entity = (GemfirePersistentEntity) mappingContext.getPersistentEntity(domainClass) - .orElseThrow(() -> newIllegalArgumentException("Unable to resolve PersistentEntity for type [%s]", domainClass)); + .orElseThrow(() -> newIllegalArgumentException("Unable to resolve PersistentEntity for type [%s]", + domainClass)); return new DefaultGemfireEntityInformation<>(entity); } @@ -95,8 +97,9 @@ public GemfireEntityInformation getEntityInformation(Class dom */ @Override protected Object getTargetRepository(RepositoryInformation repositoryInformation) { - GemfireEntityInformation entityInformation = getEntityInformation( - repositoryInformation.getDomainType()); + + GemfireEntityInformation entityInformation = + getEntityInformation(repositoryInformation.getDomainType()); GemfireTemplate gemfireTemplate = getTemplate(repositoryInformation); @@ -104,20 +107,21 @@ protected Object getTargetRepository(RepositoryInformation repositoryInformation } GemfireTemplate getTemplate(RepositoryMetadata metadata) { + GemfirePersistentEntity entity = mappingContext.getPersistentEntity(metadata.getDomainType()) .orElseThrow(() -> newIllegalArgumentException("Unable to resolve PersistentEntity for type [%s]", metadata.getDomainType())); String entityRegionName = entity.getRegionName(); String repositoryRegionName = getRepositoryRegionName(metadata.getRepositoryInterface()); - String regionName = (StringUtils.hasText(repositoryRegionName) ? repositoryRegionName : entityRegionName); + String resolvedRegionName = StringUtils.hasText(repositoryRegionName) ? repositoryRegionName : entityRegionName; - Region region = regions.getRegion(regionName); + Region region = regions.getRegion(resolvedRegionName); if (region == null) { - throw new IllegalStateException(String.format("No Region '%1$s' found for domain class %2$s;" + throw newIllegalStateException("No Region [%1$s] was found for domain class [%2$s];" + " Make sure you have configured a GemFire Region of that name in your application context", - regionName, metadata.getDomainType().getName())); + resolvedRegionName, metadata.getDomainType().getName()); } Class regionKeyType = region.getAttributes().getKeyConstraint(); @@ -125,7 +129,7 @@ GemfireTemplate getTemplate(RepositoryMetadata metadata) { if (regionKeyType != null && entity.getIdProperty() != null) { Assert.isTrue(regionKeyType.isAssignableFrom(entityIdType), String.format( - "The Region referenced only supports keys of type %1$s, but the entity to be stored has an id of type %2$s", + "The Region referenced only supports keys of type [%1$s], but the entity to be stored has an id of type [%2$s]", regionKeyType.getName(), entityIdType.getName())); } diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java b/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java index 7db55359d..00202f135 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java @@ -16,7 +16,6 @@ package org.springframework.data.gemfire.repository.support; -import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -54,7 +53,7 @@ * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.Region */ -public class SimpleGemfireRepository implements GemfireRepository { +public class SimpleGemfireRepository implements GemfireRepository { private final EntityInformation entityInformation; @@ -80,7 +79,6 @@ public SimpleGemfireRepository(GemfireTemplate template, EntityInformation U save(U entity) { - ID id = entityInformation.getRequiredId(entity); template.put(id, entity); @@ -94,13 +92,10 @@ public U save(U entity) { */ @Override public Iterable saveAll(Iterable entities) { - Map entitiesToSave = new HashMap<>(); - entities.forEach(entity -> { - entitiesToSave.put(entityInformation.getRequiredId(entity), entity); - }); - + entities.forEach(entity -> entitiesToSave.put(entityInformation.getRequiredId(entity), entity)); + template.putAll(entitiesToSave); return entitiesToSave.values(); @@ -113,7 +108,9 @@ public Iterable saveAll(Iterable entities) { @Override public T save(Wrapper wrapper) { T entity = wrapper.getEntity(); + template.put(wrapper.getKey(), entity); + return entity; } @@ -180,10 +177,9 @@ public Iterable findAll(Sort sort) { */ @Override public Collection findAllById(Iterable ids) { - - List parameters = Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()); + List keys = Streamable.of(ids).stream().collect(StreamUtils.toUnmodifiableList()); - return CollectionUtils.nullSafeMap(template.getAll(parameters)).values().stream() + return CollectionUtils.nullSafeMap(template.getAll(keys)).values().stream() .filter(Objects::nonNull).collect(Collectors.toList()); } diff --git a/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java index 177b853d6..f757c3be3 100644 --- a/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTests.java @@ -10,9 +10,10 @@ * 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.data.gemfire.client; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.List; diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java b/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java index 94be65137..1476bc2d3 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/AnimalRepositoryTest.java @@ -16,7 +16,7 @@ package org.springframework.data.gemfire.repository.sample; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Optional; @@ -27,20 +27,20 @@ import org.springframework.test.context.junit4.SpringRunner; /** - * The AnimalRepositoryTest class is a test suite of test cases testing the functionality behind PR #55 involving - * persisting application domain object/entities to multiple Regions in GemFire's Cache. + * Integration test testing the functionality behind PR #55 involving persisting application domain object/entities + * to multiple Regions in a GemFire Cache. * * @author Stuart Williams * @author John Blum * @see org.junit.Test * @see org.junit.runner.RunWith * @see org.springframework.test.context.ContextConfiguration - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - * @since 1.4.0 + * @see org.springframework.test.context.junit4.SpringRunner * @link https://github.com/spring-projects/spring-data-gemfire/pull/55 + * @since 1.4.0 */ -@ContextConfiguration @RunWith(SpringRunner.class) +@ContextConfiguration @SuppressWarnings("unused") public class AnimalRepositoryTest { @@ -58,7 +58,7 @@ protected static Animal newAnimal(long id, String name) { } @Test - public void testEntityStoredInMultipleRegions() { + public void entityStoredInMultipleRegionsIsSuccessful() { Animal felix = newAnimal(1, "Felix"); Animal leo = newAnimal(2, "Leo"); Animal cerberus = newAnimal(3, "Cerberus"); diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/IncompatibleRegionKeyEntityIdAnimalRepositoryTest.java b/src/test/java/org/springframework/data/gemfire/repository/sample/IncompatibleRegionKeyEntityIdAnimalRepositoryTest.java index 1faf3352e..f3579945f 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/IncompatibleRegionKeyEntityIdAnimalRepositoryTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/IncompatibleRegionKeyEntityIdAnimalRepositoryTest.java @@ -39,15 +39,16 @@ */ public class IncompatibleRegionKeyEntityIdAnimalRepositoryTest { - protected static final String APPLICATION_CONTEXT_CONFIG_LOCATION = String.format("%1$s%2$s%1$s%3$s", + private static final String APPLICATION_CONTEXT_CONFIG_LOCATION = String.format("%1$s%2$s%1$s%3$s", File.separator, AnimalRepositoryTest.class.getPackage().getName().replace('.', File.separatorChar), - "IncompatibleRegionKeyEntityIdAnimalRepositoryTest-context.xml"); + String.format("%s-context.xml", IncompatibleRegionKeyEntityIdAnimalRepositoryTest.class.getSimpleName())); @Test(expected = IllegalArgumentException.class) public void storeAnimalHavingLongIdInRabbitsRegionWithStringKey() { try { - ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext( - APPLICATION_CONTEXT_CONFIG_LOCATION); + ConfigurableApplicationContext applicationContext = + new ClassPathXmlApplicationContext(APPLICATION_CONTEXT_CONFIG_LOCATION); + applicationContext.getBean(RabbitRepository.class); } // NOTE the ClassCastException thrown from GemFire is unexpected; this is not correct and the identifying type @@ -62,8 +63,9 @@ public void storeAnimalHavingLongIdInRabbitsRegionWithStringKey() { catch (BeanCreationException expected) { //expected.printStackTrace(System.err); assertTrue(expected.getCause() instanceof IllegalArgumentException); - assertEquals(String.format("The Region referenced only supports keys of type %1$s, but the entity to be stored has an id of type %2$s", + assertEquals(String.format("The Region referenced only supports keys of type [%1$s], but the entity to be stored has an id of type [%2$s]", String.class.getName(), Long.class.getName()), expected.getCause().getMessage()); + throw (IllegalArgumentException) expected.getCause(); } } diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/PlantRepositoryTest.java b/src/test/java/org/springframework/data/gemfire/repository/sample/PlantRepositoryTest.java index 495e54836..800f0bb9e 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/PlantRepositoryTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/PlantRepositoryTest.java @@ -38,15 +38,16 @@ */ public class PlantRepositoryTest { - protected static final String APPLICATION_CONTEXT_CONFIG_LOCATION = String.format("%1$s%2$s%1$s%3$s", + private static final String APPLICATION_CONTEXT_CONFIG_LOCATION = String.format("%1$s%2$s%1$s%3$s", File.separator, PlantRepositoryTest.class.getPackage().getName().replace('.', File.separatorChar), "PlantRepositoryTest-context.xml"); @Test(expected = IllegalArgumentException.class) public void storePlantHavingStringIdInPlantsRegionWithLongKey() { try { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - APPLICATION_CONTEXT_CONFIG_LOCATION); + ConfigurableApplicationContext context = + new ClassPathXmlApplicationContext(APPLICATION_CONTEXT_CONFIG_LOCATION); + context.getBean(PlantRepository.class); } // NOTE technically, the IllegalArgumentException for incompatible Region 'Key' and Entity ID is thrown @@ -54,8 +55,9 @@ public void storePlantHavingStringIdInPlantsRegionWithLongKey() { catch (BeanCreationException expected) { //expected.printStackTrace(System.err); assertTrue(expected.getCause() instanceof IllegalArgumentException); - assertEquals(String.format("The Region referenced only supports keys of type %1$s, but the entity to be stored has an id of type %2$s", + assertEquals(String.format("The Region referenced only supports keys of type [%1$s], but the entity to be stored has an id of type [%2$s]", Long.class.getName(), String.class.getName()), expected.getCause().getMessage()); + throw (IllegalArgumentException) expected.getCause(); } } diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java index ad057e820..d9dfdee79 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/SubRegionRepositoryIntegrationTest.java @@ -17,7 +17,10 @@ package org.springframework.data.gemfire.repository.sample; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Collections; @@ -34,11 +37,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.gemfire.repository.Wrapper; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** - * The SubRegionRepositoryTest class is a test suite of test cases testing the use of GemFire Repositories on GemFire - * Cache Subregions. + * Integration tests testing the use of GemFire Repositories on GemFire Cache Subregions. * * @author John Blum * @see org.junit.Test @@ -53,8 +55,8 @@ * @link https://jira.springsource.org/browse/SGF-252 * @since 1.4.0 */ +@RunWith(SpringRunner.class) @ContextConfiguration("subregionRepository.xml") -@RunWith(SpringJUnit4ClassRunner.class) @SuppressWarnings("unused") public class SubRegionRepositoryIntegrationTest { diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryUnitTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryUnitTests.java index 41d74a485..9ca493c99 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryUnitTests.java @@ -221,7 +221,7 @@ public void getTemplateThrowsIllegalArgumentExceptionForIncompatibleRegionKeyTyp exception.expect(IllegalArgumentException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(String.format( - "The Region referenced only supports keys of type %1$s, but the entity to be stored has an id of type %2$s", + "The Region referenced only supports keys of type [%1$s], but the entity to be stored has an id of type [%2$s]", String.class.getName(), Long.class.getName())); gemfireRepositoryFactory.getTemplate(mockRepositoryMetadata); @@ -248,7 +248,7 @@ public void getTemplateThrowsIllegalStateExceptionForRegionNotFound() { exception.expect(IllegalStateException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(String.format( - "No Region 'People' found for domain class %s; Make sure you have configured a GemFire Region of that name in your application context", + "No Region [People] was found for domain class [%s]; Make sure you have configured a GemFire Region of that name in your application context", Person.class.getName())); gemfireRepositoryFactory.getTemplate(mockRepositoryMetadata); diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java index 516b5ca22..80ca60080 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryIntegrationTests.java @@ -16,7 +16,7 @@ package org.springframework.data.gemfire.repository.support; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.Collection; @@ -58,7 +58,7 @@ @SuppressWarnings("unused") public class SimpleGemfireRepositoryIntegrationTests { - protected static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning"; + static final String DEFAULT_GEMFIRE_LOG_LEVEL = "warning"; @Autowired private GemfireTemplate template; @@ -177,7 +177,7 @@ public void saveEntities() { @SuppressWarnings("rawtypes") public static class RegionClearListener extends CacheListenerAdapter { - public volatile boolean eventFired; + volatile boolean eventFired; @Override public void afterRegionClear(RegionEvent ev) { diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java index 06ddf31d7..0cc788f06 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryTransactionalIntegrationTest.java @@ -16,7 +16,10 @@ package org.springframework.data.gemfire.repository.support; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.Serializable; import java.util.ArrayList; @@ -36,16 +39,15 @@ import org.springframework.data.gemfire.repository.sample.Customer; import org.springframework.data.repository.core.support.ReflectionEntityInformation; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; /** - * The SimpleGemfireRepositoryTransactionalIntegrationTest class is a test suite of test cases testing - * the SimpleGemfireRepository class and SDC Repository abstraction implementation in the context of - * GemFire "Cache" Transactions. + * Integration tests testing the {@link SimpleGemfireRepository} class and SDC Repository abstraction implementation + * in the context of GemFire "Cache" Transactions. * * @author John Blum * @see org.junit.Test @@ -55,14 +57,14 @@ * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner * @since 1.6.0 */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration @SuppressWarnings("unused") public class SimpleGemfireRepositoryTransactionalIntegrationTest { // TODO add additional test cases for SimpleGemfireRepository (Region operations) in the presence of Transactions!!! - protected static final AtomicLong ID_SEQUENCE = new AtomicLong(0l); + static final AtomicLong ID_SEQUENCE = new AtomicLong(0L); @Autowired private CustomerService customerService; @@ -70,7 +72,7 @@ public class SimpleGemfireRepositoryTransactionalIntegrationTest { @Resource(name = "Customers") private Region customers; - protected static Customer createCustomer(final String firstName, final String lastName) { + static Customer createCustomer(String firstName, String lastName) { Customer customer = new SerializableCustomer(firstName, lastName); customer.setId(ID_SEQUENCE.incrementAndGet()); return customer; @@ -146,7 +148,7 @@ public CustomerService(GemfireTemplate customersTemplate, PlatformTransactionMan transactionTemplate = new TransactionTemplate(transactionManager); } - public void saveAll(final Iterable customers) { + void saveAll(final Iterable customers) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus status) { customerRepository.saveAll(customers); @@ -154,7 +156,7 @@ public void saveAll(final Iterable customers) { }); } - public void removeAllCausingTransactionRollback() { + void removeAllCausingTransactionRollback() { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus status) { removeAll(); @@ -163,7 +165,7 @@ public void removeAllCausingTransactionRollback() { }); } - public void removeAll() { + void removeAll() { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus status) { customerRepository.deleteAll(); @@ -171,5 +173,4 @@ public void removeAll() { }); } } - } diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java index f949daef7..5396f0f9a 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepositoryUnitTests.java @@ -16,11 +16,19 @@ package org.springframework.data.gemfire.repository.support; -import static org.assertj.core.api.Assertions.*; -import static org.hamcrest.Matchers.*; -import static org.mockito.ArgumentMatchers.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays;