use of org.apache.atlas.catalog.query.AtlasQuery in project incubator-atlas by apache.
the class TaxonomyResourceProvider method updateResourceById.
@Override
public void updateResourceById(Request request) throws ResourceNotFoundException, InvalidPayloadException {
resourceDefinition.validateUpdatePayload(request);
AtlasQuery atlasQuery;
try {
atlasQuery = queryFactory.createTaxonomyQuery(request);
} catch (InvalidQueryException e) {
throw new CatalogRuntimeException("Unable to compile internal Term query: " + e, e);
}
synchronized (TaxonomyResourceProvider.class) {
createDefaultTaxonomyIfNeeded();
if (atlasQuery.execute(request.getUpdateProperties()).isEmpty()) {
throw new ResourceNotFoundException(String.format("Taxonomy '%s' not found.", request.getQueryProperties().get("name")));
}
}
}
use of org.apache.atlas.catalog.query.AtlasQuery 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);
}
use of org.apache.atlas.catalog.query.AtlasQuery 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.query.AtlasQuery in project incubator-atlas by apache.
the class TaxonomyResourceProviderTest method testUpdateResourceById_attemptNameChange.
@Test(expectedExceptions = InvalidPayloadException.class)
public void testUpdateResourceById_attemptNameChange() 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("name", "notCurrentlySupported");
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);
verify(typeSystem, queryFactory, query);
}
use of org.apache.atlas.catalog.query.AtlasQuery in project incubator-atlas by apache.
the class EntityResourceProviderTest method testGetResource_404.
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testGetResource_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.createEntityQuery(capture(requestCapture))).andReturn(query);
expect(query.execute()).andReturn(emptyResponse);
replay(typeSystem, queryFactory, query);
EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
provider.setQueryFactory(queryFactory);
Map<String, Object> requestProperties = new HashMap<>();
requestProperties.put("id", "1");
Request request = new InstanceRequest(requestProperties);
provider.getResourceById(request);
verify(typeSystem, queryFactory, query);
}
Aggregations