Search in sources :

Example 71 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class EdgeApiTest method testCreateWithUndefinedSourceOrTargetLabel.

@Test
public void testCreateWithUndefinedSourceOrTargetLabel() {
    Edge edge = new Edge("created");
    edge.sourceLabel("undefined");
    edge.targetLabel("undefined");
    edge.sourceId("person:peter");
    edge.targetId("software:lop");
    edge.property("date", "2017-03-24");
    edge.property("city", "Hongkong");
    Utils.assertResponseError(400, () -> {
        edgeAPI.create(edge);
    });
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 72 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class EdgeApiTest method testAddEdgeWithTtlAndTtlStartTime.

@Test
public void testAddEdgeWithTtlAndTtlStartTime() {
    SchemaManager schema = schema();
    schema.propertyKey("place").asText().ifNotExist().create();
    schema.edgeLabel("borrow").link("person", "book").properties("place", "date").ttl(3000L).ttlStartTime("date").enableLabelIndex(true).ifNotExist().create();
    Vertex baby = graph().addVertex(T.label, "person", "name", "Baby", "age", 3, "city", "Beijing");
    Vertex java = graph().addVertex(T.label, "book", T.id, "java", "name", "Java in action");
    long date = DateUtil.now().getTime() - 1000L;
    String dateString = Utils.formatDate(new Date(date));
    Edge edge = baby.addEdge("borrow", java, "place", "library of school", "date", date);
    Edge result = graph().getEdge(edge.id());
    Assert.assertEquals("borrow", result.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("book", edge.targetLabel());
    Assert.assertEquals(baby.id(), edge.sourceId());
    Assert.assertEquals(java.id(), edge.targetId());
    Map<String, Object> props = ImmutableMap.of("place", "library of school", "date", dateString);
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    result = graph().getEdge(edge.id());
    Assert.assertEquals("borrow", result.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("book", edge.targetLabel());
    Assert.assertEquals(baby.id(), edge.sourceId());
    Assert.assertEquals(java.id(), edge.targetId());
    Assert.assertEquals(props, result.properties());
    try {
        Thread.sleep(1100L);
    } catch (InterruptedException e) {
    // Ignore
    }
    Assert.assertThrows(ServerException.class, () -> {
        graph().getEdge(edge.id());
    }, e -> {
        Assert.assertContains("does not exist", e.getMessage());
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Edge(com.baidu.hugegraph.structure.graph.Edge) Date(java.util.Date) Test(org.junit.Test)

Example 73 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class EdgeApiTest method testBatchCreateWithInvalidVertexLabelButNotCheck.

/**
 * Note: When the vertex of an edge is dirty (id), g.E() will
 * construct the vertex, and then throw a illegal exception.
 * That will lead clearData error.
 * (Icafe: HugeGraph-768)
 */
// @Test
// public void testBatchCreateWithInvalidVertexIdButNotCheck() {
// List<Edge> edges = new ArrayList<>(2);
// 
// Edge edge1 = new Edge("created");
// edge1.sourceLabel("person");
// edge1.targetLabel("software");
// edge1.sourceId("person:invalid");
// edge1.targetId("software:lop");
// edge1.property("date", "2017-03-24");
// edge1.property("city", "Hongkong");
// edges.add(edge1);
// 
// Edge edge2 = new Edge("knows");
// edge2.sourceLabel("person");
// edge2.targetLabel("person");
// edge2.sourceId("person:peter");
// edge2.targetId("person:invalid");
// edge2.property("date", "2017-03-24");
// edges.add(edge2);
// 
// List<String> ids = edgeAPI.create(edges, false);
// Assert.assertEquals(2, ids.size());
// 
// Utils.assertErrorResponse(404, () -> {
// edgeAPI.get(ids.get(0));
// });
// Utils.assertErrorResponse(404, () -> {
// edgeAPI.get(ids.get(1));
// });
// }
@Test
public void testBatchCreateWithInvalidVertexLabelButNotCheck() {
    List<Edge> edges = new ArrayList<>(2);
    Edge edge1 = new Edge("created");
    edge1.sourceId("person:peter");
    edge1.targetId("software:lop");
    edge1.property("date", "2017-03-24");
    edge1.property("city", "Hongkong");
    edges.add(edge1);
    Edge edge2 = new Edge("knows");
    edge2.sourceLabel("undefined");
    edge2.targetLabel("undefined");
    edge2.sourceId("person:peter");
    edge2.targetId("person:marko");
    edge2.property("date", "2017-03-24");
    edges.add(edge2);
    Utils.assertResponseError(400, () -> {
        edgeAPI.create(edges, false);
    });
}
Also used : ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 74 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class EdgeApiTest method testCreateWithNullableKeysAbsent.

@Test
public void testCreateWithNullableKeysAbsent() {
    Object outVId = getVertexId("person", "name", "peter");
    Object inVId = getVertexId("software", "name", "lop");
    Edge edge = new Edge("created");
    edge.sourceLabel("person");
    edge.targetLabel("software");
    edge.sourceId(outVId);
    edge.targetId(inVId);
    // Absent prop 'city'
    edge.property("date", Utils.date("2017-03-24"));
    edgeAPI.create(edge);
    Assert.assertEquals("created", edge.label());
    Assert.assertEquals("person", edge.sourceLabel());
    Assert.assertEquals("software", edge.targetLabel());
    Assert.assertEquals(outVId, edge.sourceId());
    Assert.assertEquals(inVId, edge.targetId());
    Map<String, Object> props = ImmutableMap.of("date", Utils.date("2017-03-24"));
    Assert.assertEquals(props, edge.properties());
}
Also used : Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 75 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class EdgeApiTest method testDelete.

@Test
public void testDelete() {
    Object outVId = getVertexId("person", "name", "peter");
    Object inVId = getVertexId("software", "name", "lop");
    Edge edge = new Edge("created");
    edge.sourceLabel("person");
    edge.targetLabel("software");
    edge.sourceId(outVId);
    edge.targetId(inVId);
    edge.property("date", "2017-03-24");
    edge.property("city", "Hongkong");
    edge = edgeAPI.create(edge);
    final String id = edge.id();
    edgeAPI.delete(id);
    Assert.assertThrows(ServerException.class, () -> {
        edgeAPI.get(id);
    }, e -> {
        String expect = String.format("Edge '%s' does not exist", id);
        Assert.assertContains(expect, e.getMessage());
    });
}
Also used : 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