use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionOr.
@Test
public void testConditionOr() {
Condition c1 = Condition.lt(HugeKeys.ID, 18);
Condition c2 = Condition.gt(HugeKeys.ID, 30);
Condition c3 = c1.or(c2);
Assert.assertEquals(Condition.or(c1, c2), c3);
Assert.assertFalse(c3.test(18));
Assert.assertFalse(c3.test(19));
Assert.assertFalse(c3.test(29));
Assert.assertFalse(c3.test(30));
Assert.assertTrue(c3.test(17));
Assert.assertTrue(c3.test(31));
// null means 0
Assert.assertTrue(c3.test((Object) null));
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionEq.
@Test
public void testConditionEq() {
Condition c1 = Condition.eq(HugeKeys.ID, 123);
Assert.assertTrue(c1.test(123));
Assert.assertTrue(c1.test(123.0));
Assert.assertFalse(c1.test(122));
Assert.assertFalse(c1.test(123.01));
Assert.assertFalse(c1.test(120));
Assert.assertFalse(c1.test(20));
Assert.assertTrue(c1.test("123"));
Assert.assertTrue(c1.test("123.0"));
Assert.assertFalse(c1.test("123.01"));
Assert.assertFalse(c1.test("200"));
// null means 0
Assert.assertFalse(c1.test((Object) null));
Condition c2 = Condition.eq(HugeKeys.ID, 0);
Assert.assertTrue(c2.test((Object) null));
Condition c3 = Condition.eq(HugeKeys.ID, -1);
Assert.assertFalse(c3.test((Object) null));
Condition c4 = Condition.eq(HugeKeys.ID, "123");
Assert.assertFalse(c4.test(123));
Assert.assertFalse(c4.test(new Date(0L)));
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionTextContainsAny.
@Test
public void testConditionTextContainsAny() {
Condition c1 = Condition.textContainsAny(IdGenerator.of("1"), ImmutableSet.of("tom", "cat"));
Assert.assertTrue(c1.test("tom"));
Assert.assertTrue(c1.test("tomcat"));
Assert.assertTrue(c1.test("tomcat2"));
Assert.assertTrue(c1.test("cat"));
Assert.assertFalse(c1.test("text"));
Assert.assertFalse(c1.test("abc"));
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test((Object) null);
}, e -> {
Assert.assertEquals("Can't execute `textcontainsany` " + "on type null, expect String", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test(123L);
}, e -> {
Assert.assertEquals("Can't execute `textcontainsany` " + "on type Long, expect String", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test(ImmutableList.of("1"));
}, e -> {
Assert.assertEquals("Can't execute `textcontainsany` " + "on type SingletonImmutableList, expect String", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition c2 = new SyspropRelation(HugeKeys.ID, RelationType.TEXT_CONTAINS_ANY, "abc");
c2.test("abc");
}, e -> {
Assert.assertEquals("Can't test 'abc'(String) for " + "`textcontainsany`, expect Collection", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionEqWithSysprop.
@Test
public void testConditionEqWithSysprop() {
Condition c1 = Condition.eq(HugeKeys.ID, "123");
Assert.assertEquals("ID == 123", c1.toString());
Assert.assertTrue(c1.isRelation());
Assert.assertTrue(c1.isSysprop());
Assert.assertTrue(c1.isFlattened());
Assert.assertFalse(c1.isLogic());
Assert.assertTrue(c1.test("123"));
Assert.assertFalse(c1.test("1234"));
Assert.assertFalse(c1.test(123));
Assert.assertFalse(c1.test(new Date(123)));
Assert.assertFalse(c1.test((Object) null));
Relation r1 = (Relation) c1;
Assert.assertEquals(HugeKeys.ID, r1.key());
Assert.assertEquals("123", r1.value());
Assert.assertEquals("123", r1.serialValue());
Assert.assertEquals(RelationType.EQ, r1.relation());
Assert.assertTrue(r1.test("123"));
Relation r2 = (Relation) c1.copy();
Assert.assertEquals(r1, r2);
Assert.assertEquals(HugeKeys.ID, r2.key());
Assert.assertEquals("123", r2.value());
Assert.assertEquals("123", r2.serialValue());
Assert.assertEquals(RelationType.EQ, r2.relation());
Assert.assertTrue(r2.test("123"));
r2.serialValue("1234");
Assert.assertEquals("1234", r2.serialValue());
Assert.assertEquals("123", r1.serialValue());
Assert.assertTrue(r2.test("123"));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.eq(HugeKeys.ID, null).test("any");
}, e -> {
Assert.assertEquals("Can't test null value for `==`", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionPrefix.
@Test
public void testConditionPrefix() {
Condition c1 = Condition.prefix(HugeKeys.ID, IdGenerator.of("abc"));
Assert.assertTrue(c1.test(IdGenerator.of("a")));
Assert.assertTrue(c1.test(IdGenerator.of("ab")));
Assert.assertTrue(c1.test(IdGenerator.of("abc")));
Assert.assertFalse(c1.test(IdGenerator.of("abcd")));
Assert.assertFalse(c1.test(IdGenerator.of("b")));
Assert.assertFalse(c1.test(IdGenerator.of("bc")));
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test((Object) null);
}, e -> {
Assert.assertEquals("Can't execute `prefix` on type null, " + "expect Id", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test(123);
}, e -> {
Assert.assertEquals("Can't execute `prefix` on type Integer, " + "expect Id", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition c2 = new SyspropRelation(HugeKeys.ID, RelationType.PREFIX, "abc");
c2.test(IdGenerator.of("ab"));
}, e -> {
Assert.assertEquals("Can't test 'abc'(String) for `prefix`, " + "expect Id", e.getMessage());
});
}
Aggregations