Search in sources :

Example 1 with KoutRequest

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

the class KoutApiTest method testKoutPostWithVertex.

@Test
public void testKoutPostWithVertex() {
    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);
    builder.withPath(false);
    builder.withVertex(true);
    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());
    Assert.assertEquals(3, koutResult.vertices().size());
    Set<Object> expectedVids = ImmutableSet.of(vadasId, lopId, joshId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.withPath(false);
    builder.withVertex(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(2, koutResult.vertices().size());
    expectedVids = ImmutableSet.of(peterId, rippleId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.withPath(true);
    builder.withVertex(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(3, koutResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(3, koutResult.paths().size());
    Set<List<Object>> expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
    for (Path path : koutResult.paths()) {
        Assert.assertTrue(expectedPaths.contains(path.objects()));
    }
    Assert.assertEquals(4, koutResult.vertices().size());
    expectedVids = ImmutableSet.of(markoId, vadasId, lopId, joshId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.withPath(true);
    builder.withVertex(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(2, koutResult.paths().size());
    expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
    for (Path path : koutResult.paths()) {
        Assert.assertTrue(expectedPaths.contains(path.objects()));
    }
    Assert.assertEquals(5, koutResult.vertices().size());
    expectedVids = ImmutableSet.of(markoId, peterId, lopId, joshId, rippleId);
    for (Vertex vertex : koutResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 2 with KoutRequest

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

the class KoutApiTest method testKoutPostWithLimit.

@Test
public void testKoutPostWithLimit() {
    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);
    builder.limit(2);
    KoutRequest request = builder.build();
    Kout koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertTrue(expected.containsAll(koutResult.ids()));
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.limit(1);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(1, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertTrue(expected.containsAll(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 3 with KoutRequest

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

the class KoutApiTest method testKoutPostWithNearest.

@Test
public void testKoutPostWithNearest() {
    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);
    builder.nearest(false);
    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);
    builder.nearest(false);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(4, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId, lopId, joshId);
    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 4 with KoutRequest

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

the class KoutApiTest method testKoutPostWithPath.

@Test
public void testKoutPostWithPath() {
    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);
    builder.withPath(true);
    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());
    Assert.assertEquals(3, koutResult.paths().size());
    List<Object> expectedPaths = ImmutableList.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
    for (Path path : koutResult.paths()) {
        Assert.assertTrue(expectedPaths.contains(path.objects()));
    }
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.withPath(true);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(peterId, rippleId);
    Assert.assertEquals(expected, koutResult.ids());
    Assert.assertEquals(2, koutResult.paths().size());
    expectedPaths = ImmutableList.of(ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
    for (Path path : koutResult.paths()) {
        Assert.assertTrue(expectedPaths.contains(path.objects()));
    }
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) Path(com.baidu.hugegraph.structure.graph.Path) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 5 with KoutRequest

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

the class KoutApiTest method testKoutPostWithSingleLabel.

@Test
public void testKoutPostWithSingleLabel() {
    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");
    KoutRequest.Builder builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).labels("created");
    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).labels("created");
    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).labels("knows");
    builder.maxDepth(1);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(2, koutResult.size());
    expected = ImmutableSet.of(vadasId, joshId);
    Assert.assertEquals(expected, koutResult.ids());
    builder = KoutRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).labels("knows");
    builder.maxDepth(2);
    request = builder.build();
    koutResult = koutAPI.post(request);
    Assert.assertEquals(0, koutResult.size());
}
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