Search in sources :

Example 31 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class QueryFactoryTest method testCreateEntityQuery.

@Test
public void testCreateEntityQuery() throws Exception {
    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put("id", "foo");
    Request request = new InstanceRequest(requestProps);
    QueryFactory factory = new QueryFactory();
    AtlasEntityQuery query = (AtlasEntityQuery) factory.createEntityQuery(request);
    QueryExpression queryExpression = query.getQueryExpression();
    assertEquals(queryExpression.getClass(), TermQueryExpression.class);
    assertEquals(queryExpression.getField(), "id");
    assertEquals(queryExpression.getExpectedValue(), "foo");
    assertEquals(query.getRequest(), request);
    assertEquals(query.getResourceDefinition().getClass(), EntityResourceDefinition.class);
}
Also used : HashMap(java.util.HashMap) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Test(org.testng.annotations.Test)

Example 32 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class QueryFactoryTest method testCollectionQuery_TermRangeQuery.

@Test
public void testCollectionQuery_TermRangeQuery() throws Exception {
    String queryString = "creation_time:[2013-01-01:07:29:00 TO 2017-01-02]";
    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(), TermRangeQueryExpression.class);
    assertEquals(queryExpression.getField(), "creation_time");
    assertEquals(query.getRequest(), request);
    assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy");
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) Test(org.testng.annotations.Test)

Example 33 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class QueryFactoryTest method testCollectionQuery_PrefixQuery.

@Test
public void testCollectionQuery_PrefixQuery() throws Exception {
    String queryString = "name:t*";
    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(), PrefixQueryExpression.class);
    assertEquals(queryExpression.getField(), "name");
    assertEquals(queryExpression.getExpectedValue(), "t");
    assertEquals(query.getRequest(), request);
    assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy");
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) Test(org.testng.annotations.Test)

Example 34 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class AtlasEntityQueryTest method testExecute_Collection.

//todo: add tests for instance query and getInitialPipeline()
@Test
public void testExecute_Collection() 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);
    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");
    // 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();
    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);
    // invoke method being tested
    Collection<Map<String, Object>> queryResults = query.execute();
    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");
    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)

Example 35 with Request

use of org.apache.atlas.catalog.Request in project incubator-atlas by apache.

the class QueryFactoryTest method testCreateTaxonomyQuery.

@Test
public void testCreateTaxonomyQuery() throws Exception {
    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put("name", "test_taxonomy");
    Request request = new InstanceRequest(requestProps);
    QueryFactory factory = new QueryFactory();
    AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request);
    QueryExpression queryExpression = query.getQueryExpression();
    assertEquals(queryExpression.getClass(), TermQueryExpression.class);
    assertEquals(queryExpression.getField(), "name");
    assertEquals(queryExpression.getExpectedValue(), "test_taxonomy");
    assertEquals(query.getRequest(), request);
    assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy");
}
Also used : HashMap(java.util.HashMap) CollectionRequest(org.apache.atlas.catalog.CollectionRequest) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Request(org.apache.atlas.catalog.Request) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) 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