Search in sources :

Example 1 with PathsRequest

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()));
    }
}
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)

Example 2 with PathsRequest

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()));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) 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)

Example 3 with PathsRequest

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()));
    }
}
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)

Example 4 with PathsRequest

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()));
    }
}
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)

Example 5 with PathsRequest

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()));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) 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

BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)6 PathsRequest (com.baidu.hugegraph.structure.traverser.PathsRequest)6 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)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)2