Search in sources :

Example 61 with Vertex

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

the class BatchElementRequestTest method testVertexRequestBuildOK.

@Test
public void testVertexRequestBuildOK() {
    List<Vertex> vertices = ImmutableList.of(createVertex());
    Map<String, UpdateStrategy> strategies = ImmutableMap.of("set", INTERSECTION);
    BatchVertexRequest req;
    req = new BatchVertexRequest.Builder().vertices(vertices).updatingStrategies(strategies).createIfNotExist(true).build();
    Assert.assertNotNull(req);
    Object list = Whitebox.getInternalState(req, "vertices");
    Assert.assertEquals(vertices, list);
    Object map = Whitebox.getInternalState(req, "updateStrategies");
    Assert.assertEquals(strategies, map);
    Object created = Whitebox.getInternalState(req, "createIfNotExist");
    Assert.assertEquals(true, created);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BatchVertexRequest(com.baidu.hugegraph.structure.graph.BatchVertexRequest) UpdateStrategy(com.baidu.hugegraph.structure.graph.UpdateStrategy) Test(org.junit.Test)

Example 62 with Vertex

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

the class VertexSerializerTest method testSerializeAndDeserializeVertex.

@Test
public void testSerializeAndDeserializeVertex() {
    Vertex vertex = new Vertex("person");
    vertex.id("person:marko");
    vertex.property("name", "marko");
    vertex.property("age", 29);
    vertex.property("city", "Beijing");
    String json = serialize(vertex);
    Vertex vertexCopy = deserialize(json, Vertex.class);
    Assert.assertEquals("person:marko", vertexCopy.id());
    Assert.assertEquals("person", vertexCopy.label());
    Assert.assertEquals("vertex", vertexCopy.type());
    Map<String, Object> props = ImmutableMap.of("name", "marko", "age", 29, "city", "Beijing");
    Assert.assertEquals(props, vertexCopy.properties());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 63 with Vertex

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

the class VertexSerializerTest method testSerializeAndDeserializeVertexWithSetProp.

@Test
public void testSerializeAndDeserializeVertexWithSetProp() {
    Vertex vertex = new Vertex("person");
    vertex.id("person:marko");
    vertex.property("name", "marko");
    vertex.property("age", 29);
    vertex.property("city", ImmutableSet.of("Hefei", "Wuhan", "Wuhan"));
    String json = serialize(vertex);
    Vertex vertexCopy = deserialize(json, Vertex.class);
    Assert.assertEquals("person:marko", vertexCopy.id());
    Assert.assertEquals("person", vertexCopy.label());
    Assert.assertEquals("vertex", vertexCopy.type());
    // TODO: Set properties should deserialize to Set instead of List
    Map<String, Object> props = ImmutableMap.of("name", "marko", "age", 29, "city", ImmutableList.of("Hefei", "Wuhan"));
    Assert.assertEquals(props, vertexCopy.properties());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test)

Example 64 with Vertex

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

the class BatchUpdateElementApiTest method testVertexBatchUpdateStrategyAppend.

@Test
public void testVertexBatchUpdateStrategyAppend() {
    BatchVertexRequest req = batchVertexRequest("list", "old", "old", UpdateStrategy.APPEND);
    List<Vertex> vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "list", "old", "old");
    req = batchVertexRequest("list", "old", "new", UpdateStrategy.APPEND);
    vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "list", "old", "new");
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BatchVertexRequest(com.baidu.hugegraph.structure.graph.BatchVertexRequest) Test(org.junit.Test)

Example 65 with Vertex

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

the class BatchUpdateElementApiTest method createNVertexBatch.

private List<Vertex> createNVertexBatch(String vertexLabel, Object symbol, int num) {
    List<Vertex> vertices = new ArrayList<>(num);
    for (int i = 1; i <= num; i++) {
        Vertex vertex = new Vertex(vertexLabel);
        vertex.property("name", String.valueOf(i));
        if (symbol instanceof Number) {
            vertex.property("price", (int) symbol * i);
        }
        vertex.property("date", new Date(System.currentTimeMillis() + i));
        vertex.property("set", ImmutableSet.of(String.valueOf(symbol) + i));
        vertex.property("list", ImmutableList.of(String.valueOf(symbol) + i));
        vertices.add(vertex);
    }
    return vertices;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) Date(java.util.Date)

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