Search in sources :

Example 6 with Request

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);
}
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 7 with Request

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);
}
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 8 with Request

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);
}
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)

Example 9 with Request

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);
}
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) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 10 with Request

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);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) Request(org.apache.atlas.catalog.Request) Pipe(com.tinkerpop.pipes.Pipe) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

Aggregations

Request (org.apache.atlas.catalog.Request)45 Test (org.testng.annotations.Test)45 CollectionRequest (org.apache.atlas.catalog.CollectionRequest)30 InstanceRequest (org.apache.atlas.catalog.InstanceRequest)30 HashMap (java.util.HashMap)12 Response (javax.ws.rs.core.Response)12 UriInfo (javax.ws.rs.core.UriInfo)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 URI (java.net.URI)10 TermPath (org.apache.atlas.catalog.TermPath)9 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 JsonSerializer (org.apache.atlas.catalog.JsonSerializer)6 Result (org.apache.atlas.catalog.Result)6 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)3 Pipe (com.tinkerpop.pipes.Pipe)3 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)3