use of org.apache.atlas.catalog.definition.TaxonomyResourceDefinition in project incubator-atlas by apache.
the class TaxonomyResourceProviderTest method testDeleteResourceById.
@Test
public void testDeleteResourceById() throws Exception {
TermResourceProvider termResourceProvider = createStrictMock(TermResourceProvider.class);
AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
QueryFactory queryFactory = createStrictMock(QueryFactory.class);
AtlasQuery query = createStrictMock(AtlasQuery.class);
Capture<Request> getRequestCapture = newCapture();
Capture<TermPath> termPathCapture = newCapture();
Capture<ResourceDefinition> resourceDefinitionCapture = newCapture();
Capture<Request> deleteRequestCapture = newCapture();
Collection<Map<String, Object>> queryResult = new ArrayList<>();
Map<String, Object> queryResultRow = new HashMap<>();
queryResult.add(queryResultRow);
queryResultRow.put("name", "testTaxonomy");
queryResultRow.put("id", "111-222-333");
// mock expectations
expect(queryFactory.createTaxonomyQuery(capture(getRequestCapture))).andReturn(query);
expect(query.execute()).andReturn(queryResult);
termResourceProvider.deleteChildren(eq("111-222-333"), capture(termPathCapture));
typeSystem.deleteEntity(capture(resourceDefinitionCapture), capture(deleteRequestCapture));
replay(termResourceProvider, typeSystem, queryFactory, query);
TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem, termResourceProvider);
provider.setQueryFactory(queryFactory);
Map<String, Object> requestProperties = new HashMap<>();
requestProperties.put("name", "testTaxonomy");
Request userRequest = new InstanceRequest(requestProperties);
// invoke method being tested
provider.deleteResourceById(userRequest);
Request getRequest = getRequestCapture.getValue();
assertNull(getRequest.getQueryString());
assertEquals(getRequest.getAdditionalSelectProperties().size(), 1);
assertTrue(getRequest.getAdditionalSelectProperties().contains("id"));
assertEquals(getRequest.getQueryProperties().get("name"), "testTaxonomy");
Request deleteRequest = deleteRequestCapture.getValue();
assertNull(deleteRequest.getQueryString());
assertEquals(deleteRequest.getAdditionalSelectProperties().size(), 1);
assertTrue(deleteRequest.getAdditionalSelectProperties().contains("id"));
assertEquals(deleteRequest.getQueryProperties().get("name"), "testTaxonomy");
ResourceDefinition resourceDefinition = resourceDefinitionCapture.getValue();
assertTrue(resourceDefinition instanceof TaxonomyResourceDefinition);
verify(termResourceProvider, typeSystem, queryFactory, query);
}
use of org.apache.atlas.catalog.definition.TaxonomyResourceDefinition 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);
}
Aggregations