use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithNullableKeys.
@Test
public void testAddVertexLabelWithNullableKeys() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").create();
Assert.assertNotNull(person);
Assert.assertEquals("person", person.name());
Assert.assertEquals(3, person.properties().size());
assertContainsPk(person.properties(), "name", "age", "city");
Assert.assertEquals(1, person.primaryKeys().size());
assertContainsPk(person.primaryKeys(), "name");
Assert.assertEquals(1, person.nullableKeys().size());
assertContainsPk(person.nullableKeys(), "city");
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexWithDefaultIdStrategyAndNotPassedPk.
@Test
public void testAddVertexWithDefaultIdStrategyAndNotPassedPk() {
super.initPropertyKeys();
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age").create();
Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexWithAutomaticIdStrategyAndNotPassedPk.
@Test
public void testAddVertexWithAutomaticIdStrategyAndNotPassedPk() {
super.initPropertyKeys();
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person = schema.vertexLabel("person").useAutomaticId().properties("name", "age").create();
Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method newVertex.
private HugeVertex newVertex(Id id) {
HugeGraph graph = this.cache().graph();
graph.schema().propertyKey("name").asText().checkExist(false).create();
graph.schema().vertexLabel("person").idStrategy(IdStrategy.CUSTOMIZE_NUMBER).properties("name").nullableKeys("name").checkExist(false).create();
VertexLabel vl = graph.vertexLabel("person");
return new HugeVertex(graph, id, vl);
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class JsonUtilTest method testSerializeEdge.
@Test
public void testSerializeEdge() {
FakeObjects fakeObject = new FakeObjects();
PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
PropertyKey age = fakeObject.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
PropertyKey city = fakeObject.newPropertyKey(IdGenerator.of(3), "city");
PropertyKey date = fakeObject.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
PropertyKey weight = fakeObject.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
EdgeLabel el = fakeObject.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
HugeVertex source = new HugeVertex(fakeObject.graph(), IdGenerator.of(123456), vl);
HugeVertex target = new HugeVertex(fakeObject.graph(), IdGenerator.of(987654), vl);
Id id = EdgeId.parse("L123456>1>>L987654");
HugeEdge edge = new HugeEdge(fakeObject.graph(), id, el);
Whitebox.setInternalState(edge, "sourceVertex", source);
Whitebox.setInternalState(edge, "targetVertex", target);
Date dateValue = Utils.date("2019-03-12");
MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(date.id(), new HugeEdgeProperty<>(edge, date, dateValue), weight.id(), new HugeEdgeProperty<>(edge, weight, 0.8));
Whitebox.setInternalState(edge, "properties", properties);
String json = JsonUtil.toJson(edge);
Assert.assertEquals("{\"id\":\"L123456>1>>L987654\"," + "\"label\":\"knows\",\"type\":\"edge\"," + "\"outV\":123456,\"outVLabel\":\"person\"," + "\"inV\":987654,\"inVLabel\":\"person\"," + "\"properties\":{\"date\":" + "\"2019-03-12 00:00:00.000\"," + "\"weight\":0.8}}", json);
}
Aggregations