Search in sources :

Example 31 with AtlasQuery

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

the class TaxonomyResourceProvider method updateResourceById.

@Override
public void updateResourceById(Request request) throws ResourceNotFoundException, InvalidPayloadException {
    resourceDefinition.validateUpdatePayload(request);
    AtlasQuery atlasQuery;
    try {
        atlasQuery = queryFactory.createTaxonomyQuery(request);
    } catch (InvalidQueryException e) {
        throw new CatalogRuntimeException("Unable to compile internal Term query: " + e, e);
    }
    synchronized (TaxonomyResourceProvider.class) {
        createDefaultTaxonomyIfNeeded();
        if (atlasQuery.execute(request.getUpdateProperties()).isEmpty()) {
            throw new ResourceNotFoundException(String.format("Taxonomy '%s' not found.", request.getQueryProperties().get("name")));
        }
    }
}
Also used : AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery)

Example 32 with AtlasQuery

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

the class TaxonomyResourceProviderTest method testDeleteResourceById_404.

@Test(expectedExceptions = ResourceNotFoundException.class)
public void testDeleteResourceById_404() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> getRequestCapture = newCapture();
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(getRequestCapture))).andReturn(query);
    expect(query.execute()).andThrow(new ResourceNotFoundException("test msg"));
    replay(typeSystem, queryFactory, query);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem, null);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "badName");
    Request userRequest = new InstanceRequest(requestProperties);
    // invoke method being tested
    provider.deleteResourceById(userRequest);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) ResourceNotFoundException(org.apache.atlas.catalog.exception.ResourceNotFoundException) Test(org.testng.annotations.Test)

Example 33 with AtlasQuery

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

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

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

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