use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAppendEdgeLabelWithUserdata.
@Test
public void testAppendEdgeLabelWithUserdata() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").create();
schema.vertexLabel("book").properties("name").primaryKeys("name").create();
EdgeLabel write = schema.edgeLabel("write").link("person", "book").properties("time", "weight").userdata("multiplicity", "one-to-many").create();
// The same key user data will be overwritten
Assert.assertEquals(2, write.userdata().size());
Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
write = schema.edgeLabel("write").userdata("icon", "picture2").append();
Assert.assertEquals(3, write.userdata().size());
Assert.assertEquals("one-to-many", write.userdata().get("multiplicity"));
Assert.assertEquals("picture2", write.userdata().get("icon"));
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAddEdgeLabelWithIllegalName.
@Test
public void testAddEdgeLabelWithIllegalName() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
// Empty string
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("").link("person", "author").create();
});
// One space
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel(" ").link("person", "author").create();
});
// Two spaces
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel(" ").link("person", "author").create();
});
// Multi spaces
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel(" ").link("person", "author").create();
});
// Start with '~'
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("~").link("person", "author").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("~ ").link("person", "author").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("~x").link("person", "author").create();
});
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAddEdgeLabelWithoutProperty.
@Test
public void testAddEdgeLabelWithoutProperty() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
EdgeLabel look = schema.edgeLabel("look").singleTime().link("person", "book").create();
Assert.assertNotNull(look);
Assert.assertEquals("look", look.name());
assertVLEqual("person", look.sourceLabel());
assertVLEqual("book", look.targetLabel());
Assert.assertEquals(0, look.properties().size());
Assert.assertEquals(0, look.sortKeys().size());
Assert.assertEquals(Frequency.SINGLE, look.frequency());
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAddEdgeLabelWithNullableKeysIntersectSortkeys.
@Test
public void testAddEdgeLabelWithNullableKeysIntersectSortkeys() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("look").multiTimes().properties("time", "weight").sortKeys("time").nullableKeys("time").link("person", "book").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("look").multiTimes().properties("time", "weight").sortKeys("time", "weight").nullableKeys("time").link("person", "book").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.edgeLabel("look").multiTimes().properties("time", "weight").sortKeys("time").nullableKeys("time", "weight").link("person", "book").create();
});
}
use of com.baidu.hugegraph.schema.SchemaManager in project incubator-hugegraph by apache.
the class EdgeLabelCoreTest method testAppendEdgeLabelNewEdgeWithNullableKeysAbsent.
@Test
public void testAppendEdgeLabelNewEdgeWithNullableKeysAbsent() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
schema.edgeLabel("look").properties("time", "weight").nullableKeys("weight").link("person", "book").create();
Vertex baby = graph().addVertex(T.label, "person", "name", "Baby", "age", 3, "city", "Beijing");
Vertex java = graph().addVertex(T.label, "book", "id", 123456, "name", "Java in action");
Assert.assertThrows(IllegalArgumentException.class, () -> {
// Absent 'time'
baby.addEdge("look", java, "weight", 0.5);
});
schema.edgeLabel("look").nullableKeys("time").append();
// Absent 'time'
Edge edge = baby.addEdge("look", java, "weight", 0.5);
Assert.assertEquals("look", edge.label());
Assert.assertEquals(0.5, edge.property("weight").value());
}
Aggregations