use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.
the class TestAtlasClassification method testClassificationSerDeWithSuperTypes.
@Test
public void testClassificationSerDeWithSuperTypes() throws AtlasBaseException {
AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDefWithSuperTypes();
AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());
assertNotNull(classificationType);
AtlasClassification ent1 = classificationType.createDefaultValue();
String jsonString = AtlasType.toJson(ent1);
AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);
classificationType.normalizeAttributeValues(ent2);
assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification with superTypes");
}
use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.
the class TestAtlasClassification method testClassificationSerDe.
@Test
public void testClassificationSerDe() throws AtlasBaseException {
AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDef();
AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());
assertNotNull(classificationType);
AtlasClassification ent1 = ModelTestUtil.newClassification(classificationDef, typeRegistry);
String jsonString = AtlasType.toJson(ent1);
AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);
classificationType.normalizeAttributeValues(ent2);
assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification");
}
use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.
the class TestAtlasClassification method testClassificationSerDeWithSuperType.
@Test
public void testClassificationSerDeWithSuperType() throws AtlasBaseException {
AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDefWithSuperType();
AtlasTypeRegistry typeRegistry = ModelTestUtil.getTypesRegistry();
AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classificationDef.getName());
assertNotNull(classificationType);
AtlasClassification ent1 = classificationType.createDefaultValue();
String jsonString = AtlasType.toJson(ent1);
AtlasClassification ent2 = AtlasType.fromJson(jsonString, AtlasClassification.class);
classificationType.normalizeAttributeValues(ent2);
assertEquals(ent2, ent1, "Incorrect serialization/deserialization of AtlasClassification with superType");
}
use of org.apache.atlas.type.AtlasClassificationType in project atlas by apache.
the class EntityNotificationTest method testGetAllTraitsSuperTraits.
@Test
public void testGetAllTraitsSuperTraits() throws Exception {
AtlasTypeRegistry typeRegistry = mock(AtlasTypeRegistry.class);
String traitName = "MyTrait";
Struct myTrait = new Struct(traitName);
String superTraitName = "MySuperTrait";
AtlasClassificationType traitType = mock(AtlasClassificationType.class);
Set<String> superTypeNames = Collections.singleton(superTraitName);
AtlasClassificationType superTraitType = mock(AtlasClassificationType.class);
Set<String> superSuperTypeNames = Collections.emptySet();
Referenceable entity = getEntity("id", myTrait);
when(typeRegistry.getClassificationTypeByName(traitName)).thenReturn(traitType);
when(typeRegistry.getClassificationTypeByName(superTraitName)).thenReturn(superTraitType);
when(traitType.getAllSuperTypes()).thenReturn(superTypeNames);
when(superTraitType.getAllSuperTypes()).thenReturn(superSuperTypeNames);
EntityNotificationV1 entityNotification = new EntityNotificationV1(entity, OperationType.TRAIT_ADD, typeRegistry);
List<Struct> allTraits = entityNotification.getAllTraits();
assertEquals(2, allTraits.size());
for (Struct trait : allTraits) {
String typeName = trait.getTypeName();
assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
}
}
use of org.apache.atlas.type.AtlasClassificationType in project incubator-atlas by apache.
the class AtlasEntityStoreV1 method validateAndNormalizeForUpdate.
private void validateAndNormalizeForUpdate(AtlasClassification classification) throws AtlasBaseException {
AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());
if (type == null) {
throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
}
List<String> messages = new ArrayList<>();
type.validateValueForUpdate(classification, classification.getTypeName(), messages);
if (!messages.isEmpty()) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
}
type.getNormalizedValueForUpdate(classification);
}
Aggregations