Search in sources :

Example 21 with MultivaluedMapImpl

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());
    }
}
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 22 with MultivaluedMapImpl

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);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 23 with MultivaluedMapImpl

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));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 24 with MultivaluedMapImpl

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);
    }
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Id(org.apache.atlas.typesystem.persistence.Id) Test(org.testng.annotations.Test)

Example 25 with MultivaluedMapImpl

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);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Aggregations

MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)69 JSONObject (org.codehaus.jettison.json.JSONObject)33 Test (org.junit.Test)31 ClientResponse (com.sun.jersey.api.client.ClientResponse)27 WebResource (com.sun.jersey.api.client.WebResource)19 Test (org.testng.annotations.Test)19 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)12 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)11 JSONArray (org.codehaus.jettison.json.JSONArray)9 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)7 Response (javax.ws.rs.core.Response)6 BridgePort (org.midonet.client.resource.BridgePort)5 Router (org.midonet.client.resource.Router)5 Bridge (org.midonet.client.resource.Bridge)4 Route (org.midonet.client.resource.Route)4 RouterPort (org.midonet.client.resource.RouterPort)4 OAuthServiceException (com.sun.identity.oauth.service.OAuthServiceException)3 Client (com.sun.jersey.api.client.Client)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)3