Search in sources :

Example 1 with TaxonomyResourceDefinition

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

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

Aggregations

ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)2 TaxonomyResourceDefinition (org.apache.atlas.catalog.definition.TaxonomyResourceDefinition)2 AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)2 QueryFactory (org.apache.atlas.catalog.query.QueryFactory)2 Test (org.testng.annotations.Test)2