Search in sources :

Example 36 with VertexLabel

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

Example 37 with VertexLabel

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);
}
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 38 with VertexLabel

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);
}
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 39 with VertexLabel

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);
}
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 40 with VertexLabel

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);
}
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

VertexLabel (com.baidu.hugegraph.schema.VertexLabel)86 Test (org.junit.Test)35 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)27 Id (com.baidu.hugegraph.backend.id.Id)23 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)20 HugeGraph (com.baidu.hugegraph.HugeGraph)19 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)19 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)12 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)6 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4 Date (java.util.Date)4