Search in sources :

Example 1 with SyspropRelation

use of com.baidu.hugegraph.backend.query.Condition.SyspropRelation in project incubator-hugegraph by apache.

the class ConditionTest method testConditionNotIn.

@Test
public void testConditionNotIn() {
    Condition c1 = Condition.nin(HugeKeys.ID, ImmutableList.of(1, 2, "3"));
    Assert.assertFalse(c1.test(1));
    Assert.assertFalse(c1.test(2));
    Assert.assertFalse(c1.test("3"));
    Assert.assertTrue(c1.test(4));
    Assert.assertTrue(c1.test(1.0));
    Assert.assertTrue(c1.test(2.0));
    Assert.assertTrue(c1.test(3));
    Assert.assertTrue(c1.test(123));
    Assert.assertTrue(c1.test(1.01));
    Assert.assertTrue(c1.test("123"));
    Assert.assertTrue(c1.test("123.0"));
    Assert.assertTrue(c1.test("1"));
    Assert.assertTrue(c1.test("2"));
    Assert.assertTrue(c1.test("3.0"));
    Assert.assertTrue(c1.test("1.0"));
    Assert.assertTrue(c1.test((Object) null));
    Assert.assertTrue(c1.test(ImmutableList.of(4)));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.nin(HugeKeys.ID, null).test("1");
    }, e -> {
        Assert.assertEquals("Can't test null value for `notin`", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition c2 = new SyspropRelation(HugeKeys.ID, RelationType.NOT_IN, "single-value");
        c2.test("singlevalue");
    }, e -> {
        Assert.assertEquals("Can't test 'single-value'(String) " + "for `notin`, expect Collection", e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 2 with SyspropRelation

use of com.baidu.hugegraph.backend.query.Condition.SyspropRelation 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());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 3 with SyspropRelation

use of com.baidu.hugegraph.backend.query.Condition.SyspropRelation 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());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 4 with SyspropRelation

use of com.baidu.hugegraph.backend.query.Condition.SyspropRelation in project incubator-hugegraph by apache.

the class ConditionTest method testConditionIn.

@Test
public void testConditionIn() {
    Condition c1 = Condition.in(HugeKeys.ID, ImmutableList.of(1, 2, "3"));
    Assert.assertTrue(c1.test(1));
    Assert.assertTrue(c1.test(2));
    Assert.assertTrue(c1.test("3"));
    Assert.assertFalse(c1.test(4));
    Assert.assertFalse(c1.test(1.0));
    Assert.assertFalse(c1.test(2.0));
    Assert.assertFalse(c1.test(3));
    Assert.assertFalse(c1.test(123));
    Assert.assertFalse(c1.test(1.01));
    Assert.assertFalse(c1.test("123"));
    Assert.assertFalse(c1.test("123.0"));
    Assert.assertFalse(c1.test("1"));
    Assert.assertFalse(c1.test("2"));
    Assert.assertFalse(c1.test("3.0"));
    Assert.assertFalse(c1.test("1.0"));
    Assert.assertFalse(c1.test((Object) null));
    Assert.assertFalse(c1.test(ImmutableList.of(1, 2)));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.in(HugeKeys.ID, null).test("1");
    }, e -> {
        Assert.assertEquals("Can't test null value for `in`", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition c2 = new SyspropRelation(HugeKeys.ID, RelationType.IN, "single-value");
        c2.test("singlevalue");
    }, e -> {
        Assert.assertEquals("Can't test 'single-value'(String) for `in`, " + "expect Collection", e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

Condition (com.baidu.hugegraph.backend.query.Condition)4 SyspropRelation (com.baidu.hugegraph.backend.query.Condition.SyspropRelation)4 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)4 Test (org.junit.Test)4