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