use of com.baidu.hugegraph.structure.traverser.PathsRequest in project incubator-hugegraph-toolchain by apache.
the class PathsApiTest method testPathsPostWithLabel.
@Test
public void testPathsPostWithLabel() {
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).labels("created");
builder.maxDepth(3);
request = builder.build();
pathsWithVertices = pathsAPI.post(request);
paths = pathsWithVertices.paths();
Assert.assertEquals(1, paths.size());
expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
}
use of com.baidu.hugegraph.structure.traverser.PathsRequest in project incubator-hugegraph-toolchain by apache.
the class PathsApiTest method testPathsPostWithNearest.
@Test
public void testPathsPostWithNearest() {
Object markoId = getVertexId("person", "name", "marko");
Object rippleId = getVertexId("software", "name", "ripple");
Object joshId = getVertexId("person", "name", "josh");
Object lopId = getVertexId("software", "name", "lop");
Vertex tom = graph().addVertex(T.label, "person", "name", "Tom", "age", 29, "city", "Shanghai");
Vertex jim = graph().addVertex(T.label, "person", "name", "Jim", "age", 29, "city", "Shanghai");
Vertex java = graph().addVertex(T.label, "software", "name", "java", "lang", "java", "price", 199);
Object tomId = tom.id();
Object jimId = jim.id();
Object javaId = java.id();
graph().addEdge(tomId, "created", rippleId, "date", "2016-01-10", "city", "Beijing");
graph().addEdge(tomId, "created", javaId, "date", "2017-01-10", "city", "Hongkong");
graph().addEdge(jimId, "created", javaId, "date", "2017-01-10", "city", "Hongkong");
PathsRequest.Builder builder = PathsRequest.builder();
builder.sources().ids(markoId);
builder.targets().ids(jimId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(6);
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, tomId, javaId, jimId), ImmutableList.of(markoId, joshId, rippleId, tomId, javaId, jimId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
builder = PathsRequest.builder();
builder.sources().ids(markoId);
builder.targets().ids(jimId);
builder.step().direction(Direction.BOTH);
builder.nearest(true);
builder.maxDepth(6);
request = builder.build();
pathsWithVertices = pathsAPI.post(request);
paths = pathsWithVertices.paths();
Assert.assertEquals(1, paths.size());
expected = ImmutableList.of(ImmutableList.of(markoId, joshId, rippleId, tomId, javaId, jimId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
}
use of com.baidu.hugegraph.structure.traverser.PathsRequest in project incubator-hugegraph-toolchain by apache.
the class PathsApiTest method testPathsPostWithProperties.
@Test
public void testPathsPostWithProperties() {
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).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
builder.maxDepth(3);
request = builder.build();
pathsWithVertices = pathsAPI.post(request);
paths = pathsWithVertices.paths();
Assert.assertEquals(1, paths.size());
expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
}
use of com.baidu.hugegraph.structure.traverser.PathsRequest 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.PathsRequest 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