Search in sources :

Example 31 with QueryFactory

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

the class TermResourceProviderTest method testGetResourceById_404.

@Test(expectedExceptions = ResourceNotFoundException.class)
public void testGetResourceById_404() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> requestCapture = newCapture();
    // empty response should result in a ResourceNotFoundException
    Collection<Map<String, Object>> emptyResponse = new ArrayList<>();
    // mock expectations
    expect(queryFactory.createTermQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(emptyResponse);
    replay(typeSystem, queryFactory, query);
    TermResourceProvider provider = new TermResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("termPath", new TermPath("taxonomyName.badTermName"));
    Request request = new InstanceRequest(requestProperties);
    provider.getResourceById(request);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 32 with QueryFactory

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

the class TermResourceProviderTest method testCreateResource_invalidRequest__noName.

@Test(expectedExceptions = InvalidPayloadException.class)
public void testCreateResource_invalidRequest__noName() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    // null term name should result in InvalidPayloadException
    TermPath termPath = new TermPath("testTaxonomy", null);
    // mock expectations
    replay(typeSystem, queryFactory, query);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("termPath", termPath);
    Request userRequest = new InstanceRequest(requestProperties);
    TermResourceProvider provider = new TermResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResource(userRequest);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Example 33 with QueryFactory

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

the class EntityTagResourceProviderTest method testCreateResource_invalidRequest__noName.

@Test(expectedExceptions = InvalidPayloadException.class)
public void testCreateResource_invalidRequest__noName() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    replay(typeSystem, queryFactory, query);
    Map<String, Object> requestProperties = new HashMap<>();
    // missing name name should result in InvalidPayloadException
    requestProperties.put("description", "description");
    Request userRequest = new InstanceRequest(requestProperties);
    EntityTagResourceProvider provider = new EntityTagResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResource(userRequest);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Example 34 with QueryFactory

use of org.apache.atlas.catalog.query.QueryFactory 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 35 with QueryFactory

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

the class TaxonomyResourceProviderTest method testCreateResource_invalidRequest__noName.

@Test(expectedExceptions = InvalidPayloadException.class)
public void testCreateResource_invalidRequest__noName() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    // mock expectations
    replay(typeSystem, queryFactory, query);
    // taxonomy create request must contain 'name' property
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("description", "test");
    Request userRequest = new InstanceRequest(requestProperties);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResource(userRequest);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Aggregations

QueryFactory (org.apache.atlas.catalog.query.QueryFactory)40 Test (org.testng.annotations.Test)40 AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)38 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)5 TaxonomyResourceDefinition (org.apache.atlas.catalog.definition.TaxonomyResourceDefinition)3 ResourceAlreadyExistsException (org.apache.atlas.catalog.exception.ResourceAlreadyExistsException)2 ResourceNotFoundException (org.apache.atlas.catalog.exception.ResourceNotFoundException)1