use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class PathSerializerTest method testSerializeAndDeserializePathWithVertexAndEdge.
@Test
public void testSerializeAndDeserializePathWithVertexAndEdge() {
Vertex vertex = new Vertex("person");
vertex.id("person:marko");
vertex.property("name", "marko");
vertex.property("age", 29);
vertex.property("city", "Beijing");
Edge edge = new Edge("knows");
edge.id("person:marko>knows>>person:vadas");
edge.sourceId("person:marko");
edge.sourceLabel("person");
edge.targetId("person:vadas");
edge.targetLabel("person");
edge.property("date", "2016-01-10");
edge.property("weight", 0.5);
Path path = new Path();
path.labels(ImmutableList.of());
path.labels(ImmutableList.of());
path.objects(vertex);
path.objects(edge);
String json = serialize(path);
Path pathCopy = deserialize(json, Path.class);
Assert.assertEquals(2, pathCopy.objects().size());
Utils.assertGraphEqual(ImmutableList.of(vertex), ImmutableList.of(edge), path.objects());
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class CommonTraverserApiTest method testCustomizedCrosspoints.
@Test
public void testCustomizedCrosspoints() {
Object lopId = getVertexId("software", "name", "lop");
Object joshId = getVertexId("person", "name", "josh");
Object rippleId = getVertexId("software", "name", "ripple");
CrosspointsRequest.Builder builder = CrosspointsRequest.builder();
builder.sources().ids(lopId, rippleId);
builder.pathPatterns().steps().direction(Direction.IN).labels("created").degree(-1);
builder.withPath(true).withVertex(true).capacity(-1).limit(-1);
CustomizedCrosspoints customizedCrosspoints = customizedCrosspointsAPI.post(builder.build());
List<Object> crosspoints = customizedCrosspoints.crosspoints();
Assert.assertEquals(1, crosspoints.size());
Assert.assertEquals(joshId, crosspoints.get(0));
List<Path> paths = customizedCrosspoints.paths();
Assert.assertEquals(2, paths.size());
List<Object> path1 = ImmutableList.of(rippleId, joshId);
List<Object> path2 = ImmutableList.of(lopId, joshId);
List<List<Object>> expectedPaths = ImmutableList.of(path1, path2);
Assert.assertTrue(expectedPaths.contains(paths.get(0).objects()));
Assert.assertTrue(expectedPaths.contains(paths.get(1).objects()));
Set<?> vertices = customizedCrosspoints.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
List<Object> expectedVids = ImmutableList.of(rippleId, joshId, lopId);
Assert.assertTrue(expectedVids.containsAll(vertices));
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class AllShortestPathsApiTest method testAllShortestPathWithMaxDepth.
@Test
public void testAllShortestPathWithMaxDepth() {
List<Path> paths = allShortestPathsAPI.get(14, 6, Direction.BOTH, null, 4, 5L, 0L, 19L);
Assert.assertEquals(1, paths.size());
Path path = paths.get(0);
Assert.assertEquals(ImmutableList.of(14, 7, 8, 9, 6), path.objects());
paths = allShortestPathsAPI.get(14, 6, Direction.BOTH, null, 3, 5L, 0L, 19L);
Assert.assertEquals(0, paths.size());
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class AllShortestPathsApiTest method testAllShortestPathWithCapacity.
@Test
public void testAllShortestPathWithCapacity() {
List<Path> paths = allShortestPathsAPI.get(1, 6, Direction.BOTH, null, 6, -1L, 0L, -1L);
Assert.assertEquals(4, paths.size());
List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 10, 11, 6), ImmutableList.of(1, 19, 20, 6), ImmutableList.of(1, 21, 22, 6), ImmutableList.of(1, 23, 24, 6));
for (Path path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
Assert.assertThrows(ServerException.class, () -> {
allShortestPathsAPI.get(1, 6, Direction.BOTH, null, 6, 6, 0L, 10L);
}, e -> {
String expect = "Exceed capacity '10' while finding shortest path";
Assert.assertContains(expect, e.getMessage());
});
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class AllShortestPathsApiTest method testAllShortestPathWithLabel.
@Test
public void testAllShortestPathWithLabel() {
List<Path> paths = allShortestPathsAPI.get(1, 6, Direction.BOTH, "link", 6, -1L, 0L, -1L);
Assert.assertEquals(4, paths.size());
List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 10, 11, 6), ImmutableList.of(1, 19, 20, 6), ImmutableList.of(1, 21, 22, 6), ImmutableList.of(1, 23, 24, 6));
for (Path path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
}
Aggregations