use of org.baeldung.web.util.SearchCriteria in project tutorials by eugenp.
the class JPACriteriaQueryIntegrationTest method givenPartialFirst_whenGettingListOfUsers_thenCorrect.
@Test
public void givenPartialFirst_whenGettingListOfUsers_thenCorrect() {
final List<SearchCriteria> params = new ArrayList<SearchCriteria>();
params.add(new SearchCriteria("firstName", ":", "jo"));
final List<User> results = userApi.searchUser(params);
assertThat(userJohn, isIn(results));
assertThat(userTom, not(isIn(results)));
}
use of org.baeldung.web.util.SearchCriteria in project tutorials by eugenp.
the class JPACriteriaQueryIntegrationTest method givenLast_whenGettingListOfUsers_thenCorrect.
@Test
public void givenLast_whenGettingListOfUsers_thenCorrect() {
final List<SearchCriteria> params = new ArrayList<SearchCriteria>();
params.add(new SearchCriteria("lastName", ":", "doe"));
final List<User> results = userApi.searchUser(params);
assertThat(userJohn, isIn(results));
assertThat(userTom, isIn(results));
}
use of org.baeldung.web.util.SearchCriteria in project tutorials by eugenp.
the class MyUserPredicatesBuilder method build.
public BooleanExpression build() {
if (params.size() == 0) {
return null;
}
final List<BooleanExpression> predicates = new ArrayList<>();
MyUserPredicate predicate;
for (final SearchCriteria param : params) {
predicate = new MyUserPredicate(param);
final BooleanExpression exp = predicate.getPredicate();
if (exp != null) {
predicates.add(exp);
}
}
BooleanExpression result = predicates.get(0);
for (int i = 1; i < predicates.size(); i++) {
result = result.and(predicates.get(i));
}
return result;
}
Aggregations