Search in sources :

Example 96 with Vertex

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());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Example 97 with Vertex

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());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Example 98 with Vertex

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;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex)

Example 99 with 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());
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 100 with Vertex

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());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

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