Search in sources :

Example 46 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project incubator-atlas by apache.

the class MetadataDiscoveryJerseyResourceIT method testSearchUsingDSL.

@Test
public void testSearchUsingDSL() throws Exception {
    // String query = "from dsl_test_type";
    String query = "from " + DATABASE_TYPE + " name=\"" + dbName + "\"";
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("query", query);
    JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH, queryParams);
    Assert.assertNotNull(response);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    assertEquals(response.getString("query"), query);
    assertEquals(response.getString("queryType"), "dsl");
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Example 47 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project incubator-atlas by apache.

the class MetadataDiscoveryJerseyResourceIT method testSearchByDSL.

@Test
public void testSearchByDSL() throws Exception {
    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);
    Assert.assertNotNull(response);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    assertEquals(response.getString("query"), dslQuery);
    assertEquals(response.getString("queryType"), "dsl");
    JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
    assertNotNull(results);
    assertEquals(results.length(), 1);
    int numRows = response.getInt(AtlasClient.COUNT);
    assertEquals(numRows, 1);
}
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)

Example 48 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 49 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 50 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project incubator-atlas by apache.

the class MetadataDiscoveryJerseyResourceIT method testSearchUsingGremlin.

@Test
public void testSearchUsingGremlin() throws Exception {
    String query = "g.V.has('type', '" + BaseResourceIT.HIVE_TABLE_TYPE + "').toList()";
    MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
    queryParams.add("query", query);
    JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GREMLIN_SEARCH, queryParams);
    assertNotNull(response);
    assertNotNull(response.get(AtlasClient.REQUEST_ID));
    assertEquals(response.getString("query"), query);
    assertEquals(response.getString("queryType"), "gremlin");
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.testng.annotations.Test)

Aggregations

MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)131 Test (org.junit.Test)55 ClientResponse (com.sun.jersey.api.client.ClientResponse)48 WebResource (com.sun.jersey.api.client.WebResource)39 JSONObject (org.codehaus.jettison.json.JSONObject)39 Test (org.testng.annotations.Test)35 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)12 List (java.util.List)11 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)11 JSONArray (org.codehaus.jettison.json.JSONArray)9 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 Client (com.sun.jersey.api.client.Client)7 SearchFilter (org.apache.atlas.model.SearchFilter)7 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 WebDriverHelper (org.orcid.api.common.WebDriverHelper)7 Response (javax.ws.rs.core.Response)6 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)6 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)6 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)6