TaxonomyResourceProvider extends BaseResourceProvider implements ResourceProvider { @Override public Result getResources(Request request) throws InvalidQueryException, ResourceNotFoundException { synchronized (TaxonomyResourceProvider.class) { createDefaultTaxonomyIfNeeded(); } return doGetResources(request); } TaxonomyResourceProvider(AtlasTypeSystem typeSystem); @Override Result getResourceById(Request request); @Override Result getResources(Request request); @Override void createResource(Request request); @Override Collection<String> createResources(Request request); @Override void deleteResourceById(Request request); @Override void updateResourceById(Request request); static final String DEFAULT_TAXONOMY_NAME; static final String DEFAULT_TAXONOMY_DESCRIPTION; static final String NAMESPACE_ATTRIBUTE_NAME; static final String TAXONOMY_TERM_TYPE; static final String TAXONOMY_NS; }
@Test public void testGetResources() throws Exception { AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class); QueryFactory queryFactory = createStrictMock(QueryFactory.class); AtlasQuery query = createStrictMock(AtlasQuery.class); Capture<Request> requestCapture = newCapture(); Collection<Map<String, Object>> queryResult = new ArrayList<>(); Map<String, Object> queryResultRow1 = new HashMap<>(); queryResult.add(queryResultRow1); queryResultRow1.put("mame", "taxonomyName1"); queryResultRow1.put("description", "test taxonomy description"); queryResultRow1.put("creation_time", "04/20/2016"); Map<String, Object> queryResultRow2 = new HashMap<>(); queryResult.add(queryResultRow2); queryResultRow2.put("mame", "taxonomyName2"); queryResultRow2.put("description", "test taxonomy description 2"); queryResultRow2.put("creation_time", "04/21/2016"); expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); replay(typeSystem, queryFactory, query); TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); Request userRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), "name:taxonomy*"); Result result = provider.getResources(userRequest); assertEquals(2, result.getPropertyMaps().size()); assertTrue(result.getPropertyMaps().contains(queryResultRow1)); assertTrue(result.getPropertyMaps().contains(queryResultRow2)); Request request = requestCapture.getValue(); assertEquals("name:taxonomy*", request.getQueryString()); assertEquals(0, request.getAdditionalSelectProperties().size()); assertEquals(0, request.getQueryProperties().size()); verify(typeSystem, queryFactory, query); }
@Test public void testGetResources_noResults() throws Exception { AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class); QueryFactory queryFactory = createStrictMock(QueryFactory.class); AtlasQuery query = createStrictMock(AtlasQuery.class); Capture<Request> requestCapture = newCapture(); Collection<Map<String, Object>> queryResult = new ArrayList<>(); expect(queryFactory.createTaxonomyQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); replay(typeSystem, queryFactory, query); TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); Request userRequest = new CollectionRequest(Collections.<String, Object>emptyMap(), "name:taxonomy*"); Result result = provider.getResources(userRequest); assertEquals(0, result.getPropertyMaps().size()); Request request = requestCapture.getValue(); assertEquals("name:taxonomy*", request.getQueryString()); assertEquals(0, request.getAdditionalSelectProperties().size()); assertEquals(0, request.getQueryProperties().size()); verify(typeSystem, queryFactory, query); }