Merge pull request #15 from olivergierke/SGF-101

SGF-101 - Fixed repositories deleteAll() for partitioned regions.
This commit is contained in:
David Turanski
2012-07-24 10:19:06 -07:00
6 changed files with 107 additions and 10 deletions

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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<Person, Long> {
public interface PersonRepository extends CrudRepository<Person, Long> {
@Query("SELECT * FROM /Person p WHERE p.firstname = $1")
Collection<Person> findByFirstnameAnnotated(String firstname);

View File

@@ -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 <T> void assertResultsFound(Collection<T> result, T... expected) {
/**
* @see SGF-101
*/
@Test
public void deletesAllEntitiesFromRegions() {
repository.deleteAll();
assertResultsFound(repository.findAll());
}
private <T> void assertResultsFound(Iterable<T> result, T... expected) {
assertThat(result, is(notNullValue()));
assertThat(result.size(), is(expected.length));
assertThat(result, is(Matchers.<T> iterableWithSize(expected.length)));
for (T element : expected) {
assertThat(result.contains(element), is(true));
assertThat(result, hasItem(element));
}
}
}