Search in sources :

Example 21 with PathsWithVertices

use of com.baidu.hugegraph.structure.traverser.PathsWithVertices 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

PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)21 Test (org.junit.Test)21 ImmutableList (com.google.common.collect.ImmutableList)19 List (java.util.List)19 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)15 CustomizedPathsRequest (com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest)6 PathsRequest (com.baidu.hugegraph.structure.traverser.PathsRequest)6 TemplatePathsRequest (com.baidu.hugegraph.structure.traverser.TemplatePathsRequest)6 Vertex (com.baidu.hugegraph.structure.graph.Vertex)4 ArrayList (java.util.ArrayList)4 MultiNodeShortestPathRequest (com.baidu.hugegraph.structure.traverser.MultiNodeShortestPathRequest)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1