Search in sources :

Example 21 with AttributeDefinition

use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.

the class TaxonomyResourceDefinitionTest method testGetPropertyDefinitions.

@Test
public void testGetPropertyDefinitions() {
    ResourceDefinition taxonomyDefinition = new TaxonomyResourceDefinition();
    Collection<AttributeDefinition> propertyDefinitions = taxonomyDefinition.getPropertyDefinitions();
    assertEquals(propertyDefinitions.size(), 3);
    Set<String> defNames = new HashSet<>();
    for (AttributeDefinition def : propertyDefinitions) {
        defNames.add(def.name);
    }
    assertTrue(defNames.contains("name"));
    assertTrue(defNames.contains("description"));
}
Also used : AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) Test(org.testng.annotations.Test)

Example 22 with AttributeDefinition

use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.

the class EntityTagResourceDefinitionTest method testGetPropertyDefinitions.

@Test
public void testGetPropertyDefinitions() {
    ResourceDefinition entityTagDefinition = new EntityTagResourceDefinition();
    Collection<AttributeDefinition> propertyDefinitions = entityTagDefinition.getPropertyDefinitions();
    assertEquals(propertyDefinitions.size(), 1);
    Set<String> defNames = new HashSet<>();
    for (AttributeDefinition def : propertyDefinitions) {
        defNames.add(def.name);
    }
    assertTrue(defNames.contains("name"));
}
Also used : AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) Test(org.testng.annotations.Test)

Example 23 with AttributeDefinition

use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.

the class TypeConverterUtil method entityToTypesDef.

private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) throws AtlasBaseException {
    String typeName = entityType.getEntityDef().getName();
    String typeDesc = entityType.getEntityDef().getDescription();
    String typeVersion = entityType.getEntityDef().getTypeVersion();
    ImmutableSet superTypes = ImmutableSet.copyOf(entityType.getEntityDef().getSuperTypes());
    AttributeDefinition[] attributes = getAttributes(entityType, registry);
    HierarchicalTypeDefinition<ClassType> classType = TypesUtil.createClassTypeDef(typeName, typeDesc, typeVersion, superTypes, attributes);
    TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(classType));
    return ret;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 24 with AttributeDefinition

use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.

the class FieldMappingTest method testOutputReferenceableInstance.

@Test
public void testOutputReferenceableInstance() throws Exception {
    // ATLAS-645: verify that FieldMapping.output(IReferenceableInstance)
    // does not infinitely recurse when ITypedReferenceableInstance's reference each other.
    HierarchicalTypeDefinition<ClassType> valueDef = TypesUtil.createClassTypeDef("Value", ImmutableSet.<String>of(), new AttributeDefinition("owner", "Owner", Multiplicity.OPTIONAL, false, null));
    // Define class type with reference, where the value is a class reference to Value.
    HierarchicalTypeDefinition<ClassType> ownerDef = TypesUtil.createClassTypeDef("Owner", ImmutableSet.<String>of(), new AttributeDefinition("value", "Value", Multiplicity.OPTIONAL, false, null));
    TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(ownerDef, valueDef));
    TypeSystem typeSystem = TypeSystem.getInstance();
    typeSystem.defineTypes(typesDef);
    ClassType ownerType = typeSystem.getDataType(ClassType.class, "Owner");
    // Prior to fix for ATLAS-645, this call would throw a StackOverflowError
    try {
        ownerType.toString();
    } catch (StackOverflowError e) {
        Assert.fail("Infinite recursion in ClassType.toString() caused StackOverflowError");
    }
    ClassType valueType = typeSystem.getDataType(ClassType.class, "Value");
    // Create instances of Owner and Value that reference each other.
    ITypedReferenceableInstance ownerInstance = ownerType.createInstance();
    ITypedReferenceableInstance valueInstance = valueType.createInstance();
    // Set Owner.value reference to Value instance.
    ownerInstance.set("value", valueInstance);
    // Set Value.owner reference on Owner instance.
    valueInstance.set("owner", ownerInstance);
    // Prior to fix for ATLAS-645, this call would throw a StackOverflowError
    try {
        ownerInstance.fieldMapping().output(ownerInstance, new StringBuilder(), "", new HashSet<IReferenceableInstance>());
    } catch (StackOverflowError e) {
        Assert.fail("Infinite recursion in FieldMapping.output() caused StackOverflowError");
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 25 with AttributeDefinition

use of org.apache.atlas.typesystem.types.AttributeDefinition in project incubator-atlas by apache.

the class RestUtilsTest method testBidirectonalNonCompositeMappingConsistent.

@Test(enabled = false)
public // in "table" attribute in "database".  See ATLAS-1528.
void testBidirectonalNonCompositeMappingConsistent() throws AtlasBaseException {
    HierarchicalTypeDefinition<ClassType> dbV1Type = TypesUtil.createClassTypeDef("database", ImmutableSet.<String>of(), new AttributeDefinition("tables", DataTypes.arrayTypeName("table"), Multiplicity.OPTIONAL, false, "containingDatabase"));
    HierarchicalTypeDefinition<ClassType> tableV1Type = TypesUtil.createClassTypeDef("table", ImmutableSet.<String>of(), new AttributeDefinition("containingDatabase", "database", Multiplicity.OPTIONAL, false, "tables"));
    testV1toV2toV1Conversion(Arrays.asList(dbV1Type, tableV1Type), new boolean[] { false, false });
}
Also used : AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Aggregations

AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)27 ClassType (org.apache.atlas.typesystem.types.ClassType)17 Test (org.testng.annotations.Test)13 TraitType (org.apache.atlas.typesystem.types.TraitType)10 ArrayList (java.util.ArrayList)7 TypesDef (org.apache.atlas.typesystem.TypesDef)7 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)5 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)4 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Referenceable (org.apache.atlas.typesystem.Referenceable)3 StructTypeDefinition (org.apache.atlas.typesystem.types.StructTypeDefinition)3 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)3 BeforeTest (org.testng.annotations.BeforeTest)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 QueryParams (org.apache.atlas.query.QueryParams)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Callable (java.util.concurrent.Callable)1