use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelTest method testLinkedVertexLabel.
@Test
public void testLinkedVertexLabel() {
SchemaManager schema = schema();
EdgeLabel father = schema.edgeLabel("father").link("person", "person").properties("weight").userdata("multiplicity", "one-to-many").create();
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("multiplicity", "many-to-many").create();
Assert.assertTrue(father.linkedVertexLabel("person"));
Assert.assertFalse(father.linkedVertexLabel("book"));
Assert.assertTrue(write.linkedVertexLabel("person"));
Assert.assertTrue(write.linkedVertexLabel("book"));
}
use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelTest method testSetCheckExist.
@Test
public void testSetCheckExist() {
SchemaManager schema = schema();
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("date", "weight").userdata("multiplicity", "one-to-many").userdata("icon", "picture2").create();
Assert.assertTrue(write.checkExist());
write.checkExist(false);
Assert.assertFalse(write.checkExist());
}
use of com.baidu.hugegraph.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelTest method testAppendEdgeLabelWithUserData.
@Test
public void testAppendEdgeLabelWithUserData() {
SchemaManager schema = schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").ifNotExist().create();
EdgeLabel father = schema.edgeLabel("father").link("person", "person").properties("weight").create();
Assert.assertEquals(1, father.userdata().size());
String time = (String) father.userdata().get("~create_time");
Date createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
father = schema.edgeLabel("father").userdata("multiplicity", "one-to-many").append();
Assert.assertEquals(2, father.userdata().size());
Assert.assertEquals("one-to-many", father.userdata().get("multiplicity"));
time = (String) father.userdata().get("~create_time");
Assert.assertEquals(createTime, DateUtil.parse(time));
}
use of com.baidu.hugegraph.driver.SchemaManager 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.driver.SchemaManager in project incubator-hugegraph-toolchain by apache.
the class GraphsApiTest method initEdgeLabel.
protected static void initEdgeLabel(HugeClient client) {
SchemaManager schema = client.schema();
schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").multiTimes().properties("date", "city").sortKeys("date").nullableKeys("city").ifNotExist().create();
schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "city").nullableKeys("city").ifNotExist().create();
}
Aggregations