Search in sources :

Example 6 with KoutRequest

use of com.baidu.hugegraph.structure.traverser.KoutRequest in project incubator-hugegraph-toolchain by apache.

the class KoutApiTest method testKoutPostWithProperties.

@Test
public void testKoutPostWithProperties() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object peterId = getVertexId("person", "name", "peter");
    KoutRequest.Builder builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
    builder.maxDepth(1);
    KoutRequest request = builder.build();
    Kout koutResult = koutAPI.post(request);
    Assert.assertEquals(1, koutResult.size());
    Set<Object> expected = ImmutableSet.of(lopId);
    Assert.assertEquals(expected, koutResult.ids());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
    builder.maxDepth(2);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, joshId);
    Assert.assertEquals(expected, koutResult.ids());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
    builder.maxDepth(3);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(1, koutResult.size());
    expected = ImmutableSet.of(rippleId);
    Assert.assertEquals(expected, koutResult.ids());
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 7 with KoutRequest

use of com.baidu.hugegraph.structure.traverser.KoutRequest in project incubator-hugegraph-toolchain by apache.

the class KoutApiTest method testKoutPostWithCountOnly.

@Test
public void testKoutPostWithCountOnly() {
    Object markoId = getVertexId("person", "name", "marko");
    KoutRequest.Builder builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.countOnly(true);
    KoutRequest request = builder.build();
    Kout koutResult = koutAPI.post(request);
    Assert.assertEquals(3, koutResult.size());
    Assert.assertTrue(koutResult.ids().isEmpty());
    Assert.assertTrue(koutResult.paths().isEmpty());
    Assert.assertTrue(koutResult.vertices().isEmpty());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.countOnly(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    Assert.assertTrue(koutResult.ids().isEmpty());
    Assert.assertTrue(koutResult.paths().isEmpty());
    Assert.assertTrue(koutResult.vertices().isEmpty());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.countOnly(true);
    builder.withPath(true);
    KoutRequest.Builder finalBuilder = builder;
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        finalBuilder.build();
    });
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.countOnly(true);
    builder.withVertex(true);
    KoutRequest.Builder finalBuilder1 = builder;
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        finalBuilder1.build();
    });
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 8 with KoutRequest

use of com.baidu.hugegraph.structure.traverser.KoutRequest in project incubator-hugegraph-toolchain by apache.

the class KoutApiTest method testKoutPostWithDirection.

@Test
public void testKoutPostWithDirection() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object vadasId = getVertexId("person", "name", "vadas");
    KoutRequest.Builder builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.OUT);
    builder.maxDepth(1);
    KoutRequest request = builder.build();
    Kout koutResult = koutAPI.post(request);
    Assert.assertEquals(3, koutResult.size());
    Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertEquals(expected, koutResult.ids());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.OUT);
    builder.maxDepth(2);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(1, koutResult.size());
    expected = ImmutableSet.of(rippleId);
    Assert.assertEquals(expected, koutResult.ids());
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 9 with KoutRequest

use of com.baidu.hugegraph.structure.traverser.KoutRequest in project incubator-hugegraph-toolchain by apache.

the class KoutApiTest method testKoutPost.

@Test
public void testKoutPost() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object vadasId = getVertexId("person", "name", "vadas");
    Object peterId = getVertexId("person", "name", "peter");
    KoutRequest.Builder builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    KoutRequest request = builder.build();
    Kout koutResult = koutAPI.post(request);
    Assert.assertEquals(3, koutResult.size());
    Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertEquals(expected, koutResult.ids());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertEquals(expected, koutResult.ids());
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 10 with KoutRequest

use of com.baidu.hugegraph.structure.traverser.KoutRequest in project incubator-hugegraph-toolchain by apache.

the class KoutApiTest method testKoutPostWithMultiLabels.

@Test
public void testKoutPostWithMultiLabels() {
    Object markoId = getVertexId("person", "name", "marko");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object vadasId = getVertexId("person", "name", "vadas");
    Object peterId = getVertexId("person", "name", "peter");
    Object rippleId = getVertexId("software", "name", "ripple");
    KoutRequest.Builder builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).labels("knows").labels("created");
    builder.maxDepth(1);
    KoutRequest request = builder.build();
    Kout koutResult = koutAPI.post(request);
    Assert.assertEquals(3, koutResult.size());
    Set<Object> expected = ImmutableSet.of(vadasId, joshId, lopId);
    Assert.assertEquals(expected, koutResult.ids());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).labels("knows").labels("created");
    builder.maxDepth(2);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertEquals(expected, koutResult.ids());
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Aggregations

BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)10 Kout (com.baidu.hugegraph.structure.traverser.Kout)10 KoutRequest (com.baidu.hugegraph.structure.traverser.KoutRequest)10 Test (org.junit.Test)10 Path (com.baidu.hugegraph.structure.graph.Path)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1