Search in sources :

Example 56 with Edge

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

Example 57 with Edge

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

Example 58 with Edge

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);
}
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)

Example 59 with Edge

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

Example 60 with 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());
}
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)

Aggregations

Edge (com.baidu.hugegraph.structure.graph.Edge)103 Test (org.junit.Test)73 Vertex (com.baidu.hugegraph.structure.graph.Vertex)33 ArrayList (java.util.ArrayList)22 BaseClientTest (com.baidu.hugegraph.BaseClientTest)20 BatchEdgeRequest (com.baidu.hugegraph.structure.graph.BatchEdgeRequest)12 HugeClient (com.baidu.hugegraph.driver.HugeClient)10 Path (com.baidu.hugegraph.structure.graph.Path)9 Result (com.baidu.hugegraph.structure.gremlin.Result)8 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)7 RestResult (com.baidu.hugegraph.rest.RestResult)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 GraphManager (com.baidu.hugegraph.driver.GraphManager)4 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 Edges (com.baidu.hugegraph.structure.graph.Edges)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3