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