Search in sources :

Example 6 with FakeObjects

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);
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 7 with FakeObjects

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);
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 8 with FakeObjects

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);
}
Also used : HugeProperty(com.baidu.hugegraph.structure.HugeProperty) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 9 with FakeObjects

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);
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 10 with FakeObjects

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);
}
Also used : FakeObjects(com.baidu.hugegraph.unit.FakeObjects) VertexLabel(com.baidu.hugegraph.schema.VertexLabel) Id(com.baidu.hugegraph.backend.id.Id) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Test(org.junit.Test)

Aggregations

FakeObjects (com.baidu.hugegraph.unit.FakeObjects)19 Test (org.junit.Test)19 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)16 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)9 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)7 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)7 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)6 CachedSchemaTransaction (com.baidu.hugegraph.backend.cache.CachedSchemaTransaction)4 BinarySerializer (com.baidu.hugegraph.backend.serializer.BinarySerializer)4 HugeConfig (com.baidu.hugegraph.config.HugeConfig)4 Id (com.baidu.hugegraph.backend.id.Id)3 HugeResource (com.baidu.hugegraph.auth.HugeResource)2 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)2 BinaryScatterSerializer (com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer)2 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)2 HugeProperty (com.baidu.hugegraph.structure.HugeProperty)2 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)1 Date (java.util.Date)1