Search in sources :

Example 11 with MetadataService

use of org.apache.atlas.services.MetadataService in project incubator-atlas by apache.

the class TaxonomyServiceTest method testDeleteSubTerm.

@Test
public void testDeleteSubTerm() 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");
    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.deleteSubTerm(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);
    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, 200);
    verify(uriInfo, taxonomyResourceProvider, termResourceProvider);
}
Also used : Request(org.apache.atlas.catalog.Request) URI(java.net.URI) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) TermPath(org.apache.atlas.catalog.TermPath) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 12 with MetadataService

use of org.apache.atlas.services.MetadataService in project incubator-atlas by apache.

the class TaxonomyServiceTest method testDeleteTaxonomy.

@Test
public void testDeleteTaxonomy() 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();
    // set mock expectations
    expect(uriInfo.getRequestUri()).andReturn(uri);
    taxonomyResourceProvider.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.deleteTaxonomy(null, uriInfo, "testTaxonomy");
    Request request = requestCapture.getValue();
    assertEquals(request.getQueryProperties().size(), 1);
    assertEquals(request.getQueryProperties().get("name"), "testTaxonomy");
    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");
    assertEquals(createResults.status, 200);
    verify(uriInfo, taxonomyResourceProvider, termResourceProvider);
}
Also used : Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) Request(org.apache.atlas.catalog.Request) URI(java.net.URI) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Aggregations

Response (javax.ws.rs.core.Response)12 UriInfo (javax.ws.rs.core.UriInfo)12 Request (org.apache.atlas.catalog.Request)12 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)12 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)12 MetadataService (org.apache.atlas.services.MetadataService)12 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)12 Test (org.testng.annotations.Test)12 URI (java.net.URI)10 TermPath (org.apache.atlas.catalog.TermPath)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 JsonSerializer (org.apache.atlas.catalog.JsonSerializer)6 Result (org.apache.atlas.catalog.Result)6 PathSegment (javax.ws.rs.core.PathSegment)2