use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadVertex.
@Test
public void testReadVertex() {
String json = "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"name\": \"marko\"" + "}" + "}";
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());
Vertex vertex = result.readObject(Vertex.class);
Assert.assertEquals("person:marko", vertex.id());
Assert.assertEquals("person", vertex.label());
Assert.assertEquals(ImmutableMap.of("name", "marko"), vertex.properties());
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadVertices.
@Test
public void testReadVertices() {
String json = "{\"vertices\": [" + "{" + "\"id\": \"person:marko\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"city\": [\"Beijing\",\"Wuhan\",\"Beijing\"]," + "\"name\": \"marko\"," + "\"age\": 29" + "}" + "}," + "{" + "\"id\": \"software:lop\"," + "\"label\": \"software\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"price\": 328," + "\"name\": \"lop\"," + "\"lang\": [\"java\",\"python\",\"c++\"]" + "}" + "}," + "{" + "\"id\": \"person:peter\"," + "\"label\": \"person\"," + "\"type\": \"vertex\"," + "\"properties\": {" + "\"city\": [\"Shanghai\"]," + "\"name\": \"peter\"," + "\"age\": 29" + "}" + "}" + "]}";
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<Vertex> vertices = result.readList("vertices", Vertex.class);
Assert.assertEquals(3, vertices.size());
Vertex vertex1 = vertices.get(0);
Vertex vertex2 = vertices.get(1);
Vertex vertex3 = vertices.get(2);
Assert.assertEquals("person:marko", vertex1.id());
Assert.assertEquals("person", vertex1.label());
Assert.assertEquals(ImmutableMap.of("name", "marko", "age", 29, "city", ImmutableList.of("Beijing", "Wuhan", "Beijing")), vertex1.properties());
Assert.assertEquals("software:lop", vertex2.id());
Assert.assertEquals("software", vertex2.label());
Assert.assertEquals(ImmutableMap.of("name", "lop", "lang", ImmutableList.of("java", "python", "c++"), "price", 328), vertex2.properties());
Assert.assertEquals("person:peter", vertex3.id());
Assert.assertEquals("person", vertex3.label());
Assert.assertEquals(ImmutableMap.of("name", "peter", "age", 29, "city", ImmutableList.of("Shanghai")), vertex3.properties());
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class BatchElementRequestTest method createVertex.
private static Vertex createVertex() {
Vertex vertex = new Vertex("object");
vertex.id("object:1");
vertex.property("name", 1);
vertex.property("price", 2);
return vertex;
}
use of com.baidu.hugegraph.structure.graph.Vertex 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());
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class VertexTest method testAddVertexProperty.
@Test
public void testAddVertexProperty() {
Vertex vadas = graph().addVertex(T.label, "person", "name", "vadas", "age", 19);
Map<String, Object> props = ImmutableMap.of("name", "vadas", "age", 19);
Assert.assertEquals(props, vadas.properties());
vadas.property("city", "Beijing");
props = ImmutableMap.of("name", "vadas", "age", 19, "city", "Beijing");
Assert.assertEquals(props, vadas.properties());
}
Aggregations