use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdges.
@Test
public void testReadEdges() {
String json = "{\"edges\": [" + "{" + "\"id\": \"person:peter>created>>software:lop\"," + "\"label\": \"created\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"software\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"software:lop\"," + "\"outV\": \"person:peter\"," + "\"properties\": {" + "\"date\": 1495036800000," + "\"city\": \"Hongkong\"" + "}" + "}," + "{" + "\"id\": \"person:peter>knows>>person:marko\"," + "\"label\": \"knows\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"person\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"person:marko\"," + "\"outV\": \"person:peter\"," + "\"properties\": {" + "\"date\": 1476720000000" + "}" + "}" + "]}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult result = new RestResult(this.mockResponse);
Assert.assertEquals(200, result.status());
Assert.assertNull(result.headers());
List<Edge> edges = result.readList("edges", Edge.class);
Assert.assertEquals(2, edges.size());
Edge edge1 = edges.get(0);
Edge edge2 = edges.get(1);
Assert.assertEquals("person:peter>created>>software:lop", edge1.id());
Assert.assertEquals("created", edge1.label());
Assert.assertEquals("person:peter", edge1.sourceId());
Assert.assertEquals("software:lop", edge1.targetId());
Assert.assertEquals("person", edge1.sourceLabel());
Assert.assertEquals("software", edge1.targetLabel());
Assert.assertEquals(ImmutableMap.of("city", "Hongkong", "date", 1495036800000L), edge1.properties());
Assert.assertEquals("person:peter>knows>>person:marko", edge2.id());
Assert.assertEquals("knows", edge2.label());
Assert.assertEquals("person:peter", edge2.sourceId());
Assert.assertEquals("person:marko", edge2.targetId());
Assert.assertEquals("person", edge2.sourceLabel());
Assert.assertEquals("person", edge2.targetLabel());
Assert.assertEquals(ImmutableMap.of("date", 1476720000000L), edge2.properties());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadEdge.
@Test
public void testReadEdge() {
String json = "{" + "\"id\": \"person:peter>created>>software:lop\"," + "\"label\": \"created\"," + "\"type\": \"edge\"," + "\"outV\": \"person:peter\"," + "\"inV\": \"software:lop\"," + "\"outVLabel\": \"person\"," + "\"inVLabel\": \"software\"," + "\"properties\": {" + "\"city\": \"Hongkong\"," + "\"date\": 1495036800000" + "}" + "}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult result = new RestResult(this.mockResponse);
Assert.assertEquals(200, result.status());
Assert.assertNull(result.headers());
Edge edge = result.readObject(Edge.class);
Assert.assertEquals("person:peter>created>>software:lop", edge.id());
Assert.assertEquals("created", edge.label());
Assert.assertEquals("person:peter", edge.sourceId());
Assert.assertEquals("software:lop", edge.targetId());
Assert.assertEquals("person", edge.sourceLabel());
Assert.assertEquals("software", edge.targetLabel());
Assert.assertEquals(ImmutableMap.of("city", "Hongkong", "date", 1495036800000L), edge.properties());
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class BatchElementRequestTest method testEdgeRequestBuildOK.
@Test
public void testEdgeRequestBuildOK() {
List<Edge> edges = ImmutableList.of(createEdge());
Map<String, UpdateStrategy> strategies = ImmutableMap.of("set", INTERSECTION);
BatchEdgeRequest req;
req = new BatchEdgeRequest.Builder().edges(edges).updatingStrategies(strategies).checkVertex(false).createIfNotExist(true).build();
Assert.assertNotNull(req);
Object list = Whitebox.getInternalState(req, "edges");
Assert.assertEquals(edges, list);
Object map = Whitebox.getInternalState(req, "updateStrategies");
Assert.assertEquals(strategies, map);
Object checked = Whitebox.getInternalState(req, "checkVertex");
Assert.assertEquals(false, checked);
Object created = Whitebox.getInternalState(req, "createIfNotExist");
Assert.assertEquals(true, created);
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class BatchElementRequestTest method createEdge.
private static Edge createEdge() {
Edge edge = new Edge("updates");
edge.id("object:1>updates>>object:2");
edge.sourceId("object:1");
edge.sourceLabel("object");
edge.targetId("object:2");
edge.targetLabel("object");
edge.property("price", 1);
return edge;
}
use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.
the class PathSerializerTest method testSerializeAndDeserializePathWithVertexAndEdge.
@Test
public void testSerializeAndDeserializePathWithVertexAndEdge() {
Vertex vertex = new Vertex("person");
vertex.id("person:marko");
vertex.property("name", "marko");
vertex.property("age", 29);
vertex.property("city", "Beijing");
Edge edge = new Edge("knows");
edge.id("person:marko>knows>>person:vadas");
edge.sourceId("person:marko");
edge.sourceLabel("person");
edge.targetId("person:vadas");
edge.targetLabel("person");
edge.property("date", "2016-01-10");
edge.property("weight", 0.5);
Path path = new Path();
path.labels(ImmutableList.of());
path.labels(ImmutableList.of());
path.objects(vertex);
path.objects(edge);
String json = serialize(path);
Path pathCopy = deserialize(json, Path.class);
Assert.assertEquals(2, pathCopy.objects().size());
Utils.assertGraphEqual(ImmutableList.of(vertex), ImmutableList.of(edge), path.objects());
}
Aggregations