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());
}
}
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());
}
}
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());
}
}
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;
}
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);
}
}
Aggregations