Search in sources :

Example 1 with TermPath

use of org.apache.atlas.catalog.TermPath 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);
}
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 2 with TermPath

use of org.apache.atlas.catalog.TermPath 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);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.atlas.catalog.Request) ArrayList(java.util.ArrayList) JsonSerializer(org.apache.atlas.catalog.JsonSerializer) PathSegment(javax.ws.rs.core.PathSegment) URI(java.net.URI) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Result(org.apache.atlas.catalog.Result) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) TermPath(org.apache.atlas.catalog.TermPath) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 3 with TermPath

use of org.apache.atlas.catalog.TermPath 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);
}
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 4 with TermPath

use of org.apache.atlas.catalog.TermPath 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);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.atlas.catalog.Request) ArrayList(java.util.ArrayList) JsonSerializer(org.apache.atlas.catalog.JsonSerializer) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Result(org.apache.atlas.catalog.Result) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) TermPath(org.apache.atlas.catalog.TermPath) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 5 with TermPath

use of org.apache.atlas.catalog.TermPath 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);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.atlas.catalog.Request) ArrayList(java.util.ArrayList) JsonSerializer(org.apache.atlas.catalog.JsonSerializer) URI(java.net.URI) MetadataService(org.apache.atlas.services.MetadataService) AtlasTypeDefStore(org.apache.atlas.store.AtlasTypeDefStore) Result(org.apache.atlas.catalog.Result) Response(javax.ws.rs.core.Response) TaxonomyResourceProvider(org.apache.atlas.catalog.TaxonomyResourceProvider) ResourceProvider(org.apache.atlas.catalog.ResourceProvider) TermPath(org.apache.atlas.catalog.TermPath) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Aggregations

TermPath (org.apache.atlas.catalog.TermPath)13 Request (org.apache.atlas.catalog.Request)9 Test (org.testng.annotations.Test)9 Response (javax.ws.rs.core.Response)8 UriInfo (javax.ws.rs.core.UriInfo)8 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)8 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)8 MetadataService (org.apache.atlas.services.MetadataService)8 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)8 URI (java.net.URI)7 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 JsonSerializer (org.apache.atlas.catalog.JsonSerializer)4 Result (org.apache.atlas.catalog.Result)4 PipeFunction (com.tinkerpop.pipes.PipeFunction)2 PathSegment (javax.ws.rs.core.PathSegment)2 ResourceComparator (org.apache.atlas.catalog.ResourceComparator)2 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)2 Projection (org.apache.atlas.catalog.projection.Projection)2