use of org.baeldung.web.util.SpecSearchCriteria in project tutorials by eugenp.
the class JPASpecificationIntegrationTest method givenFirstOrLastName_whenGettingListOfUsers_thenCorrect.
@Test
public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() {
UserSpecificationsBuilder builder = new UserSpecificationsBuilder();
SpecSearchCriteria spec = new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john");
SpecSearchCriteria spec1 = new SpecSearchCriteria("'", "lastName", SearchOperation.EQUALITY, "doe");
List<User> results = repository.findAll(builder.with(spec).with(spec1).build());
assertThat(results, hasSize(2));
assertThat(userJohn, isIn(results));
assertThat(userTom, isIn(results));
}
use of org.baeldung.web.util.SpecSearchCriteria in project tutorials by eugenp.
the class JPASpecificationIntegrationTest method givenAgeRange_whenGettingListOfUsers_thenCorrect.
@Test
public void givenAgeRange_whenGettingListOfUsers_thenCorrect() {
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "20"));
final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.LESS_THAN, "25"));
final List<User> results = repository.findAll(Specifications.where(spec).and(spec1));
assertThat(userJohn, isIn(results));
assertThat(userTom, not(isIn(results)));
}
use of org.baeldung.web.util.SpecSearchCriteria in project tutorials by eugenp.
the class JPASpecificationIntegrationTest method givenFirstAndLastName_whenGettingListOfUsers_thenCorrect.
@Test
public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() {
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john"));
final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe"));
final List<User> results = repository.findAll(Specifications.where(spec).and(spec1));
assertThat(userJohn, isIn(results));
assertThat(userTom, not(isIn(results)));
}
use of org.baeldung.web.util.SpecSearchCriteria in project tutorials by eugenp.
the class JPASpecificationIntegrationTest method givenFirstNameInverse_whenGettingListOfUsers_thenCorrect.
@Test
public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() {
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john"));
final List<User> results = repository.findAll(Specifications.where(spec));
assertThat(userTom, isIn(results));
assertThat(userJohn, not(isIn(results)));
}
use of org.baeldung.web.util.SpecSearchCriteria in project tutorials by eugenp.
the class JPASpecificationIntegrationTest method givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect.
@Test
public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() {
final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.CONTAINS, "oh"));
final List<User> results = repository.findAll(spec);
assertThat(userJohn, isIn(results));
assertThat(userTom, not(isIn(results)));
}
Aggregations