Search in sources :

Example 11 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class TemplatePathsApiTest method testTemplatePathsWithVertex.

@Test
public void testTemplatePathsWithVertex() {
    TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("relateTo").maxTimes(3);
    builder.withVertex(true);
    TemplatePathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    List<Object> expectedIds = ImmutableList.of(1, 16, 17, 10);
    List<List<Object>> expectedPath = ImmutableList.of(expectedIds);
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expectedPath.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) 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)

Example 12 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class CustomizedPathsApiTest method initEdgesWithWeights.

private static void initEdgesWithWeights() {
    SchemaManager schema = schema();
    schema.edgeLabel("knows1").sourceLabel("person").targetLabel("person").properties("date", "weight").nullableKeys("weight").ifNotExist().create();
    schema.edgeLabel("created1").sourceLabel("person").targetLabel("software").properties("date", "weight").nullableKeys("weight").ifNotExist().create();
    Vertex marko = getVertex("person", "name", "marko");
    Vertex vadas = getVertex("person", "name", "vadas");
    Vertex lop = getVertex("software", "name", "lop");
    Vertex josh = getVertex("person", "name", "josh");
    Vertex ripple = getVertex("software", "name", "ripple");
    Vertex peter = getVertex("person", "name", "peter");
    marko.addEdge("knows1", vadas, "date", "2016-01-10", "weight", 0.5);
    marko.addEdge("knows1", josh, "date", "2013-02-20", "weight", 1.0);
    marko.addEdge("created1", lop, "date", "2017-12-10", "weight", 0.4);
    josh.addEdge("created1", lop, "date", "2009-11-11", "weight", 0.4);
    josh.addEdge("created1", ripple, "date", "2017-12-10", "weight", 1.0);
    peter.addEdge("created1", lop, "date", "2017-03-24", "weight", 0.2);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) SchemaManager(com.baidu.hugegraph.driver.SchemaManager)

Example 13 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexApiTest method testCreate.

@Test
public void testCreate() {
    Vertex vertex = new Vertex("person");
    vertex.property("name", "James");
    vertex.property("city", "Beijing");
    vertex.property("age", 19);
    vertex = vertexAPI.create(vertex);
    Assert.assertEquals("person", vertex.label());
    Map<String, Object> props = ImmutableMap.of("name", "James", "city", "Beijing", "age", 19);
    Assert.assertEquals(props, vertex.properties());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 14 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexApiTest method testCreateWithCustomizeNumberId.

@Test
public void testCreateWithCustomizeNumberId() {
    Vertex person = new Vertex("person");
    person.property(T.id, 123456);
    person.property("name", "James");
    person.property("city", "Beijing");
    person.property("age", 19);
    Utils.assertResponseError(400, () -> {
        vertexAPI.create(person);
    });
    schema().vertexLabel("log").useCustomizeNumberId().properties("date").ifNotExist().create();
    Vertex log = new Vertex("log");
    log.id(123456);
    log.property("date", "2018-01-01");
    Vertex vertex = vertexAPI.create(log);
    Assert.assertEquals("log", vertex.label());
    Assert.assertEquals(123456, vertex.id());
    String date = Utils.formatDate("2018-01-01");
    Map<String, Object> props = ImmutableMap.of("date", date);
    Assert.assertEquals(props, vertex.properties());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 15 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class VertexApiTest method testBatchCreate.

@Test
public void testBatchCreate() {
    List<Vertex> vertices = super.create100PersonBatch();
    vertexAPI.create(vertices);
    List<Object> ids = vertexAPI.create(vertices);
    Assert.assertEquals(100, ids.size());
    for (int i = 0; i < 100; i++) {
        Vertex person = vertexAPI.get(ids.get(i));
        Assert.assertEquals("person", person.label());
        Map<String, Object> props = ImmutableMap.of("name", "Person-" + i, "city", "Beijing", "age", 30);
        Assert.assertEquals(props, person.properties());
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Aggregations

Vertex (com.baidu.hugegraph.structure.graph.Vertex)165 Test (org.junit.Test)110 Edge (com.baidu.hugegraph.structure.graph.Edge)33 HugeClient (com.baidu.hugegraph.driver.HugeClient)22 ArrayList (java.util.ArrayList)21 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)18 BaseClientTest (com.baidu.hugegraph.BaseClientTest)17 BeforeClass (org.junit.BeforeClass)17 GraphManager (com.baidu.hugegraph.driver.GraphManager)14 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)13 Path (com.baidu.hugegraph.structure.graph.Path)11 Result (com.baidu.hugegraph.structure.gremlin.Result)10 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)10 List (java.util.List)10 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)9 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 RestResult (com.baidu.hugegraph.rest.RestResult)5 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)5