use of com.sun.jersey.core.util.MultivaluedMapImpl 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 com.sun.jersey.core.util.MultivaluedMapImpl in project incubator-atlas by apache.
the class TypedefsJerseyResourceIT method testListTypesByFilter.
@Test
public void testListTypesByFilter() throws Exception {
AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr);
AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(classDefA.getName()), attr);
AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr);
AtlasEntityDef classDefC = AtlasTypeUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(classDefB.getName(), classDefA.getName()), attr);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEntityDefs().add(classDefA);
atlasTypesDef.getEntityDefs().add(classDefA1);
atlasTypesDef.getEntityDefs().add(classDefB);
atlasTypesDef.getEntityDefs().add(classDefC);
AtlasTypesDef created = clientV2.createAtlasTypeDefs(atlasTypesDef);
assertNotNull(created);
assertEquals(created.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
searchParams.add(SearchFilter.PARAM_TYPE, "CLASS");
searchParams.add(SearchFilter.PARAM_SUPERTYPE, classDefA.getName());
SearchFilter searchFilter = new SearchFilter(searchParams);
AtlasTypesDef searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 2);
searchParams.add(SearchFilter.PARAM_NOT_SUPERTYPE, classDefB.getName());
searchFilter = new SearchFilter(searchParams);
searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 1);
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testGetEntityListForBadEntityType.
@Test(expectedExceptions = AtlasServiceException.class)
public void testGetEntityListForBadEntityType() throws Exception {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", "blah");
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.ERROR));
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testDeleteEntitiesViaRestApi.
@Test
public void testDeleteEntitiesViaRestApi() throws Exception {
// Create 2 database entities
Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
String dbName = randomString();
db1.set(NAME, dbName);
db1.set(DESCRIPTION, randomString());
db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
db1.set("owner", "user1");
db1.set(CLUSTER_NAME, "cl1");
db1.set("parameters", Collections.EMPTY_MAP);
db1.set("location", "/tmp");
Id db1Id = createInstance(db1);
Referenceable db2 = new Referenceable(DATABASE_TYPE_BUILTIN);
String dbName2 = randomString();
db2.set(NAME, dbName2);
db2.set(QUALIFIED_NAME, dbName2);
db2.set(CLUSTER_NAME, randomString());
db2.set(DESCRIPTION, randomString());
db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
db2.set("owner", "user2");
db2.set(CLUSTER_NAME, "cl1");
db2.set("parameters", Collections.EMPTY_MAP);
db2.set("location", "/tmp");
Id db2Id = createInstance(db2);
// Delete the database entities
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId());
queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId());
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.DELETE_ENTITIES, queryParams);
List<String> deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities();
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
// Verify entities were deleted from the repository.
for (String guid : deletedGuidsList) {
Referenceable entity = atlasClientV1.getEntity(guid);
assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
}
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project incubator-atlas by apache.
the class EntityJerseyResourceIT method testGetEntityListForNoInstances.
@Test
public void testGetEntityListForNoInstances() throws Exception {
String typeName = addNewType();
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", typeName);
JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
Assert.assertEquals(list.length(), 0);
}
Aggregations