Search in sources :

Example 36 with AtlasQuery

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

the class EntityResourceProviderTest method testCreateResources.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testCreateResources() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    // mock expectations
    replay(typeSystem, queryFactory, query);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("id", "1");
    Request userRequest = new InstanceRequest(requestProperties);
    EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.createResources(userRequest);
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) QueryFactory(org.apache.atlas.catalog.query.QueryFactory) Test(org.testng.annotations.Test)

Example 37 with AtlasQuery

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

the class EntityTagResourceProviderTest method testCreateResource.

@Test
public void testCreateResource() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    ResourceProvider termResourceProvider = createStrictMock(TermResourceProvider.class);
    Capture<Request> termRequestCapture = newCapture();
    Collection<Map<String, Object>> termQueryResult = new ArrayList<>();
    Map<String, Object> termQueryResultRow = new HashMap<>();
    termQueryResult.add(termQueryResultRow);
    termQueryResultRow.put("name", "testTaxonomy.termName");
    termQueryResultRow.put("type", "testTaxonomy.termName");
    termQueryResultRow.put("available_as_tag", true);
    termQueryResultRow.put("description", "term description");
    Result termResult = new Result(termQueryResult);
    // mock expectations
    expect(termResourceProvider.getResourceById(capture(termRequestCapture))).andReturn(termResult);
    Map<String, Object> tagProperties = new HashMap<>();
    tagProperties.put("name", "testTaxonomy.termName");
    tagProperties.put("description", "term description");
    typeSystem.createTraitInstance("11-22-33", "testTaxonomy.termName", tagProperties);
    replay(typeSystem, queryFactory, query, termResourceProvider);
    EntityTagResourceProvider provider = new TestEntityTagResourceProvider(typeSystem, termResourceProvider);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "testTaxonomy.termName");
    requestProperties.put("id", "11-22-33");
    Request userRequest = new InstanceRequest(requestProperties);
    provider.createResource(userRequest);
    Request termRequest = termRequestCapture.getValue();
    Map<String, Object> termRequestProps = termRequest.getQueryProperties();
    assertEquals(1, termRequestProps.size());
    TermPath termPath = (TermPath) termRequestProps.get("termPath");
    assertEquals("testTaxonomy.termName", termPath.getFullyQualifiedName());
    assertEquals(1, termRequest.getAdditionalSelectProperties().size());
    assertEquals("type", termRequest.getAdditionalSelectProperties().iterator().next());
    assertNull(termRequest.getQueryString());
    verify(typeSystem, queryFactory, query, termResourceProvider);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 38 with AtlasQuery

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

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

use of org.apache.atlas.catalog.query.AtlasQuery 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)

Aggregations

AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)47 QueryFactory (org.apache.atlas.catalog.query.QueryFactory)38 Test (org.testng.annotations.Test)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