Search in sources :

Example 1 with ITypedInstance

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

the class TypeInheritanceTest method testSimpleInheritanceWithOverrides.

/*
     * Type Hierarchy is:
     *   A(a, b)
     *   B(b) extends A
     */
@Test
public void testSimpleInheritanceWithOverrides() throws AtlasException {
    HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE), createRequiredAttrDef("b", DataTypes.BOOLEAN_TYPE));
    HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    defineClasses(A, B);
    ClassType BType = getTypeSystem().getDataType(ClassType.class, "B");
    Struct s1 = new Struct("B");
    s1.set("b", true);
    s1.set("a", 1);
    s1.set("A.B.b", false);
    ITypedInstance ts = BType.convert(s1, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\tid : (type: B, id: <unassigned>)\n" + "\tb : \ttrue\n" + "\ta : \t1\n" + "\tA.B.b : \tfalse\n" + "}");
}
Also used : ITypedInstance(org.apache.atlas.typesystem.ITypedInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 2 with ITypedInstance

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

the class TypeInheritanceTest method testMultiLevelInheritance.

/*
     * Type Hierarchy is:
     *   A(a)
     *   B(b) extends A
     *   C(c) extends B
     *   D(d) extends C
     */
@Test
public void testMultiLevelInheritance() throws AtlasException {
    HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
    HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    HierarchicalTypeDefinition C = createClassTypeDef("C", ImmutableSet.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
    HierarchicalTypeDefinition D = createClassTypeDef("D", ImmutableSet.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
    defineClasses(A, B, C, D);
    ClassType DType = getTypeSystem().getDataType(ClassType.class, "D");
    Struct s1 = new Struct("D");
    s1.set("d", 1);
    s1.set("c", 1);
    s1.set("b", true);
    s1.set("a", 1);
    ITypedInstance ts = DType.convert(s1, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\tid : (type: D, id: <unassigned>)\n" + "\td : \t1\n" + "\tc : \t1\n" + "\tb : \ttrue\n" + "\ta : \t1\n" + "}");
}
Also used : ITypedInstance(org.apache.atlas.typesystem.ITypedInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 3 with ITypedInstance

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

the class TypeInheritanceTest method testSimpleInheritance.

/*
     * Type Hierarchy is:
     *   A(a)
     *   B(b) extends A
     */
@Test
public void testSimpleInheritance() throws AtlasException {
    HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
    HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    defineClasses(A, B);
    ClassType BType = getTypeSystem().getDataType(ClassType.class, "B");
    Struct s1 = new Struct("B");
    s1.set("b", true);
    s1.set("a", 1);
    ITypedInstance ts = BType.convert(s1, Multiplicity.REQUIRED);
    Assert.assertEquals(ts.toString(), "{\n" + "\tid : (type: B, id: <unassigned>)\n" + "\tb : \ttrue\n" + "\ta : \t1\n" + "}");
}
Also used : ITypedInstance(org.apache.atlas.typesystem.ITypedInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 4 with ITypedInstance

use of org.apache.atlas.typesystem.ITypedInstance 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

ITypedInstance (org.apache.atlas.typesystem.ITypedInstance)4 Struct (org.apache.atlas.typesystem.Struct)4 Test (org.testng.annotations.Test)4 IStruct (org.apache.atlas.typesystem.IStruct)3 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)3 BaseTest (org.apache.atlas.typesystem.types.BaseTest)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1 TraitType (org.apache.atlas.typesystem.types.TraitType)1 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)1