use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithIdStrategy.
@Test
public void testAddVertexLabelWithIdStrategy() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").create();
Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
VertexLabel person1 = schema.vertexLabel("person1").useAutomaticId().properties("name", "age", "city").create();
Assert.assertEquals(IdStrategy.AUTOMATIC, person1.idStrategy());
VertexLabel person2 = schema.vertexLabel("person2").useCustomizeStringId().properties("name", "age", "city").create();
Assert.assertEquals(IdStrategy.CUSTOMIZE_STRING, person2.idStrategy());
VertexLabel person3 = schema.vertexLabel("person3").useCustomizeNumberId().properties("name", "age", "city").create();
Assert.assertEquals(IdStrategy.CUSTOMIZE_NUMBER, person3.idStrategy());
VertexLabel person4 = schema.vertexLabel("person4").useCustomizeUuidId().properties("name", "age", "city").create();
Assert.assertEquals(IdStrategy.CUSTOMIZE_UUID, person4.idStrategy());
VertexLabel person5 = schema.vertexLabel("person5").properties("name", "age", "city").primaryKeys("name").create();
Assert.assertEquals(IdStrategy.PRIMARY_KEY, person5.idStrategy());
VertexLabel person6 = schema.vertexLabel("person6").usePrimaryKeyId().properties("name", "age", "city").primaryKeys("name").create();
Assert.assertEquals(IdStrategy.PRIMARY_KEY, person6.idStrategy());
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithUserdata.
@Test
public void testAddVertexLabelWithUserdata() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
VertexLabel player = schema.vertexLabel("player").properties("name").userdata("super_vl", "person").create();
Assert.assertEquals(2, player.userdata().size());
Assert.assertEquals("person", player.userdata().get("super_vl"));
VertexLabel runner = schema.vertexLabel("runner").properties("name").userdata("super_vl", "person").userdata("super_vl", "player").create();
// The same key user data will be overwritten
Assert.assertEquals(2, runner.userdata().size());
Assert.assertEquals("player", runner.userdata().get("super_vl"));
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithTtl.
@Test
public void testAddVertexLabelWithTtl() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
schema.propertyKey("born").asDate().ifNotExist().create();
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").properties("name", "age", "city", "born").ttl(-86400L).create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").properties("name", "age", "city", "born").ttlStartTime("born").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").properties("name", "age", "city", "born").ttlStartTime("name").create();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
schema.vertexLabel("person").properties("name", "age", "city", "born").ttlStartTime("age").create();
});
VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city", "born").ttl(86400L).create();
Assert.assertNotNull(person);
Assert.assertEquals("person", person.name());
Assert.assertEquals(4, person.properties().size());
assertContainsPk(person.properties(), "name", "age", "city", "born");
Assert.assertEquals(0, person.primaryKeys().size());
Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
Assert.assertEquals(86400L, person.ttl());
Assert.assertEquals(IdGenerator.ZERO, person.ttlStartTime());
VertexLabel student = schema.vertexLabel("student").properties("name", "age", "city", "born").ttl(86400L).ttlStartTime("born").create();
Assert.assertNotNull(student);
Assert.assertEquals("student", student.name());
Assert.assertEquals(4, student.properties().size());
assertContainsPk(student.properties(), "name", "age", "city", "born");
Assert.assertEquals(0, student.primaryKeys().size());
Assert.assertEquals(IdStrategy.AUTOMATIC, student.idStrategy());
Assert.assertEquals(86400L, student.ttl());
Assert.assertNotNull(student.ttlStartTime());
assertContainsPk(ImmutableSet.of(student.ttlStartTime()), "born");
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithoutPropertyKey.
@Test
public void testAddVertexLabelWithoutPropertyKey() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
VertexLabel person = schema.vertexLabel("person").create();
Assert.assertTrue(person.properties().isEmpty());
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testListVertexLabels.
@Test
public void testListVertexLabels() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
VertexLabel author = schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
VertexLabel book = schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
List<VertexLabel> vertexLabels = schema.getVertexLabels();
Assert.assertEquals(3, vertexLabels.size());
Assert.assertTrue(vertexLabels.contains(person));
Assert.assertTrue(vertexLabels.contains(author));
Assert.assertTrue(vertexLabels.contains(book));
// clear cache
params().schemaEventHub().call(Events.CACHE, "clear", null);
Assert.assertEquals(person, schema.getVertexLabel("person"));
vertexLabels = schema.getVertexLabels();
Assert.assertEquals(3, vertexLabels.size());
Assert.assertTrue(vertexLabels.contains(person));
Assert.assertTrue(vertexLabels.contains(author));
Assert.assertTrue(vertexLabels.contains(book));
}
Aggregations