Search in sources :

Example 6 with AtlasServiceException

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

the class TypesJerseyResourceIT method testDuplicateSubmit.

@Test
public void testDuplicateSubmit() throws Exception {
    HierarchicalTypeDefinition<ClassType> type = TypesUtil.createClassTypeDef(randomString(), ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
    TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(type));
    atlasClientV1.createType(typesDef);
    try {
        atlasClientV1.createType(typesDef);
        fail("Expected 409");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
    }
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) TraitType(org.apache.atlas.typesystem.types.TraitType) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 7 with AtlasServiceException

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

the class MetadataDiscoveryJerseyResourceIT method testSearchDSLLimits.

@Test
public void testSearchDSLLimits() throws Exception {
    //search without new parameters of limit and offset should work
    String dslQuery = "from " + DATABASE_TYPE + " name=\"" + dbName + "\"";
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("query", dslQuery);
    JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams);
    assertNotNull(response);
    //higher limit, all results returned
    JSONArray results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
    assertEquals(results.length(), 1);
    //default limit and offset -1, all results returned
    results = atlasClientV1.searchByDSL(dslQuery, -1, -1);
    assertEquals(results.length(), 1);
    //uses the limit parameter passed
    results = atlasClientV1.searchByDSL(dslQuery, 1, 0);
    assertEquals(results.length(), 1);
    //uses the offset parameter passed
    results = atlasClientV1.searchByDSL(dslQuery, 10, 1);
    assertEquals(results.length(), 0);
    //limit > 0
    try {
        atlasClientV1.searchByDSL(dslQuery, 0, 10);
        fail("Expected BAD_REQUEST");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
    }
    //limit > maxlimit
    try {
        atlasClientV1.searchByDSL(dslQuery, Integer.MAX_VALUE, 10);
        fail("Expected BAD_REQUEST");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
    }
    //offset >= 0
    try {
        atlasClientV1.searchByDSL(dslQuery, 10, -2);
        fail("Expected BAD_REQUEST");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) AtlasServiceException(org.apache.atlas.AtlasServiceException) JSONArray(org.codehaus.jettison.json.JSONArray) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 8 with AtlasServiceException

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

the class TypedefsJerseyResourceIT method testDuplicateCreate.

@Test
public void testDuplicateCreate() throws Exception {
    AtlasEntityDef type = createClassTypeDef(randomString(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(type);
    AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
    assertNotNull(created);
    try {
        created = clientV2.createAtlasTypeDefs(typesDef);
        fail("Expected 409");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
    }
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 9 with AtlasServiceException

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

the class BaseResourceIT method modifyEntity.

protected AtlasEntityHeader modifyEntity(AtlasEntity atlasEntity, boolean update) {
    EntityMutationResponse entity = null;
    try {
        if (!update) {
            entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(atlasEntity));
            assertNotNull(entity);
            assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
            assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size() > 0);
            return entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0);
        } else {
            entity = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(atlasEntity));
            assertNotNull(entity);
            assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
            assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
            return entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0);
        }
    } catch (AtlasServiceException e) {
        LOG.error("Entity {} failed", update ? "update" : "creation", entity);
    }
    return null;
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasServiceException(org.apache.atlas.AtlasServiceException) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse)

Example 10 with AtlasServiceException

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

the class EntityJerseyResourceIT method testEntityInvalidValue.

@Test(dataProvider = "invalidAttrValues")
public void testEntityInvalidValue(String value) throws Exception {
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
    databaseInstance.set("name", randomString());
    databaseInstance.set("description", value);
    try {
        createInstance(databaseInstance);
        Assert.fail("Expected AtlasServiceException");
    } catch (AtlasServiceException e) {
        Assert.assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Test(org.testng.annotations.Test)

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