use of org.baeldung.persistence.dao.UserSpecification 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.persistence.dao.UserSpecification 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.persistence.dao.UserSpecification 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.persistence.dao.UserSpecification 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)));
}
use of org.baeldung.persistence.dao.UserSpecification in project tutorials by eugenp.
the class JPASpecificationIntegrationTest method givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect.
@Test
public void givenFirstOrLastNameAndAgeGenericBuilder_whenGettingListOfUsers_thenCorrect() {
GenericSpecificationsBuilder<User> builder = new GenericSpecificationsBuilder<>();
Function<SpecSearchCriteria, Specification<User>> converter = UserSpecification::new;
CriteriaParser parser = new CriteriaParser();
List<User> results = repository.findAll(builder.build(parser.parse("( lastName:doe OR firstName:john ) AND age:22"), converter));
assertThat(results, hasSize(1));
assertThat(userJohn, isIn(results));
assertThat(userTom, not(isIn(results)));
}
Aggregations