use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testCreateSubTerm.
@Test
public void testCreateSubTerm() throws Exception {
String taxonomyName = "testTaxonomy";
String termName = "testTerm";
MetadataService metadataService = createStrictMock(MetadataService.class);
AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
UriInfo uriInfo = createNiceMock(UriInfo.class);
URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
Capture<Request> requestCapture = newCapture();
String body = "{ \"description\" : \"test description\" } ";
// set mock expectations
expect(uriInfo.getRequestUri()).andReturn(uri);
expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
termResourceProvider.createResource(capture(requestCapture));
replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
// instantiate service and invoke method being tested
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null);
Response response = service.createSubTerm(body, null, uriInfo, taxonomyName, termName, "/terms/testTerm2");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 2);
assertEquals(request.getQueryProperties().get("description"), "test description");
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2");
assertNull(request.getQueryString());
assertEquals(response.getStatus(), 201);
BaseService.Results createResults = (BaseService.Results) response.getEntity();
assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm/terms/testTerm2");
assertEquals(createResults.status, 201);
verify(uriInfo, taxonomyResourceProvider, termResourceProvider);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testGetTaxonomyTerm.
@Test
public void testGetTaxonomyTerm() throws Exception {
String taxonomyName = "testTaxonomy";
String termName = "testTaxonomy.termName";
MetadataService metadataService = createStrictMock(MetadataService.class);
AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
UriInfo uriInfo = createNiceMock(UriInfo.class);
JsonSerializer serializer = createStrictMock(JsonSerializer.class);
Capture<Request> requestCapture = newCapture();
Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put("name", "testTaxonomy.termName");
resultPropertyMaps.add(propertyMap);
Result result = new Result(resultPropertyMaps);
expect(termResourceProvider.getResourceById(capture(requestCapture))).andReturn(result);
expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
Response response = service.getTaxonomyTerm(null, uriInfo, taxonomyName, termName);
Request request = requestCapture.getValue();
Map<String, Object> requestProperties = request.getQueryProperties();
assertEquals(requestProperties.size(), 1);
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTaxonomy.termName");
assertEquals(response.getStatus(), 200);
assertEquals(response.getEntity(), "Taxonomy Term Get Response");
verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testGetTaxonomyTerms.
@Test
public void testGetTaxonomyTerms() throws Exception {
MetadataService metadataService = createStrictMock(MetadataService.class);
AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
UriInfo uriInfo = createNiceMock(UriInfo.class);
URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms?name:testTaxonomy.testTerm");
JsonSerializer serializer = createStrictMock(JsonSerializer.class);
Capture<Request> requestCapture = newCapture();
Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put("name", "testTaxonomy.testTerm");
resultPropertyMaps.add(propertyMap);
Result result = new Result(resultPropertyMaps);
// set mock expectations
expect(uriInfo.getRequestUri()).andReturn(uri);
expect(termResourceProvider.getResources(capture(requestCapture))).andReturn(result);
expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response");
expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
// instantiate service and invoke method being tested
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
Response response = service.getTaxonomyTerms(null, uriInfo, "testTaxonomy");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 1);
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy");
assertEquals(request.getQueryString(), "name:testTaxonomy.testTerm");
assertEquals(response.getStatus(), 200);
assertEquals(response.getEntity(), "Taxonomy Term Get Response");
verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testCreateTaxonomy.
@Test
public void testCreateTaxonomy() throws Exception {
MetadataService metadataService = createStrictMock(MetadataService.class);
AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class);
ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class);
ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class);
UriInfo uriInfo = createNiceMock(UriInfo.class);
URI uri = new URI("http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
Capture<Request> requestCapture = newCapture();
String body = "{ \"description\" : \"test description\" } ";
// set mock expectations
expect(uriInfo.getRequestUri()).andReturn(uri);
expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
taxonomyResourceProvider.createResource(capture(requestCapture));
replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
// instantiate service and invoke method being tested
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null);
Response response = service.createTaxonomy(body, null, uriInfo, "testTaxonomy");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 2);
assertEquals(request.getQueryProperties().get("name"), "testTaxonomy");
assertEquals(request.getQueryProperties().get("description"), "test description");
assertNull(request.getQueryString());
assertEquals(response.getStatus(), 201);
BaseService.Results createResults = (BaseService.Results) response.getEntity();
assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy");
assertEquals(createResults.status, 201);
verify(uriInfo, taxonomyResourceProvider, termResourceProvider);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class AtlasEntityQueryTest method testExecute_Collection_update.
@Test
public void testExecute_Collection_update() throws Exception {
AtlasGraph graph = createStrictMock(AtlasGraph.class);
QueryExpression expression = createStrictMock(QueryExpression.class);
ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class);
Request request = createStrictMock(Request.class);
GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class);
Pipe queryPipe = createStrictMock(Pipe.class);
Pipe expressionPipe = createStrictMock(Pipe.class);
Pipe notDeletedPipe = createStrictMock(Pipe.class);
GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class);
Vertex vertex1 = createStrictMock(Vertex.class);
VertexWrapper vertex1Wrapper = createStrictMock(VertexWrapper.class);
Capture<Long> modifiedTimestampCapture = newCapture();
List<Vertex> results = new ArrayList<>();
results.add(vertex1);
Map<String, Object> vertex1PropertyMap = new HashMap<>();
vertex1PropertyMap.put("prop1", "prop1.value1");
vertex1PropertyMap.put("prop2", "prop2.value1");
Map<String, Object> filteredVertex1PropertyMap = new HashMap<>();
filteredVertex1PropertyMap.put("prop1", "prop1.value1");
Map<String, Object> updateProperties = new HashMap<>();
updateProperties.put("prop3", "newValue");
// mock expectations
expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline);
expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline);
expect(initialPipeline.as("root")).andReturn(rootPipeline);
expect(expression.asPipe()).andReturn(expressionPipe);
expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline);
expect(expressionPipeline.back("root")).andReturn(rootPipeline);
expect(rootPipeline.toList()).andReturn(results);
graph.commit();
vertex1Wrapper.setProperty("prop3", "newValue");
vertex1Wrapper.setProperty(eq(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY), capture(modifiedTimestampCapture));
expect(vertex1Wrapper.getPropertyMap()).andReturn(vertex1PropertyMap);
expect(resourceDefinition.filterProperties(request, vertex1PropertyMap)).andReturn(filteredVertex1PropertyMap);
expect(resourceDefinition.resolveHref(filteredVertex1PropertyMap)).andReturn("/foo/bar");
expect(request.getCardinality()).andReturn(Request.Cardinality.COLLECTION);
replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
// end mock expectations
AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, initialPipeline, queryPipe, notDeletedPipe, graph, vertex1Wrapper);
long startTime = System.currentTimeMillis();
// invoke method being tested
Collection<Map<String, Object>> queryResults = query.execute(updateProperties);
long endTime = System.currentTimeMillis();
assertEquals(queryResults.size(), 1);
Map<String, Object> queryResultMap = queryResults.iterator().next();
assertEquals(queryResultMap.size(), 2);
assertEquals(queryResultMap.get("prop1"), "prop1.value1");
assertEquals(queryResultMap.get("href"), "/foo/bar");
long modifiedTimestamp = modifiedTimestampCapture.getValue();
assertTrue(modifiedTimestamp >= startTime && modifiedTimestamp <= endTime);
verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
}
Aggregations