use of org.apache.atlas.catalog.query.QueryFactory in project incubator-atlas by apache.
the class TermResourceProviderTest 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.createTermQuery(capture(requestCapture))).andReturn(query);
expect(query.execute()).andReturn(emptyResponse);
replay(typeSystem, queryFactory, query);
TermResourceProvider provider = new TermResourceProvider(typeSystem);
provider.setQueryFactory(queryFactory);
Map<String, Object> requestProperties = new HashMap<>();
requestProperties.put("termPath", new TermPath("taxonomyName.badTermName"));
Request request = new InstanceRequest(requestProperties);
provider.getResourceById(request);
}
use of org.apache.atlas.catalog.query.QueryFactory in project incubator-atlas by apache.
the class TermResourceProviderTest 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);
// null term name should result in InvalidPayloadException
TermPath termPath = new TermPath("testTaxonomy", null);
// mock expectations
replay(typeSystem, queryFactory, query);
Map<String, Object> requestProperties = new HashMap<>();
requestProperties.put("termPath", termPath);
Request userRequest = new InstanceRequest(requestProperties);
TermResourceProvider provider = new TermResourceProvider(typeSystem);
provider.setQueryFactory(queryFactory);
provider.createResource(userRequest);
}
use of org.apache.atlas.catalog.query.QueryFactory in project incubator-atlas by apache.
the class EntityTagResourceProviderTest 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);
replay(typeSystem, queryFactory, query);
Map<String, Object> requestProperties = new HashMap<>();
// missing name name should result in InvalidPayloadException
requestProperties.put("description", "description");
Request userRequest = new InstanceRequest(requestProperties);
EntityTagResourceProvider provider = new EntityTagResourceProvider(typeSystem);
provider.setQueryFactory(queryFactory);
provider.createResource(userRequest);
}
use of org.apache.atlas.catalog.query.QueryFactory 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.QueryFactory 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);
}
Aggregations