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 d958d7b2..e7c7fc2a 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 @@ -183,7 +183,11 @@ public class SimpleGemfireRepository implements Gemf @Override @SuppressWarnings("rawtypes") public Void doInGemfire(Region region) { - region.clear(); + + for (Object key : region.keySet()) { + region.remove(key); + } + return null; } }); diff --git a/src/test/java/org/springframework/data/gemfire/repository/config/PartitionedRegionNamespaceRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/config/PartitionedRegionNamespaceRepositoryIntegrationTests.java new file mode 100644 index 00000000..6c969ede --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/repository/config/PartitionedRegionNamespaceRepositoryIntegrationTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012 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.data.gemfire.repository.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.gemfire.mapping.Regions; +import org.springframework.data.gemfire.repository.sample.PersonRepository; +import org.springframework.data.gemfire.repository.support.AbstractGemfireRepositoryFactoryIntegrationTests; +import org.springframework.test.context.ContextConfiguration; + +/** + * Integration tests for namespace usage. + * + * @author Oliver Gierke + */ +@ContextConfiguration("partitioned-region-repo-context.xml") +public class PartitionedRegionNamespaceRepositoryIntegrationTests extends + AbstractGemfireRepositoryFactoryIntegrationTests { + + @Autowired + PersonRepository repository; + + @Override + protected PersonRepository getRepository(Regions regions) { + return repository; + } +} diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/Person.java b/src/test/java/org/springframework/data/gemfire/repository/sample/Person.java index 372b9ee5..9f05ec89 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/Person.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/Person.java @@ -21,7 +21,6 @@ import org.springframework.data.annotation.Id; import org.springframework.data.gemfire.mapping.Region; /** - * * @author Oliver Gierke */ @Region("simple") @@ -54,4 +53,33 @@ public class Person implements Serializable { public String getLastname() { return lastname; } + + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (!(obj instanceof Person)) { + return false; + } + + Person that = (Person) obj; + + return this.id == null ? false : this.id.equals(that.id); + } + + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return this.id == null ? 0 : this.id.hashCode(); + } } diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java b/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java index 7fe55fd2..d7ccd565 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java @@ -18,14 +18,14 @@ package org.springframework.data.gemfire.repository.sample; import java.util.Collection; import org.springframework.data.gemfire.repository.Query; -import org.springframework.data.repository.Repository; +import org.springframework.data.repository.CrudRepository; /** - * + * Sample repository interface managing {@link Person}s. * * @author Oliver Gierke */ -public interface PersonRepository extends Repository { +public interface PersonRepository extends CrudRepository { @Query("SELECT * FROM /Person p WHERE p.firstname = $1") Collection findByFirstnameAnnotated(String firstname); diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java index c53ab4f4..4fba9928 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/AbstractGemfireRepositoryFactoryIntegrationTests.java @@ -15,13 +15,13 @@ */ package org.springframework.data.gemfire.repository.support; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import java.util.Arrays; -import java.util.Collection; import java.util.List; +import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -108,13 +108,24 @@ public abstract class AbstractGemfireRepositoryFactoryIntegrationTests { assertResultsFound(repository.findByFirstnameOrLastname("Carter", "Matthews"), carter, dave); } - private void assertResultsFound(Collection result, T... expected) { + /** + * @see SGF-101 + */ + @Test + public void deletesAllEntitiesFromRegions() { + + repository.deleteAll(); + + assertResultsFound(repository.findAll()); + } + + private void assertResultsFound(Iterable result, T... expected) { assertThat(result, is(notNullValue())); - assertThat(result.size(), is(expected.length)); + assertThat(result, is(Matchers. iterableWithSize(expected.length))); for (T element : expected) { - assertThat(result.contains(element), is(true)); + assertThat(result, hasItem(element)); } } } diff --git a/src/test/resources/org/springframework/data/gemfire/repository/config/partitioned-region-repo-context.xml b/src/test/resources/org/springframework/data/gemfire/repository/config/partitioned-region-repo-context.xml new file mode 100644 index 00000000..a73d3a42 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/repository/config/partitioned-region-repo-context.xml @@ -0,0 +1,14 @@ + + + + + + + + +