Search in sources :

Example 6 with PathsRequest

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

the class PathsApiTest method testPathsWithLimit.

@Test
public void testPathsWithLimit() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    PathsRequest.Builder builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(3);
    PathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = pathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId), ImmutableList.of(markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH);
    builder.limit(1);
    builder.maxDepth(3);
    request = builder.build();
    pathsWithVertices = pathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    expected = ImmutableList.of(ImmutableList.of(markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PathsRequest(com.baidu.hugegraph.structure.traverser.PathsRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Aggregations

BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)6 PathsRequest (com.baidu.hugegraph.structure.traverser.PathsRequest)6 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)6 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 Test (org.junit.Test)6 Vertex (com.baidu.hugegraph.structure.graph.Vertex)2