use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class RolePermissionTest method testHugeResourceFilterSchema.
@Test
public void testHugeResourceFilterSchema() {
HugeResource all = HugeResource.ALL;
HugeResource schema = new HugeResource(ResourceType.SCHEMA, HugeResource.ANY, null);
HugeResource vlPrefix = new HugeResource(ResourceType.VERTEX_LABEL, "p-.*", null);
ResourceObject<?> r3 = ResourceObject.of("g1", ResourceType.VERTEX_LABEL, NameObject.of("test"));
Assert.assertTrue(all.filter(r3));
Assert.assertTrue(schema.filter(r3));
Assert.assertFalse(vlPrefix.filter(r3));
ResourceObject<?> r4 = ResourceObject.of("g1", ResourceType.VERTEX_LABEL, NameObject.of("p-test"));
Assert.assertTrue(all.filter(r4));
Assert.assertTrue(schema.filter(r4));
Assert.assertTrue(vlPrefix.filter(r4));
FakeObjects fo = new FakeObjects();
VertexLabel vl1 = fo.newVertexLabel(IdGenerator.of("id1"), "person", IdStrategy.PRIMARY_KEY, IdGenerator.of("1"));
ResourceObject<?> r5 = ResourceObject.of("g1", vl1);
Assert.assertTrue(all.filter(r5));
Assert.assertTrue(schema.filter(r5));
Assert.assertFalse(vlPrefix.filter(r5));
VertexLabel vl2 = fo.newVertexLabel(IdGenerator.of("id1"), "p-person", IdStrategy.PRIMARY_KEY, IdGenerator.of("1"));
ResourceObject<?> r6 = ResourceObject.of("g1", vl2);
Assert.assertTrue(all.filter(r6));
Assert.assertTrue(schema.filter(r6));
Assert.assertTrue(vlPrefix.filter(r6));
}
use of com.baidu.hugegraph.schema.VertexLabel 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.schema.VertexLabel 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.schema.VertexLabel 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.schema.VertexLabel 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