Search in sources :

Example 46 with AtlasQuery

use of org.apache.atlas.catalog.query.AtlasQuery in project incubator-atlas by apache.

the class TermResourceProviderTest method testGetResources_noResults.

@Test
public void testGetResources_noResults() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> requestCapture = newCapture();
    TermPath termPath = new TermPath("testTaxonomy", "termName");
    // empty result shouldn't result in exception for collection query
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    // mock expectations
    expect(queryFactory.createTermQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    TermResourceProvider provider = new TermResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("termPath", termPath);
    Request userRequest = new CollectionRequest(requestProperties, "name:taxonomy*");
    // invoke test method
    Result result = provider.getResources(userRequest);
    assertEquals(0, result.getPropertyMaps().size());
    Request request = requestCapture.getValue();
    assertEquals(request.getQueryString(), "name:taxonomy*");
    assertEquals(request.getAdditionalSelectProperties().size(), 0);
    assertEquals(request.getQueryProperties().size(), 1);
    verify(typeSystem, queryFactory, query);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 47 with AtlasQuery

use of org.apache.atlas.catalog.query.AtlasQuery in project incubator-atlas by apache.

the class TermResourceProviderTest method testUpdateResourceById.

@Test
public void testUpdateResourceById() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> termRequestCapture = newCapture();
    Capture<Request> tagRequestCapture = newCapture();
    TermPath termPath = new TermPath("testTaxonomy", "termName");
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("termPath", termPath);
    Map<String, Object> requestUpdateProperties = new HashMap<>();
    requestUpdateProperties.put("description", "updatedValue");
    Request userRequest = new InstanceRequest(requestProperties, requestUpdateProperties);
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    Map<String, Object> queryResultRow = new HashMap<>();
    queryResult.add(queryResultRow);
    queryResultRow.put("name", "testTaxonomy.termName");
    // mock expectations
    // term update
    expect(queryFactory.createTermQuery(capture(termRequestCapture))).andReturn(query);
    expect(query.execute(requestUpdateProperties)).andReturn(queryResult);
    // tag updates
    expect(queryFactory.createEntityTagQuery(capture(tagRequestCapture))).andReturn(query);
    // query response isn't used so just returning null
    expect(query.execute(requestUpdateProperties)).andReturn(null);
    replay(typeSystem, queryFactory, query);
    TermResourceProvider provider = new TermResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.updateResourceById(userRequest);
    Request request = termRequestCapture.getValue();
    assertNull(request.getQueryString());
    assertTrue(request.getAdditionalSelectProperties().isEmpty());
    assertEquals(request.getQueryProperties().size(), 2);
    assertEquals(request.getQueryProperties().get("termPath"), termPath);
    assertEquals(request.getQueryProperties().get("name"), termPath.getFullyQualifiedName());
    Request tagRequest = tagRequestCapture.getValue();
    assertEquals(tagRequest.getQueryString(), "name:testTaxonomy.termName");
    assertEquals(tagRequest.getQueryProperties().size(), 1);
    assertEquals(tagRequest.getQueryProperties().get("id"), "*");
    verify(typeSystem, queryFactory, query);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Aggregations

AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)47 QueryFactory (org.apache.atlas.catalog.query.QueryFactory)38 Test (org.testng.annotations.Test)38 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)5 TaxonomyResourceDefinition (org.apache.atlas.catalog.definition.TaxonomyResourceDefinition)3 ResourceAlreadyExistsException (org.apache.atlas.catalog.exception.ResourceAlreadyExistsException)2 ResourceNotFoundException (org.apache.atlas.catalog.exception.ResourceNotFoundException)1