use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class QueryFactoryTest method testCreateEntityTagQuery.
@Test
public void testCreateEntityTagQuery() throws Exception {
Map<String, Object> requestProps = new HashMap<>();
requestProps.put("id", "entity_id");
requestProps.put("name", "test_taxonomy.term1");
Request request = new InstanceRequest(requestProps);
QueryFactory factory = new QueryFactory();
AtlasEntityTagQuery query = (AtlasEntityTagQuery) factory.createEntityTagQuery(request);
QueryExpression queryExpression = query.getQueryExpression();
assertEquals(queryExpression.getClass(), TermQueryExpression.class);
assertEquals(queryExpression.getField(), "name");
assertEquals(queryExpression.getExpectedValue(), "test_taxonomy.term1");
assertEquals(query.getRequest(), request);
assertEquals(query.getResourceDefinition().getClass(), EntityTagResourceDefinition.class);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class QueryFactoryTest method testCollectionQuery_WildcardQuery.
@Test
public void testCollectionQuery_WildcardQuery() throws Exception {
String queryString = "name:ta?onomy";
Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString);
QueryFactory factory = new QueryFactory();
AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request);
QueryExpression queryExpression = query.getQueryExpression();
assertEquals(queryExpression.getClass(), WildcardQueryExpression.class);
assertEquals(queryExpression.getField(), "name");
assertEquals(queryExpression.getExpectedValue(), "ta?onomy");
assertEquals(query.getRequest(), request);
assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy");
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testGetTaxonomy.
@Test
public void testGetTaxonomy() throws Exception {
String taxonomyName = "testTaxonomy";
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");
resultPropertyMaps.add(propertyMap);
Result result = new Result(resultPropertyMaps);
expect(taxonomyResourceProvider.getResourceById(capture(requestCapture))).andReturn(result);
expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Get Response");
replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer);
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
Response response = service.getTaxonomy(null, uriInfo, taxonomyName);
Request request = requestCapture.getValue();
Map<String, Object> requestProperties = request.getQueryProperties();
assertEquals(requestProperties.size(), 1);
assertEquals(requestProperties.get("name"), taxonomyName);
assertEquals(response.getStatus(), 200);
assertEquals(response.getEntity(), "Taxonomy Get Response");
verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testCreateTerm.
@Test
public void testCreateTerm() 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");
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.createTerm(body, null, uriInfo, taxonomyName, termName);
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");
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");
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 testGetSubTerms_collection.
@Test
public void testGetSubTerms_collection() 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/testTerm/terms/testTerm2/terms?name:testTaxonomy.testTerm.testTerm2.testTerm3");
JsonSerializer serializer = createStrictMock(JsonSerializer.class);
// would actually be more segments but at this time only the last segment is used
PathSegment segment1 = createNiceMock(PathSegment.class);
PathSegment segment2 = createNiceMock(PathSegment.class);
PathSegment segment3 = createNiceMock(PathSegment.class);
Capture<Request> requestCapture = newCapture();
Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>();
Map<String, Object> propertyMap = new HashMap<>();
propertyMap.put("name", "testTaxonomy.testTerm.testTerm2.testTerm3");
resultPropertyMaps.add(propertyMap);
Result result = new Result(resultPropertyMaps);
// set mock expectations
expect(uriInfo.getRequestUri()).andReturn(uri);
expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3));
expect(segment3.getPath()).andReturn("terms");
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, segment1, segment2, segment3);
// instantiate service and invoke method being tested
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer);
Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2/terms");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 1);
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2.");
assertEquals(request.getQueryString(), "name:testTaxonomy.testTerm.testTerm2.testTerm3");
assertEquals(response.getStatus(), 200);
assertEquals(response.getEntity(), "Taxonomy Term Get Response");
verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
}
Aggregations