Search in sources :

Example 16 with AtlasQuery

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

the class TaxonomyResourceProviderTest method testGetResourceById.

@Test
public void testGetResourceById() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    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(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    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 17 with AtlasQuery

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

the class TaxonomyResourceProviderTest method testUpdateResourceById_404.

@Test(expectedExceptions = ResourceNotFoundException.class)
public void testUpdateResourceById_404() 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", "updated");
    Request userRequest = new InstanceRequest(requestProperties, requestUpdateProperties);
    // mock expectations
    // term update
    expect(queryFactory.createTaxonomyQuery(capture(taxonomyRequestCapture))).andReturn(query);
    expect(query.execute(requestUpdateProperties)).andReturn(Collections.<Map<String, Object>>emptyList());
    replay(typeSystem, queryFactory, query);
    // instantiate resource provider and invoke method being tested
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.updateResourceById(userRequest);
    verify(typeSystem, queryFactory, query);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Example 18 with AtlasQuery

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

the class TaxonomyResourceProviderTest method testGetResources.

@Test
public void testGetResources() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> requestCapture = newCapture();
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    Map<String, Object> queryResultRow1 = new HashMap<>();
    queryResult.add(queryResultRow1);
    queryResultRow1.put("mame", "taxonomyName1");
    queryResultRow1.put("description", "test taxonomy description");
    queryResultRow1.put("creation_time", "04/20/2016");
    Map<String, Object> queryResultRow2 = new HashMap<>();
    queryResult.add(queryResultRow2);
    queryResultRow2.put("mame", "taxonomyName2");
    queryResultRow2.put("description", "test taxonomy description 2");
    queryResultRow2.put("creation_time", "04/21/2016");
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Request userRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), "name:taxonomy*");
    Result result = provider.getResources(userRequest);
    assertEquals(2, result.getPropertyMaps().size());
    assertTrue(result.getPropertyMaps().contains(queryResultRow1));
    assertTrue(result.getPropertyMaps().contains(queryResultRow2));
    Request request = requestCapture.getValue();
    assertEquals("name:taxonomy*", request.getQueryString());
    assertEquals(0, request.getAdditionalSelectProperties().size());
    assertEquals(0, request.getQueryProperties().size());
    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 19 with AtlasQuery

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

the class TaxonomyResourceProviderTest method testCreateResource_invalidRequest__alreadyExists.

@Test(expectedExceptions = ResourceAlreadyExistsException.class)
public void testCreateResource_invalidRequest__alreadyExists() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> requestCapture = newCapture();
    // query is executed to see if resource already exists
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    Map<String, Object> queryResultRow = new HashMap<>();
    queryResult.add(queryResultRow);
    queryResultRow.put("mame", "taxonomyName");
    queryResultRow.put("description", "test taxonomy description");
    queryResultRow.put("creation_time", "04/20/2016");
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query);
    // returning result for query should result in ResourceAlreadyExistsException
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    // taxonomy create request must contain 'name' property
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "taxonomyName");
    Request userRequest = new InstanceRequest(requestProperties);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResource(userRequest);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 20 with AtlasQuery

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

the class EntityTagResourceProviderTest 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();
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    // mock expectations
    expect(queryFactory.createEntityTagQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    EntityTagResourceProvider provider = new EntityTagResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("id", "1");
    Request userRequest = new CollectionRequest(requestProperties, "name:testTaxonomy.*");
    // invoke test method
    Result result = provider.getResources(userRequest);
    assertEquals(0, result.getPropertyMaps().size());
    Request request = requestCapture.getValue();
    assertEquals("name:testTaxonomy.*", request.getQueryString());
    assertEquals(0, request.getAdditionalSelectProperties().size());
    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