use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.
the class MultiNodeShortestPathApiTest method testMultiNodeShortestPathWithMaxDepth.
@Test
public void testMultiNodeShortestPathWithMaxDepth() {
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");
MultiNodeShortestPathRequest.Builder builder = MultiNodeShortestPathRequest.builder();
builder.vertices().ids(markoId, rippleId, joshId, lopId, vadasId, peterId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
MultiNodeShortestPathRequest request = builder.build();
PathsWithVertices pathsWithVertices = multiNodeShortestPathAPI.post(request);
List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
Assert.assertEquals(12, paths.size());
List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, joshId), ImmutableList.of(peterId, lopId), ImmutableList.of(peterId, lopId, joshId), ImmutableList.of(markoId, vadasId), ImmutableList.of(vadasId, markoId, lopId), ImmutableList.of(vadasId, markoId, joshId), ImmutableList.of(lopId, joshId, rippleId), ImmutableList.of(lopId, joshId), ImmutableList.of(rippleId, joshId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(contains(expected, path));
}
builder = MultiNodeShortestPathRequest.builder();
builder.vertices().ids(markoId, rippleId, joshId, lopId, vadasId, peterId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
request = builder.build();
pathsWithVertices = multiNodeShortestPathAPI.post(request);
paths = pathsWithVertices.paths();
Assert.assertEquals(6, paths.size());
expected = ImmutableList.of(ImmutableList.of(markoId, joshId), ImmutableList.of(peterId, lopId), ImmutableList.of(markoId, vadasId), ImmutableList.of(lopId, joshId), ImmutableList.of(rippleId, joshId), ImmutableList.of(markoId, lopId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(contains(expected, path));
}
}
use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.
the class TemplatePathsApiTest method testTemplatePaths.
@Test
public void testTemplatePaths() {
TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
builder.sources().ids(1);
builder.targets().ids(10);
builder.steps().direction(Direction.OUT).maxTimes(3);
builder.steps().direction(Direction.OUT).maxTimes(3);
builder.steps().direction(Direction.IN).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()));
}
}
use of com.baidu.hugegraph.structure.traverser.PathsWithVertices 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()));
}
}
use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.
the class PathsApiTest method testPathsPost.
@Test
public void testPathsPost() {
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()));
}
}
use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.
the class PathsApiTest method testPathsPostWithVertex.
@Test
public void testPathsPostWithVertex() {
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);
builder.withVertex(true);
PathsRequest request = builder.build();
PathsWithVertices pathsWithVertices = pathsAPI.post(request);
List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
Assert.assertEquals(2, paths.size());
List<Object> expectedIds = ImmutableList.of(markoId, lopId, joshId, rippleId);
List<List<Object>> expected = ImmutableList.of(expectedIds, ImmutableList.of(markoId, joshId, rippleId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
Set<Vertex> vertices = pathsWithVertices.vertices();
Assert.assertEquals(4, vertices.size());
for (Vertex v : vertices) {
Assert.assertTrue(expectedIds.contains(v.id()));
}
}
Aggregations