use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyResourceDefinitionTest method testFilterProperties_Instance.
@Test
public void testFilterProperties_Instance() {
Map<String, Object> resourceProps = new HashMap<>();
resourceProps.put("id", "111-222-333");
resourceProps.put("name", "nameVal");
resourceProps.put("type", "someType");
resourceProps.put("foo", "fooVal");
resourceProps.put("bar", "barVal");
resourceProps.put("description", "desc");
resourceProps.put("creation_time", "2016:10:10");
Request request = new InstanceRequest(resourceProps);
request.addAdditionalSelectProperties(Collections.singleton("foo"));
ResourceDefinition taxonomyDefinition = new TaxonomyResourceDefinition();
Map<String, Object> filteredProperties = taxonomyDefinition.filterProperties(request, resourceProps);
assertEquals(filteredProperties.size(), 4);
// registered collection props
assertTrue(filteredProperties.containsKey("name"));
assertTrue(filteredProperties.containsKey("description"));
assertTrue(filteredProperties.containsKey("creation_time"));
// added prop
assertTrue(filteredProperties.containsKey("foo"));
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyResourceDefinitionTest method testValidate_missingName.
@Test(expectedExceptions = InvalidPayloadException.class)
public void testValidate_missingName() throws Exception {
Map<String, Object> properties = new HashMap<>();
properties.put("description", "foo");
Request request = new InstanceRequest(properties);
ResourceDefinition taxonomyDefinition = new TaxonomyResourceDefinition();
taxonomyDefinition.validateCreatePayload(request);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testDeleteTerm.
@Test
public void testDeleteTerm() 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");
Capture<Request> requestCapture = newCapture();
// set mock expectations
expect(uriInfo.getRequestUri()).andReturn(uri);
termResourceProvider.deleteResourceById(capture(requestCapture));
expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition");
replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider);
// instantiate service and invoke method being tested
TestTaxonomyService service = new TestTaxonomyService(metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, null);
Response response = service.deleteTerm(null, uriInfo, "testTaxonomy", "testTerm");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 1);
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm");
assertNull(request.getQueryString());
assertEquals(response.getStatus(), 200);
BaseService.Results createResults = (BaseService.Results) response.getEntity();
assertEquals(createResults.href, "http://localhost:21000/api/atlas/v1/taxonomies/testTaxonomy/terms/testTerm");
assertEquals(createResults.status, 200);
verify(uriInfo, taxonomyResourceProvider, termResourceProvider);
}
use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.
the class TaxonomyServiceTest method testGetTaxonomies.
@Test
public void testGetTaxonomies() 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?name:testTaxonomy");
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);
// set mock expectations
expect(uriInfo.getRequestUri()).andReturn(uri);
expect(taxonomyResourceProvider.getResources(capture(requestCapture))).andReturn(result);
expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy 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.getTaxonomies(null, uriInfo);
Request request = requestCapture.getValue();
assertTrue(request.getQueryProperties().isEmpty());
assertEquals(request.getQueryString(), "name:testTaxonomy");
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 testGetSubTerms_instance.
@Test
public void testGetSubTerms_instance() 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");
JsonSerializer serializer = createStrictMock(JsonSerializer.class);
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");
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("testTerm2");
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, 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");
Request request = requestCapture.getValue();
assertEquals(request.getQueryProperties().size(), 1);
TermPath termPath = (TermPath) request.getQueryProperties().get("termPath");
assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2");
assertNull(request.getQueryString());
assertEquals(response.getStatus(), 200);
assertEquals(response.getEntity(), "Taxonomy Term Get Response");
verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3);
}
Aggregations