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" + "}");
}
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" + "}");
}
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" + "}");
}
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());
}
Aggregations