use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.
the class JsonUtilTest method testSerializePropertyKey.
@Test
public void testSerializePropertyKey() {
FakeObjects fakeObject = new FakeObjects();
PropertyKey name = fakeObject.newPropertyKey(IdGenerator.of(1), "name");
String json = JsonUtil.toJson(name);
Assert.assertEquals("{\"id\":1,\"name\":\"name\"," + "\"data_type\":\"TEXT\"," + "\"cardinality\":\"SINGLE\"," + "\"aggregate_type\":\"NONE\"," + "\"write_type\":\"OLTP\"," + "\"properties\":[],\"status\":\"CREATED\"," + "\"user_data\":{}}", json);
PropertyKey rate = fakeObject.newPropertyKey(IdGenerator.of(2), "rate", DataType.INT, Cardinality.LIST);
json = JsonUtil.toJson(rate);
Assert.assertEquals("{\"id\":2,\"name\":\"rate\"," + "\"data_type\":\"INT\",\"cardinality\":\"LIST\"," + "\"aggregate_type\":\"NONE\"," + "\"write_type\":\"OLTP\"," + "\"properties\":[],\"status\":\"CREATED\"," + "\"user_data\":{}}", json);
}
use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.
the class JsonUtilTest method testSerializeIndexLabel.
@Test
public void testSerializeIndexLabel() {
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");
VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
IndexLabel il = fakeObject.newIndexLabel(IdGenerator.of(1), "personByAgeAndCity", HugeType.VERTEX_LABEL, vl.id(), IndexType.SECONDARY, age.id(), city.id());
Mockito.when(fakeObject.graph().vertexLabel(vl.id())).thenReturn(vl);
Mockito.when(fakeObject.graph().mapPkId2Name(il.indexFields())).thenReturn(Arrays.asList(age.name(), city.name()));
String json = JsonUtil.toJson(il);
Assert.assertEquals("{\"id\":1," + "\"name\":\"personByAgeAndCity\"," + "\"base_type\":\"VERTEX_LABEL\"," + "\"base_value\":\"person\"," + "\"index_type\":\"SECONDARY\"," + "\"fields\":[\"age\",\"city\"]," + "\"status\":\"CREATED\"," + "\"user_data\":{}}", json);
}
use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.
the class JsonUtilTest method testSerializeVertexWithNumberId.
@Test
public void testSerializeVertexWithNumberId() {
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");
VertexLabel vl = fakeObject.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
Id id = IdGenerator.of(123456L);
HugeVertex vertex = new HugeVertex(fakeObject.graph(), id, vl);
MutableIntObjectMap<HugeProperty<?>> properties = CollectionFactory.newIntObjectMap(name.id(), new HugeVertexProperty<>(vertex, name, "marko"), age.id(), new HugeVertexProperty<>(vertex, age, 29), city.id(), new HugeVertexProperty<>(vertex, city, "Beijing"));
Whitebox.setInternalState(vertex, "properties", properties);
String json = JsonUtil.toJson(vertex);
Assert.assertEquals("{\"id\":123456,\"label\":\"person\"," + "\"type\":\"vertex\",\"properties\":{\"" + "name\":\"marko\",\"age\":29," + "\"city\":\"Beijing\"}}", json);
}
use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.
the class JsonUtilTest method testSerializeEdgeLabel.
@Test
public void testSerializeEdgeLabel() {
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());
Mockito.when(fakeObject.graph().vertexLabel(vl.id())).thenReturn(vl);
Mockito.when(fakeObject.graph().mapPkId2Name(el.properties())).thenReturn(Arrays.asList(date.name(), weight.name()));
String json = JsonUtil.toJson(el);
Assert.assertEquals("{\"id\":1,\"name\":\"knows\"," + "\"source_label\":\"person\"," + "\"target_label\":\"person\"," + "\"frequency\":\"SINGLE\",\"sort_keys\":[]," + "\"nullable_keys\":[],\"index_labels\":[]," + "\"properties\":[\"date\",\"weight\"]," + "\"status\":\"CREATED\"," + "\"ttl\":0,\"enable_label_index\":true," + "\"user_data\":{}}", json);
}
use of com.baidu.hugegraph.unit.FakeObjects in project incubator-hugegraph by apache.
the class SplicingIdGeneratorTest method testGenerate.
@Test
public void testGenerate() {
FakeObjects fakeObjects = new FakeObjects();
PropertyKey name = fakeObjects.newPropertyKey(IdGenerator.of(1), "name");
VertexLabel vertexLabel = fakeObjects.newVertexLabel(IdGenerator.of(1L), "fake", IdStrategy.PRIMARY_KEY, name.id());
HugeVertex vertex = Mockito.mock(HugeVertex.class);
Mockito.when(vertex.schemaLabel()).thenReturn(vertexLabel);
Mockito.when(vertex.name()).thenReturn("marko");
Id vid = SplicingIdGenerator.instance().generate(vertex);
Assert.assertEquals(IdGenerator.of("1:marko"), vid);
}
Aggregations