Search in sources :

Example 6 with ResourceDefinition

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

the class TermResourceProviderTest method testCreateResource.

@Test
public void testCreateResource() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<ResourceDefinition> resourceDefinitionCapture = newCapture();
    ResourceProvider taxonomyResourceProvider = createStrictMock(TaxonomyResourceProvider.class);
    Capture<Request> taxonomyRequestCapture = newCapture();
    Collection<Map<String, Object>> taxonomyQueryResult = new ArrayList<>();
    Map<String, Object> taxonomyQueryResultRow = new HashMap<>();
    taxonomyQueryResult.add(taxonomyQueryResultRow);
    taxonomyQueryResultRow.put("name", "testTaxonomy");
    taxonomyQueryResultRow.put("id", "11-22-33");
    Result taxonomyResult = new Result(taxonomyQueryResult);
    Map<String, Object> expectedRequestProps = new HashMap<>();
    expectedRequestProps.put("name", "testTaxonomy.termName");
    // when not specified, the default value of 'true' should be set
    expectedRequestProps.put("available_as_tag", true);
    // mock expectations
    expect(taxonomyResourceProvider.getResourceById(capture(taxonomyRequestCapture))).andReturn(taxonomyResult);
    typeSystem.createTraitType(capture(resourceDefinitionCapture), eq("testTaxonomy.termName"), EasyMock.<String>isNull());
    typeSystem.createTraitInstance("11-22-33", "testTaxonomy.termName", expectedRequestProps);
    replay(typeSystem, queryFactory, query, taxonomyResourceProvider);
    TermResourceProvider provider = new TestTermResourceProvider(typeSystem, taxonomyResourceProvider);
    provider.setQueryFactory(queryFactory);
    TermPath termPath = new TermPath("testTaxonomy", "termName");
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("termPath", termPath);
    Request userRequest = new InstanceRequest(requestProperties);
    provider.createResource(userRequest);
    Request taxonomyRequest = taxonomyRequestCapture.getValue();
    Map<String, Object> taxonomyRequestProps = taxonomyRequest.getQueryProperties();
    assertEquals(taxonomyRequestProps.size(), 1);
    assertEquals(taxonomyRequestProps.get("name"), "testTaxonomy");
    assertEquals(taxonomyRequest.getAdditionalSelectProperties().size(), 1);
    assertEquals(taxonomyRequest.getAdditionalSelectProperties().iterator().next(), "id");
    assertNull(taxonomyRequest.getQueryString());
    ResourceDefinition resourceDefinition = resourceDefinitionCapture.getValue();
    assertEquals(resourceDefinition.getTypeName(), "Term");
    verify(typeSystem, queryFactory, query, taxonomyResourceProvider);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 7 with ResourceDefinition

use of org.apache.atlas.catalog.definition.ResourceDefinition 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 8 with ResourceDefinition

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

the class TaxonomyResourceProviderTest method testDeleteResourceById.

@Test
public void testDeleteResourceById() throws Exception {
    TermResourceProvider termResourceProvider = createStrictMock(TermResourceProvider.class);
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> getRequestCapture = newCapture();
    Capture<TermPath> termPathCapture = newCapture();
    Capture<ResourceDefinition> resourceDefinitionCapture = newCapture();
    Capture<Request> deleteRequestCapture = newCapture();
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    Map<String, Object> queryResultRow = new HashMap<>();
    queryResult.add(queryResultRow);
    queryResultRow.put("name", "testTaxonomy");
    queryResultRow.put("id", "111-222-333");
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(getRequestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    termResourceProvider.deleteChildren(eq("111-222-333"), capture(termPathCapture));
    typeSystem.deleteEntity(capture(resourceDefinitionCapture), capture(deleteRequestCapture));
    replay(termResourceProvider, typeSystem, queryFactory, query);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem, termResourceProvider);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "testTaxonomy");
    Request userRequest = new InstanceRequest(requestProperties);
    // invoke method being tested
    provider.deleteResourceById(userRequest);
    Request getRequest = getRequestCapture.getValue();
    assertNull(getRequest.getQueryString());
    assertEquals(getRequest.getAdditionalSelectProperties().size(), 1);
    assertTrue(getRequest.getAdditionalSelectProperties().contains("id"));
    assertEquals(getRequest.getQueryProperties().get("name"), "testTaxonomy");
    Request deleteRequest = deleteRequestCapture.getValue();
    assertNull(deleteRequest.getQueryString());
    assertEquals(deleteRequest.getAdditionalSelectProperties().size(), 1);
    assertTrue(deleteRequest.getAdditionalSelectProperties().contains("id"));
    assertEquals(deleteRequest.getQueryProperties().get("name"), "testTaxonomy");
    ResourceDefinition resourceDefinition = resourceDefinitionCapture.getValue();
    assertTrue(resourceDefinition instanceof TaxonomyResourceDefinition);
    verify(termResourceProvider, typeSystem, queryFactory, query);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) TaxonomyResourceDefinition(org.apache.atlas.catalog.definition.TaxonomyResourceDefinition) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) TaxonomyResourceDefinition(org.apache.atlas.catalog.definition.TaxonomyResourceDefinition) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 9 with ResourceDefinition

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

the class TaxonomyResourceProviderTest method testCreateResource.

@Test
public void testCreateResource() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<ResourceDefinition> resourceDefinitionCapture = newCapture();
    Capture<Request> requestCapture = newCapture();
    // empty response indicates that resource doesn't already exist
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(queryResult);
    expect(typeSystem.createEntity(capture(resourceDefinitionCapture), capture(requestCapture))).andReturn("testGuid");
    replay(typeSystem, queryFactory, query);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "taxonomyName");
    Request userRequest = new InstanceRequest(requestProperties);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResource(userRequest);
    assertEquals(new TaxonomyResourceDefinition().getTypeName(), resourceDefinitionCapture.getValue().getTypeName());
    Request request = requestCapture.getValue();
    assertNull(request.getQueryString());
    assertEquals(requestProperties, request.getQueryProperties());
    verify(typeSystem, queryFactory, query);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) TaxonomyResourceDefinition(org.apache.atlas.catalog.definition.TaxonomyResourceDefinition) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) TaxonomyResourceDefinition(org.apache.atlas.catalog.definition.TaxonomyResourceDefinition) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 10 with ResourceDefinition

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

the class VertexWrapperTest method testGetVertex.

@Test
public void testGetVertex() {
    Vertex v = createStrictMock(Vertex.class);
    ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class);
    // just return null for these because they aren't used in this test
    expect(resourceDefinition.getPropertyMapper()).andReturn(null);
    expect(resourceDefinition.getPropertyValueFormatters()).andReturn(null);
    expect(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY)).andReturn("testType");
    replay(v, resourceDefinition);
    VertexWrapper vWrapper = new VertexWrapper(v, resourceDefinition);
    assertEquals(vWrapper.getVertex(), v);
    verify(v, resourceDefinition);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) Test(org.testng.annotations.Test)

Aggregations

ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)10 Test (org.testng.annotations.Test)10 AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)5 QueryFactory (org.apache.atlas.catalog.query.QueryFactory)5 Vertex (com.tinkerpop.blueprints.Vertex)4 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)3 Pipe (com.tinkerpop.pipes.Pipe)3 Request (org.apache.atlas.catalog.Request)3 TaxonomyResourceDefinition (org.apache.atlas.catalog.definition.TaxonomyResourceDefinition)3 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)3 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)2 ResourceAlreadyExistsException (org.apache.atlas.catalog.exception.ResourceAlreadyExistsException)1