Search in sources :

Example 6 with TemplatePathsRequest

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

the class TemplatePathsApiTest method testTemplatePathsWithLimit.

@Test
public void testTemplatePathsWithLimit() {
    TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("link").maxTimes(3);
    TemplatePathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(3, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ImmutableList.of(1, 11, 12, 13, 14, 15, 10), ImmutableList.of(1, 16, 17, 10));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("link").maxTimes(3);
    builder.limit(2);
    request = builder.build();
    pathsWithVertices = templatePathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    expected = ImmutableList.of(ImmutableList.of(1, 16, 17, 10), ImmutableList.of(1, 11, 12, 13, 14, 15, 10));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : TemplatePathsRequest(com.baidu.hugegraph.structure.traverser.TemplatePathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Aggregations

PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)6 TemplatePathsRequest (com.baidu.hugegraph.structure.traverser.TemplatePathsRequest)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)1