DATAMONGO-1425 - Polishing.

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

Original pull request: #363.
This commit is contained in:
Mark Paluch
2016-05-09 10:41:24 +02:00
parent 0aff94b5ce
commit b2cd7bbfd6
3 changed files with 36 additions and 0 deletions

View File

@@ -83,8 +83,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);
@@ -1221,4 +1223,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)));
}
}

View File

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

View File

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