use of org.springframework.data.relational.core.query.Criteria in project spring-data-jdbc by spring-projects.
the class CriteriaUnitTests method shouldBuildGtCriteria.
// DATAJDBC-513
@Test
void shouldBuildGtCriteria() {
Criteria criteria = where("foo").greaterThan(1);
assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.GT);
assertThat(criteria.getValue()).isEqualTo(1);
}
use of org.springframework.data.relational.core.query.Criteria in project spring-data-jdbc by spring-projects.
the class CriteriaUnitTests method fromCriteria.
// DATAJDBC-513
@Test
void fromCriteria() {
Criteria nested1 = where("foo").isNotNull();
Criteria nested2 = where("foo").isNull();
CriteriaDefinition criteria = Criteria.from(nested1, nested2);
assertThat(criteria.isGroup()).isTrue();
assertThat(criteria.getGroup()).containsExactly(nested1, nested2);
assertThat(criteria.getPrevious()).isEqualTo(Criteria.empty());
assertThat(criteria).hasToString("(foo IS NOT NULL AND foo IS NULL)");
}
use of org.springframework.data.relational.core.query.Criteria in project spring-data-jdbc by spring-projects.
the class CriteriaUnitTests method shouldBuildNotInCriteria.
// DATAJDBC-513
@Test
void shouldBuildNotInCriteria() {
Criteria criteria = where("foo").notIn("bar", "baz");
assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.NOT_IN);
assertThat(criteria.getValue()).isEqualTo(Arrays.asList("bar", "baz"));
}
use of org.springframework.data.relational.core.query.Criteria in project spring-data-jdbc by spring-projects.
the class CriteriaUnitTests method andGroupedCriteria.
// DATAJDBC-513
@Test
void andGroupedCriteria() {
Criteria grouped = where("foo").is("bar").and(where("foo").is("baz").or("bar").isNotNull());
Criteria criteria = grouped;
assertThat(criteria.isGroup()).isTrue();
assertThat(criteria.getGroup()).hasSize(1);
assertThat(criteria.getGroup().get(0).getColumn()).isEqualTo(SqlIdentifier.unquoted("bar"));
assertThat(criteria.getCombinator()).isEqualTo(Criteria.Combinator.AND);
criteria = criteria.getPrevious();
assertThat(criteria).isNotNull();
assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.EQ);
assertThat(criteria.getValue()).isEqualTo("bar");
assertThat(grouped).hasToString("foo = 'bar' AND (foo = 'baz' OR bar IS NOT NULL)");
}
use of org.springframework.data.relational.core.query.Criteria in project spring-data-jdbc by spring-projects.
the class CriteriaUnitTests method isEmpty.
// DATAJDBC-513
@Test
void isEmpty() {
assertSoftly(softly -> {
Criteria empty = empty();
Criteria notEmpty = where("foo").is("bar");
assertThat(empty.isEmpty()).isTrue();
assertThat(notEmpty.isEmpty()).isFalse();
assertThat(Criteria.from(notEmpty).isEmpty()).isFalse();
assertThat(Criteria.from(notEmpty, notEmpty).isEmpty()).isFalse();
assertThat(Criteria.from(empty).isEmpty()).isTrue();
assertThat(Criteria.from(empty, empty).isEmpty()).isTrue();
assertThat(Criteria.from(empty, notEmpty).isEmpty()).isFalse();
assertThat(Criteria.from(notEmpty, empty).isEmpty()).isFalse();
});
}
Aggregations