use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class PredicatesTest method testOr.
@Test
public void testOr() {
final Predicate or1 = or(equal(ATTRIBUTE, 3), equal(ATTRIBUTE, 4), equal(ATTRIBUTE, 5));
assertPredicateTrue(or1, 4);
assertPredicateFalse(or1, 6);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class FlatteningVisitorTest method visitNotPredicate_whenContainsNegatablePredicate_thenFlattenIt.
@Test
public void visitNotPredicate_whenContainsNegatablePredicate_thenFlattenIt() {
// (not(equals(foo, 1))) --> (notEquals(foo, 1))
Predicate negated = mock(Predicate.class);
NegatablePredicate negatablePredicate = mock(NegatablePredicate.class, withSettings().extraInterfaces(Predicate.class));
when(negatablePredicate.negate()).thenReturn(negated);
NotPredicate outerPredicate = (NotPredicate) not((Predicate) negatablePredicate);
Predicate result = visitor.visit(outerPredicate, mockIndexes);
assertEquals(negated, result);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class FlatteningVisitorTest method visitAndPredicate_whenHasInnerAndPredicate_thenFlattenIt.
@Test
public void visitAndPredicate_whenHasInnerAndPredicate_thenFlattenIt() {
// (a1 = 1 and (a2 = 2 and a3 = 3)) --> (a1 = 1 and a2 = 2 and a3 = 3)
Predicate a1 = equal("a1", 1);
Predicate a2 = equal("a2", 2);
Predicate a3 = equal("a3", 3);
AndPredicate innerAnd = (AndPredicate) and(a2, a3);
AndPredicate outerAnd = (AndPredicate) and(a1, innerAnd);
AndPredicate result = (AndPredicate) visitor.visit(outerAnd, mockIndexes);
Predicate[] inners = result.predicates;
assertEquals(3, inners.length);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class NestedPredicateTest method nestedAttributeQuery_predicates.
@Test
public void nestedAttributeQuery_predicates() throws Exception {
// GIVEN
map.put(1, new Body("body1", new Limb("hand")));
map.put(2, new Body("body2", new Limb("leg")));
// WHEN
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("limb.name").equal("leg");
Collection<Body> values = map.values(predicate);
// THEN
assertEquals(1, values.size());
assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class NestedPredicateTest method singleAttributeQuery_predicates.
@Test
public void singleAttributeQuery_predicates() throws Exception {
// GIVEN
map.put(1, new Body("body1", new Limb("hand")));
map.put(2, new Body("body2", new Limb("leg")));
// WHEN
EntryObject e = new PredicateBuilder().getEntryObject();
Predicate predicate = e.get("name").equal("body1");
Collection<Body> values = map.values(predicate);
// THEN
assertEquals(1, values.size());
assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
}
Aggregations