use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionLte.
@Test
public void testConditionLte() {
Condition c1 = Condition.lte(HugeKeys.ID, 123);
Assert.assertTrue(c1.test(123));
Assert.assertTrue(c1.test(123.0));
Assert.assertTrue(c1.test(120));
Assert.assertTrue(c1.test(20));
Assert.assertTrue(c1.test("123"));
Assert.assertTrue(c1.test("123.0"));
Assert.assertFalse(c1.test("123.01"));
Assert.assertTrue(c1.test("20"));
// null means 0
Assert.assertTrue(c1.test((Object) null));
Condition c2 = Condition.lte(HugeKeys.ID, 0);
Assert.assertTrue(c2.test((Object) null));
Condition c3 = Condition.lte(HugeKeys.ID, -1);
Assert.assertFalse(c3.test((Object) null));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.lte(HugeKeys.ID, "123").test(123);
}, e -> {
String err = "Can't compare between 123(Integer) and 123(String)";
Assert.assertEquals(err, e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.lte(HugeKeys.ID, "123").test(new Date(0L));
}, e -> {
String err = String.format("Can't compare between %s(Date) " + "and 123(String)", new Date(0L));
Assert.assertEquals(err, e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionLt.
@Test
public void testConditionLt() {
Condition c1 = Condition.lt(HugeKeys.ID, 123);
Assert.assertTrue(c1.test(122));
Assert.assertTrue(c1.test(120));
Assert.assertTrue(c1.test(20));
Assert.assertFalse(c1.test(124));
Assert.assertFalse(c1.test(200));
Assert.assertFalse(c1.test(123));
Assert.assertFalse(c1.test(123.0));
Assert.assertFalse(c1.test("123"));
Assert.assertFalse(c1.test("123.0"));
Assert.assertFalse(c1.test("123.01"));
Assert.assertFalse(c1.test("200"));
Assert.assertTrue(c1.test("122.99"));
// null means 0
Assert.assertTrue(c1.test((Object) null));
Condition c2 = Condition.lt(HugeKeys.ID, 0.1);
Assert.assertTrue(c2.test((Object) null));
Condition c3 = Condition.lt(HugeKeys.ID, 0);
Assert.assertFalse(c3.test((Object) null));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.lt(HugeKeys.ID, "123").test(123);
}, e -> {
String err = "Can't compare between 123(Integer) and 123(String)";
Assert.assertEquals(err, e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.lt(HugeKeys.ID, "123").test(new Date(0L));
}, e -> {
String err = String.format("Can't compare between %s(Date) " + "and 123(String)", new Date(0L));
Assert.assertEquals(err, e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionGt.
@Test
public void testConditionGt() {
Condition c1 = Condition.gt(HugeKeys.ID, 123);
Assert.assertTrue(c1.test(124));
Assert.assertTrue(c1.test(200));
Assert.assertFalse(c1.test(123));
Assert.assertFalse(c1.test(123.0));
Assert.assertFalse(c1.test(120));
Assert.assertFalse(c1.test(20));
Assert.assertFalse(c1.test("123"));
Assert.assertFalse(c1.test("123.0"));
Assert.assertTrue(c1.test("123.01"));
Assert.assertTrue(c1.test("200"));
// null means 0
Assert.assertFalse(c1.test((Object) null));
Condition c2 = Condition.gt(HugeKeys.ID, 0);
Assert.assertFalse(c2.test((Object) null));
Condition c3 = Condition.gt(HugeKeys.ID, -1);
Assert.assertTrue(c3.test((Object) null));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.gt(HugeKeys.ID, "123").test(123);
}, e -> {
String err = "Can't compare between 123(Integer) and 123(String)";
Assert.assertEquals(err, e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.gt(HugeKeys.ID, "123").test(new Date(0L));
}, e -> {
String err = String.format("Can't compare between %s(Date) " + "and 123(String)", new Date(0L));
Assert.assertEquals(err, e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionEqWithUserprop.
@Test
public void testConditionEqWithUserprop() {
Condition c1 = Condition.eq(IdGenerator.of("1"), "123");
Assert.assertEquals("1 == 123", c1.toString());
Assert.assertTrue(c1.isRelation());
Assert.assertFalse(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(IdGenerator.of("1"), 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(IdGenerator.of("1"), 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(IdGenerator.of("1"), 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 testConditionTextContains.
@Test
public void testConditionTextContains() {
Condition c1 = Condition.textContains(IdGenerator.of("1"), "tom");
Assert.assertTrue(c1.test("tom"));
Assert.assertTrue(c1.test("tomcat"));
Assert.assertFalse(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 `textcontains` on type null, " + "expect String", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
c1.test(123L);
}, e -> {
Assert.assertEquals("Can't execute `textcontains` on type Long, " + "expect String", e.getMessage());
});
}
Aggregations