use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class TestAtlasTypeRegistry method testClassificationDefValidHierarchy.
/*
* L0
* / \
* / \
* L1_1---- L1_2
* / \ \ / \
* / \ \ / \
* L2_1 L2_2 L2_3 L2_4
*/
@Test
public void testClassificationDefValidHierarchy() {
AtlasClassificationDef classifiL0 = new AtlasClassificationDef("L0");
AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1");
AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2");
AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1");
AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2");
AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3");
AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4");
classifiL1_1.addSuperType(classifiL0.getName());
classifiL1_2.addSuperType(classifiL0.getName());
classifiL2_1.addSuperType(classifiL1_1.getName());
classifiL2_2.addSuperType(classifiL1_1.getName());
classifiL2_3.addSuperType(classifiL1_1.getName());
classifiL2_3.addSuperType(classifiL1_2.getName());
classifiL2_4.addSuperType(classifiL1_2.getName());
classifiL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
classifiL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
classifiL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
classifiL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
classifiL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
classifiL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
classifiL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(classifiL0);
typesDef.getClassificationDefs().add(classifiL1_1);
typesDef.getClassificationDefs().add(classifiL1_2);
typesDef.getClassificationDefs().add(classifiL2_1);
typesDef.getClassificationDefs().add(classifiL2_2);
typesDef.getClassificationDefs().add(classifiL2_3);
typesDef.getClassificationDefs().add(classifiL2_4);
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
String failureMsg = null;
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addTypes(typesDef);
commit = true;
} catch (AtlasBaseException excp) {
failureMsg = excp.getMessage();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertNull(failureMsg);
validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());
validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class TestAtlasEntityType method createColumnEntityDefWithInvalidInverseAttributeType.
private AtlasEntityDef createColumnEntityDefWithInvalidInverseAttributeType() {
AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
Map<String, Object> params = new HashMap<>();
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_NAME);
attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
column.addAttribute(attrTable);
return column;
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class TestAtlasStructType method testInvalidStructDef_MultiValuedAttributeNotArray.
@Test
public void testInvalidStructDef_MultiValuedAttributeNotArray() {
AtlasAttributeDef invalidMultiValuedAttrib = new AtlasAttributeDef("invalidAttributeDef", ATLAS_TYPE_INT);
invalidMultiValuedAttrib.setCardinality(Cardinality.LIST);
AtlasStructDef invalidStructDef = ModelTestUtil.newStructDef();
invalidStructDef.addAttribute(invalidMultiValuedAttrib);
try {
AtlasStructType invalidStructType = new AtlasStructType(invalidStructDef, ModelTestUtil.getTypesRegistry());
fail("invalidStructDef not detected: structDef=" + invalidStructDef + "; structType=" + invalidStructType);
} catch (AtlasBaseException excp) {
assertTrue(excp.getAtlasErrorCode() == AtlasErrorCode.INVALID_ATTRIBUTE_TYPE_FOR_CARDINALITY);
invalidStructDef.removeAttribute("invalidAttributeDef");
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class TestAtlasEntityType method createColumnEntityDef.
private AtlasEntityDef createColumnEntityDef() {
AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
Map<String, Object> params = new HashMap<>();
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_COLUMNS);
attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
column.addAttribute(attrTable);
return column;
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class TestAtlasEntityType method createColumnEntityDefWithNonExistingInverseAttribute.
private AtlasEntityDef createColumnEntityDefWithNonExistingInverseAttribute() {
AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
Map<String, Object> params = new HashMap<>();
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "non-existing:" + ATTR_COLUMNS);
attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
column.addAttribute(attrTable);
return column;
}
Aggregations