use of org.apache.atlas.catalog.query.AtlasQuery in project incubator-atlas by apache.
the class TaxonomyResourceProviderTest method testCreateResource.
@Test
public void testCreateResource() throws Exception {
AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
QueryFactory queryFactory = createStrictMock(QueryFactory.class);
AtlasQuery query = createStrictMock(AtlasQuery.class);
Capture<ResourceDefinition> resourceDefinitionCapture = newCapture();
Capture<Request> requestCapture = newCapture();
// empty response indicates that resource doesn't already exist
Collection<Map<String, Object>> queryResult = new ArrayList<>();
// mock expectations
expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query);
expect(query.execute()).andReturn(queryResult);
expect(typeSystem.createEntity(capture(resourceDefinitionCapture), capture(requestCapture))).andReturn("testGuid");
replay(typeSystem, queryFactory, query);
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);
assertEquals(new TaxonomyResourceDefinition().getTypeName(), resourceDefinitionCapture.getValue().getTypeName());
Request request = requestCapture.getValue();
assertNull(request.getQueryString());
assertEquals(requestProperties, request.getQueryProperties());
verify(typeSystem, queryFactory, query);
}
use of org.apache.atlas.catalog.query.AtlasQuery in project incubator-atlas by apache.
the class TaxonomyResourceProviderTest method testCreateResource_invalidRequest__noName.
@Test(expectedExceptions = InvalidPayloadException.class)
public void testCreateResource_invalidRequest__noName() throws Exception {
AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
QueryFactory queryFactory = createStrictMock(QueryFactory.class);
AtlasQuery query = createStrictMock(AtlasQuery.class);
// mock expectations
replay(typeSystem, queryFactory, query);
// taxonomy create request must contain 'name' property
Map<String, Object> requestProperties = new HashMap<>();
requestProperties.put("description", "test");
Request userRequest = new InstanceRequest(requestProperties);
TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
provider.setQueryFactory(queryFactory);
provider.createResource(userRequest);
}
use of org.apache.atlas.catalog.query.AtlasQuery 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);
}
use of org.apache.atlas.catalog.query.AtlasQuery 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);
}
use of org.apache.atlas.catalog.query.AtlasQuery 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);
}
Aggregations