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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations