Search in sources :

Example 26 with QueryFactory

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

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

the class TaxonomyResourceProviderTest method testUpdateResourceById_attemptNameChange.

@Test(expectedExceptions = InvalidPayloadException.class)
public void testUpdateResourceById_attemptNameChange() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> taxonomyRequestCapture = newCapture();
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "testTaxonomy");
    Map<String, Object> requestUpdateProperties = new HashMap<>();
    requestUpdateProperties.put("name", "notCurrentlySupported");
    Request userRequest = new InstanceRequest(requestProperties, requestUpdateProperties);
    Collection<Map<String, Object>> queryResult = new ArrayList<>();
    Map<String, Object> queryResultRow = new HashMap<>();
    queryResult.add(queryResultRow);
    queryResultRow.put("name", "testTaxonomy");
    // mock expectations
    // term update
    expect(queryFactory.createTaxonomyQuery(capture(taxonomyRequestCapture))).andReturn(query);
    expect(query.execute(requestUpdateProperties)).andReturn(queryResult);
    replay(typeSystem, queryFactory, query);
    // instantiate resource provider and invoke method being tested
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    provider.updateResourceById(userRequest);
    verify(typeSystem, queryFactory, query);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 28 with QueryFactory

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

the class EntityResourceProviderTest method testGetResource_404.

@Test(expectedExceptions = ResourceNotFoundException.class)
public void testGetResource_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.createEntityQuery(capture(requestCapture))).andReturn(query);
    expect(query.execute()).andReturn(emptyResponse);
    replay(typeSystem, queryFactory, query);
    EntityResourceProvider provider = new EntityResourceProvider(typeSystem);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("id", "1");
    Request request = new InstanceRequest(requestProperties);
    provider.getResourceById(request);
    verify(typeSystem, queryFactory, query);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) Test(org.testng.annotations.Test)

Example 29 with QueryFactory

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

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

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