Search in sources :

Example 36 with QueryFactory

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

the class TaxonomyResourceProviderTest 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> taxonomyRequestCapture = newCapture();
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "testTaxonomy");
    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");
    // mock expectations
    // term update
    expect(queryFactory.createTaxonomyQuery(capture(taxonomyRequestCapture))).andReturn(query);
    expect(query.execute(requestUpdateProperties)).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    // instantiate resource provider and invoke method being tested
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.updateResourceById(userRequest);
    Request request = taxonomyRequestCapture.getValue();
    assertNull(request.getQueryString());
    assertEquals(request.getQueryProperties().size(), 1);
    assertEquals(request.getQueryProperties().get("name"), "testTaxonomy");
    assertEquals(request.getUpdateProperties().size(), 1);
    assertEquals(request.getUpdateProperties().get("description"), "updatedValue");
    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 37 with QueryFactory

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

the class TaxonomyResourceProviderTest method testGetResourceById_notInitialized_taxonomyAlreadyExists.

@Test
public void testGetResourceById_notInitialized_taxonomyAlreadyExists() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> checkForAnyTaxonomiesCapture = newCapture();
    Capture<Request> requestCapture = newCapture();
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    Map<String, Object> queryResultRow = new HashMap<>();
    queryResult.add(queryResultRow);
    queryResultRow.put("name", "taxonomyName");
    queryResultRow.put("description", "test taxonomy description");
    queryResultRow.put("creation_time", "04/20/2016");
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(checkForAnyTaxonomiesCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    TestTaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setInitialized(false);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "taxonomyName");
    Request userRequest = new InstanceRequest(requestProperties);
    Result result = provider.getResourceById(userRequest);
    assertEquals(1, result.getPropertyMaps().size());
    assertEquals(queryResultRow, result.getPropertyMaps().iterator().next());
    Request request = requestCapture.getValue();
    assertNull(request.getQueryString());
    assertEquals(0, request.getAdditionalSelectProperties().size());
    assertEquals(requestProperties, request.getQueryProperties());
    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 38 with QueryFactory

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

the class TaxonomyResourceProviderTest method testGetResourceById_404.

@Test(expectedExceptions = ResourceNotFoundException.class)
public void testGetResourceById_404() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> requestCapture = newCapture();
    // empty response should result in a ResourceNotFoundException
    Collection<Map<String, Object>> emptyResponse = new ArrayList<>();
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(emptyResponse);
    replay(typeSystem, queryFactory, query);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "taxonomyName");
    Request request = new InstanceRequest(requestProperties);
    provider.getResourceById(request);
    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 39 with QueryFactory

use of org.apache.atlas.catalog.query.QueryFactory 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 40 with QueryFactory

use of org.apache.atlas.catalog.query.QueryFactory 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

QueryFactory (org.apache.atlas.catalog.query.QueryFactory)40 Test (org.testng.annotations.Test)40 AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)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