Search in sources :

Example 26 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testGetTraitDefinitionForEntity.

@Test(dependsOnMethods = "testSubmitEntity")
public void testGetTraitDefinitionForEntity() throws Exception {
    traitName = "PII_Trait" + randomString();
    AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(piiTrait);
    createType(typesDef);
    AtlasClassificationDef classificationByName = atlasClientV2.getClassificationDefByName(traitName);
    assertNotNull(classificationByName);
    AtlasEntity hiveTable = createHiveTable();
    assertEquals(hiveTable.getClassifications().size(), 7);
    AtlasClassification piiClassification = new AtlasClassification(piiTrait.getName());
    atlasClientV2.addClassifications(hiveTable.getGuid(), Lists.newArrayList(piiClassification));
    AtlasClassifications classifications = atlasClientV2.getClassifications(hiveTable.getGuid());
    assertNotNull(classifications);
    assertTrue(classifications.getList().size() > 0);
    assertEquals(classifications.getList().size(), 8);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasClassifications(org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 27 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testDeleteExistentTraitNonExistentForEntity.

@Test(dependsOnMethods = "testSubmitEntity")
public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
    final String guid = createHiveTable().getGuid();
    final String traitName = "PII_Trait" + randomString();
    AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("type", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(piiTrait);
    createType(typesDef);
    try {
        atlasClientV2.deleteClassification(guid, traitName);
        fail("Deletion should've failed for non-existent trait association");
    } catch (AtlasServiceException ex) {
        Assert.assertNotNull(ex.getStatus());
        assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 28 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class TypedefsJerseyResourceIT method testInvalidGets.

@Test
public void testInvalidGets() throws Exception {
    try {
        AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEnumDef byGuid = clientV2.getEnumDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasStructDef byName = clientV2.getStructDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasStructDef byGuid = clientV2.getStructDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasClassificationDef byName = clientV2.getClassificationDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasClassificationDef byGuid = clientV2.getClassificationDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEntityDef byName = clientV2.getEntityDefByName("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
    try {
        AtlasEntityDef byGuid = clientV2.getEntityDefByGuid("blah");
        fail("Get for invalid name should have reported a failure");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(), "Should've returned a 404");
    }
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) Test(org.testng.annotations.Test)

Example 29 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-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");
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) Test(org.testng.annotations.Test)

Example 30 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-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");
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) Test(org.testng.annotations.Test)

Aggregations

AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)45 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)24 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)22 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)21 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)18 Test (org.testng.annotations.Test)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 ArrayList (java.util.ArrayList)8 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)8 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)5 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 HashMap (java.util.HashMap)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2