Search in sources :

Example 11 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testSubmitEntityWithBadDateFormat.

@Test
public void testSubmitEntityWithBadDateFormat() throws Exception {
    try {
        String dbName = "db" + randomString();
        String tableName = "table" + randomString();
        Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
        Id dbId = createInstance(hiveDBInstance);
        Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
        hiveTableInstance.set("lastAccessTime", "2014-07-11");
        Id tableId = createInstance(hiveTableInstance);
        Assert.fail("Was expecting an  exception here ");
    } catch (AtlasServiceException e) {
        Assert.assertTrue(e.getMessage().contains("\"error\":\"Cannot convert value '2014-07-11' to datatype date\""));
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 12 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException 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 13 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException 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 14 with AtlasServiceException

use of org.apache.atlas.AtlasServiceException in project incubator-atlas by apache.

the class TypedefsJerseyResourceIT method verifyByNameAndGUID.

private void verifyByNameAndGUID(AtlasBaseTypeDef typeDef) {
    try {
        AtlasBaseTypeDef byName = null;
        if (typeDef.getCategory() == TypeCategory.ENUM) {
            byName = clientV2.getEnumDefByName(typeDef.getName());
        } else if (typeDef.getCategory() == TypeCategory.ENTITY) {
            byName = clientV2.getEntityDefByName(typeDef.getName());
        } else if (typeDef.getCategory() == TypeCategory.CLASSIFICATION) {
            byName = clientV2.getClassificationDefByName(typeDef.getName());
        } else if (typeDef.getCategory() == TypeCategory.STRUCT) {
            byName = clientV2.getStructDefByName(typeDef.getName());
        }
        assertNotNull(byName);
    } catch (AtlasServiceException e) {
        fail("Get byName should've succeeded", e);
    }
    if (StringUtils.isNotBlank(typeDef.getGuid())) {
        try {
            AtlasBaseTypeDef byGuid = null;
            if (typeDef.getCategory() == TypeCategory.ENUM) {
                byGuid = clientV2.getEnumDefByGuid(typeDef.getGuid());
            } else if (typeDef.getCategory() == TypeCategory.ENTITY) {
                byGuid = clientV2.getEntityDefByGuid(typeDef.getGuid());
            } else if (typeDef.getCategory() == TypeCategory.CLASSIFICATION) {
                byGuid = clientV2.getClassificationDefByGuid(typeDef.getGuid());
            } else if (typeDef.getCategory() == TypeCategory.STRUCT) {
                byGuid = clientV2.getStructDefByGuid(typeDef.getGuid());
            }
            assertNotNull(byGuid);
        } catch (AtlasServiceException e) {
            fail("Get byGuid should've succeeded", e);
        }
    }
}
Also used : AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasBaseTypeDef(org.apache.atlas.model.typedef.AtlasBaseTypeDef)

Aggregations

AtlasServiceException (org.apache.atlas.AtlasServiceException)14 Test (org.testng.annotations.Test)12 Referenceable (org.apache.atlas.typesystem.Referenceable)7 Id (org.apache.atlas.typesystem.persistence.Id)6 TraitType (org.apache.atlas.typesystem.types.TraitType)4 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)2 Struct (org.apache.atlas.typesystem.Struct)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)1 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)1 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)1 AtlasBaseTypeDef (org.apache.atlas.model.typedef.AtlasBaseTypeDef)1 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)1 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)1 TypesDef (org.apache.atlas.typesystem.TypesDef)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 DateTime (org.joda.time.DateTime)1