Search in sources :

Example 21 with QueryFactory

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

the class EntityResourceProviderTest method testCreateResource.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testCreateResource() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    // mock expectations
    replay(typeSystem, queryFactory, query);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("id", "1");
    Request userRequest = new InstanceRequest(requestProperties);
    EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResource(userRequest);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Example 22 with QueryFactory

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

the class EntityResourceProviderTest 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();
    // empty result shouldn't result in exception for collection query
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    // mock expectations
    expect(queryFactory.createEntityQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Request userRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), "name:entity*");
    Result result = provider.getResources(userRequest);
    assertEquals(0, result.getPropertyMaps().size());
    Request request = requestCapture.getValue();
    assertEquals("name:entity*", request.getQueryString());
    assertEquals(0, request.getAdditionalSelectProperties().size());
    assertEquals(0, request.getQueryProperties().size());
    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 23 with QueryFactory

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

the class EntityResourceProviderTest 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", "entity1");
    queryResultRow1.put("description", "test entity description");
    queryResultRow1.put("creation_time", "04/20/2016");
    Map<String, Object> queryResultRow2 = new HashMap<>();
    queryResult.add(queryResultRow2);
    queryResultRow2.put("mame", "entity2");
    queryResultRow2.put("description", "test entity description 2");
    queryResultRow2.put("creation_time", "04/21/2016");
    // mock expectations
    expect(queryFactory.createEntityQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Request userRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), "name:entity*");
    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:entity*", 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 24 with QueryFactory

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

the class TaxonomyResourceProviderTest method testCreateResources.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testCreateResources() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    // mock expectations
    replay(typeSystem, queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "taxonomyName");
    Request userRequest = new InstanceRequest(requestProperties);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResources(userRequest);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Example 25 with QueryFactory

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

the class TaxonomyResourceProviderTest method testDeleteResourceById_404.

@Test(expectedExceptions = ResourceNotFoundException.class)
public void testDeleteResourceById_404() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> getRequestCapture = newCapture();
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(getRequestCapture))).andReturn(query);
    expect(query.execute()).andThrow(new ResourceNotFoundException("test msg"));
    replay(typeSystem, queryFactory, query);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem, null);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "badName");
    Request userRequest = new InstanceRequest(requestProperties);
    // invoke method being tested
    provider.deleteResourceById(userRequest);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) ResourceNotFoundException(org.apache.atlas.catalog.exception.ResourceNotFoundException) 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