Search in sources :

Example 11 with TypeSystem

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

the class BaseTest method setup.

@BeforeMethod
public void setup() throws Exception {
    TypeSystem ts = TypeSystem.getInstance();
    ts.reset();
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with TypeSystem

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

the class GraphBackedDiscoveryServiceTest method setUp.

@Override
@BeforeClass
public void setUp() throws Exception {
    super.setUp();
    repositoryService = TestUtils.addTransactionWrapper(repositoryService);
    final TypeSystem typeSystem = TypeSystem.getInstance();
    Collection<String> oldTypeNames = new HashSet<>();
    oldTypeNames.addAll(typeSystem.getTypeNames());
    TestUtils.defineDeptEmployeeTypes(typeSystem);
    addIndexesForNewTypes(oldTypeNames, typeSystem);
    ITypedReferenceableInstance hrDept = TestUtils.createDeptEg1(typeSystem);
    repositoryService.createEntities(hrDept);
    ITypedReferenceableInstance jane = repositoryService.getEntityDefinition("Manager", "name", "Jane");
    Id janeGuid = jane.getId();
    ClassType personType = typeSystem.getDataType(ClassType.class, "Person");
    ITypedReferenceableInstance instance = personType.createInstance(janeGuid);
    instance.set("orgLevel", "L1");
    repositoryService.updatePartial(instance);
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ClassType(org.apache.atlas.typesystem.types.ClassType) BeforeClass(org.testng.annotations.BeforeClass)

Example 13 with TypeSystem

use of org.apache.atlas.typesystem.types.TypeSystem 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 14 with TypeSystem

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

the class SerializationJavaTest method testTrait.

@Test
public void testTrait() throws AtlasException {
    TypeSystem ts = getTypeSystem();
    HierarchicalTypeDefinition<TraitType> securityClearanceTypeDef = createTraitTypeDef("SecurityClearance2", ImmutableSet.<String>of(), createRequiredAttrDef("level", DataTypes.INT_TYPE));
    ts.defineTypes(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(securityClearanceTypeDef), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
    Struct s = new Struct("SecurityClearance2");
    s.set("level", 1);
    TraitType tType = ts.getDataType(TraitType.class, "SecurityClearance2");
    ITypedInstance t = tType.convert(s, Multiplicity.REQUIRED);
    String jsonStr = Serialization$.MODULE$.toJson(t);
    ITypedInstance t2 = Serialization$.MODULE$.traitFromJson(jsonStr);
    Assert.assertEquals(t.toString(), t2.toString());
}
Also used : ITypedInstance(org.apache.atlas.typesystem.ITypedInstance) TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test) BaseTest(org.apache.atlas.typesystem.types.BaseTest)

Aggregations

TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)14 Test (org.testng.annotations.Test)9 ClassType (org.apache.atlas.typesystem.types.ClassType)8 TraitType (org.apache.atlas.typesystem.types.TraitType)6 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)5 Referenceable (org.apache.atlas.typesystem.Referenceable)4 Struct (org.apache.atlas.typesystem.Struct)3 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)3 BeforeTest (org.testng.annotations.BeforeTest)3 IStruct (org.apache.atlas.typesystem.IStruct)2 TypesDef (org.apache.atlas.typesystem.TypesDef)2 BaseTest (org.apache.atlas.typesystem.types.BaseTest)2 EnumValue (org.apache.atlas.typesystem.types.EnumValue)2 BeforeClass (org.testng.annotations.BeforeClass)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)1 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)1