Browse Source

DATAMONGO-1425 - Polishing.

Add NotContaining to documentation. Add integration test for Containing/NotContaining on collection properties.

Original pull request: #363.
pull/410/head
Mark Paluch 10 years ago
parent
commit
8b31ba1836
  1. 24
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java
  2. 4
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java
  3. 8
      src/main/asciidoc/reference/mongo-repositories.adoc

24
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

@ -86,8 +86,10 @@ public abstract class AbstractPersonRepositoryIntegrationTests { @@ -86,8 +86,10 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave = new Person("Dave", "Matthews", 42);
oliver = new Person("Oliver August", "Matthews", 4);
carter = new Person("Carter", "Beauford", 49);
carter.setSkills(Arrays.asList("Drums", "percussion", "vocals"));
Thread.sleep(10);
boyd = new Person("Boyd", "Tinsley", 45);
boyd.setSkills(Arrays.asList("Violin", "Electric Violin", "Viola", "Mandolin", "Vocals", "Guitar"));
stefan = new Person("Stefan", "Lessard", 34);
leroi = new Person("Leroi", "Moore", 41);
@ -1272,4 +1274,26 @@ public abstract class AbstractPersonRepositoryIntegrationTests { @@ -1272,4 +1274,26 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
assertThat(result, not(hasItem(boyd)));
}
/**
* @see DATAMONGO-1425
*/
@Test
public void findBySkillsContains() throws Exception {
List<Person> result = repository.findBySkillsContains(Arrays.asList("Drums"));
assertThat(result.size(), is(1));
assertThat(result, hasItem(carter));
}
/**
* @see DATAMONGO-1425
*/
@Test
public void findBySkillsNotContains() throws Exception {
List<Person> result = repository.findBySkillsNotContains(Arrays.asList("Drums"));
assertThat(result.size(), is((int) (repository.count() - 1)));
assertThat(result, not(hasItem(carter)));
}
}

4
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java

@ -93,6 +93,10 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query @@ -93,6 +93,10 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
List<Person> findByFirstnameLikeOrderByLastnameAsc(String firstname, Sort sort);
List<Person> findBySkillsContains(List<String> skills);
List<Person> findBySkillsNotContains(List<String> skills);
@Query("{'age' : { '$lt' : ?0 } }")
List<Person> findByAgeLessThan(int age, Sort sort);

8
src/main/asciidoc/reference/mongo-repositories.adoc

@ -212,10 +212,18 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete @@ -212,10 +212,18 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
| `findByFirstnameContaining(String name)`
| `{"firstname" : name} (name as regex)`
| `NotContaining` on String
| `findByFirstnameNotContaining(String name)`
| `{"firstname" : { "$not" : name}} (name as regex)`
| `Containing` on Collection
| `findByAddressesContaining(Address address)`
| `{"addresses" : { "$in" : address}}`
| `NotContaining` on Collection
| `findByAddressesNotContaining(Address address)`
| `{"addresses" : { "$not" : { "$in" : address}}}`
| `Regex`
| `findByFirstnameRegex(String firstname)`
| `{"firstname" : {"$regex" : firstname }}`

Loading…
Cancel
Save