Search in sources :

Example 11 with AtlasTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.

the class TestAtlasEntity method testEntitySerDe.

@Test
public void testEntitySerDe() throws AtlasBaseException {
    AtlasEntityDef entityDef = ModelTestUtil.getEntityDef();
    AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
    assertNotNull(entityType);
    AtlasEntity ent1 = entityType.createDefaultValue();
    String jsonString = AtlasType.toJson(ent1);
    AtlasEntity ent2 = AtlasType.fromJson(jsonString, AtlasEntity.class);
    entityType.normalizeAttributeValues(ent2);
    assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasEntity");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Example 12 with AtlasTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.

the class BaseRepositoryTest method setUp.

protected void setUp() throws Exception {
    //force graph initialization / built in type registration
    TestUtils.getGraph();
    setUpDefaultTypes();
    setUpTypes();
    TestUtils.getGraph().commit();
    new GraphBackedSearchIndexer(new AtlasTypeRegistry());
    TestUtils.resetRequestContext();
    setupInstances();
    TestUtils.getGraph().commit();
    TestUtils.dumpGraph(TestUtils.getGraph());
}
Also used : GraphBackedSearchIndexer(org.apache.atlas.repository.graph.GraphBackedSearchIndexer) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry)

Example 13 with AtlasTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.

the class RestUtilsTest method convertV1toV2.

private List<AtlasEntityDef> convertV1toV2(List<HierarchicalTypeDefinition<ClassType>> types) throws AtlasBaseException {
    ImmutableList<HierarchicalTypeDefinition<ClassType>> classTypeList = ImmutableList.<HierarchicalTypeDefinition<ClassType>>builder().addAll(types).build();
    TypesDef toConvert = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), classTypeList);
    String json = TypesSerialization.toJson(toConvert);
    AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry();
    AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry);
    List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs();
    return convertedEntityDefs;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 14 with AtlasTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.

the class RestUtilsTest method createRegistry.

private AtlasTypeRegistry createRegistry(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
    AtlasTypeRegistry reg = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry tmp = reg.lockTypeRegistryForUpdate();
    tmp.addTypes(toConvert);
    reg.releaseTypeRegistryForUpdate(tmp, true);
    return reg;
}
Also used : AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry)

Example 15 with AtlasTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry in project incubator-atlas by apache.

the class RestUtilsTest method testV1toV2toV1Conversion.

private void testV1toV2toV1Conversion(List<HierarchicalTypeDefinition<ClassType>> typesToTest, boolean[] compositeExpected) throws AtlasBaseException {
    List<AtlasEntityDef> convertedEntityDefs = convertV1toV2(typesToTest);
    AtlasTypeRegistry registry = createRegistry(convertedEntityDefs);
    for (int i = 0; i < convertedEntityDefs.size(); i++) {
        AtlasEntityDef def = convertedEntityDefs.get(i);
        for (AtlasAttributeDef attrDef : def.getAttributeDefs()) {
            AtlasAttributeDef converted = convertToJsonAndBack(registry, def, attrDef, compositeExpected[i]);
            Assert.assertEquals(converted, attrDef);
        }
    }
    List<HierarchicalTypeDefinition<ClassType>> convertedBackTypeDefs = convertV2toV1(convertedEntityDefs);
    for (int i = 0; i < typesToTest.size(); i++) {
        HierarchicalTypeDefinition<ClassType> convertedBack = convertedBackTypeDefs.get(i);
        Assert.assertEquals(convertedBack, typesToTest.get(i));
        AttributeDefinition[] attributeDefinitions = convertedBack.attributeDefinitions;
        if (attributeDefinitions.length > 0) {
            Assert.assertEquals(attributeDefinitions[0].isComposite, compositeExpected[i]);
        }
    }
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Aggregations

AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)15 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)6 Test (org.testng.annotations.Test)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)4 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)3 GraphBackedSearchIndexer (org.apache.atlas.repository.graph.GraphBackedSearchIndexer)3 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)3 TypesDef (org.apache.atlas.typesystem.TypesDef)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2 BeforeClass (org.testng.annotations.BeforeClass)2 ArrayList (java.util.ArrayList)1 AtlasException (org.apache.atlas.AtlasException)1 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)1 TypesChangeListener (org.apache.atlas.listener.TypesChangeListener)1 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)1 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)1 InMemoryEntityAuditRepository (org.apache.atlas.repository.audit.InMemoryEntityAuditRepository)1 GraphBackedTypeStore (org.apache.atlas.repository.typestore.GraphBackedTypeStore)1 ITypeStore (org.apache.atlas.repository.typestore.ITypeStore)1