Search in sources :

Example 6 with UpdateStrategy

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

the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyOverride.

@Test
public void testEdgeBatchUpdateStrategyOverride() {
    BatchEdgeRequest req = batchEdgeRequest("price", -1, 1, UpdateStrategy.OVERRIDE);
    assertBatchResponse(edgeAPI.update(req), "price", 1);
    // Construct a specialized test case
    graph().addEdges(this.createNEdgesBatch("object", "updates", -1, 2));
    List<String> list = ImmutableList.of("newStr1", "newStr2");
    String vid = "1:a";
    Edge e1 = new Edge("updates");
    e1.sourceLabel("object");
    e1.targetLabel("object");
    e1.sourceId(vid);
    e1.targetId(vid);
    e1.property("name", "tom");
    e1.property("price", 1);
    e1.property("list", list);
    Edge e2 = new Edge("updates");
    e2.sourceLabel("object");
    e2.targetLabel("object");
    e2.sourceId(vid);
    e2.targetId(vid);
    e2.property("name", "tom");
    Map<String, UpdateStrategy> strategies;
    strategies = ImmutableMap.of("price", UpdateStrategy.OVERRIDE, "list", UpdateStrategy.OVERRIDE);
    req = BatchEdgeRequest.createBuilder().edges(ImmutableList.of(e1, e2)).updatingStrategies(strategies).checkVertex(false).createIfNotExist(true).build();
    List<Edge> edges = edgeAPI.update(req);
    Assert.assertEquals(1, edges.size());
    Map<String, Object> expectProperties = ImmutableMap.of("name", "tom", "price", 1, "list", list);
    Assert.assertEquals(edges.get(0).properties(), expectProperties);
}
Also used : BatchEdgeRequest(com.baidu.hugegraph.structure.graph.BatchEdgeRequest) UpdateStrategy(com.baidu.hugegraph.structure.graph.UpdateStrategy) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Aggregations

UpdateStrategy (com.baidu.hugegraph.structure.graph.UpdateStrategy)6 Test (org.junit.Test)4 BatchEdgeRequest (com.baidu.hugegraph.structure.graph.BatchEdgeRequest)3 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)3 Edge (com.baidu.hugegraph.structure.graph.Edge)3 Vertex (com.baidu.hugegraph.structure.graph.Vertex)3