TermResourceProvider extends BaseResourceProvider implements ResourceProvider { public Result getResources(Request request) throws InvalidQueryException, ResourceNotFoundException { TermPath termPath = request.getProperty("termPath"); String queryString = doQueryStringConversions(termPath, request.getQueryString()); Request queryRequest = new CollectionRequest(request.getQueryProperties(), queryString); AtlasQuery atlasQuery = queryFactory.createTermQuery(queryRequest); Collection<Map<String, Object>> result = atlasQuery.execute(); return new Result(result); } TermResourceProvider(AtlasTypeSystem typeSystem); @Override Result getResourceById(Request request); Result getResources(Request request); void createResource(Request request); @Override Collection<String> createResources(Request request); @Override void updateResourceById(Request request); @Override void deleteResourceById(Request request);  }
@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(); TermPath termPath = new TermPath("testTaxonomy", null); Collection<Map<String, Object>> queryResult = new ArrayList<>(); Map<String, Object> queryResultRow1 = new HashMap<>(); queryResult.add(queryResultRow1); queryResultRow1.put("name", "testTaxonomy.termName"); queryResultRow1.put("description", "test term description"); queryResultRow1.put("creation_time", "04/20/2016"); queryResultRow1.put("acceptable_use", "anything"); queryResultRow1.put("available_as_tag", true); Map<String, Object> hierarchyMap = new HashMap<>(); queryResultRow1.put("hierarchy", hierarchyMap); hierarchyMap.put("path", "/"); hierarchyMap.put("short_name", "termName"); hierarchyMap.put("taxonomy", "testTaxonomy"); Map<String, Object> queryResultRow2 = new HashMap<>(); queryResult.add(queryResultRow2); queryResultRow2.put("name", "testTaxonomy.termName2"); queryResultRow2.put("description", "test term 2 description"); queryResultRow2.put("creation_time", "04/21/2016"); queryResultRow2.put("acceptable_use", "anything"); queryResultRow2.put("available_as_tag", true); Map<String, Object> hierarchyMap2 = new HashMap<>(); queryResultRow2.put("hierarchy", hierarchyMap2); hierarchyMap2.put("path", "/"); hierarchyMap2.put("short_name", "termName2"); hierarchyMap2.put("taxonomy", "testTaxonomy"); expect(queryFactory.createTermQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); replay(typeSystem, queryFactory, query); TermResourceProvider provider = new TermResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); Map<String, Object> requestProperties = new HashMap<>(); requestProperties.put("termPath", termPath); Request userRequest = new CollectionRequest(requestProperties, "name:taxonomy*"); Result result = provider.getResources(userRequest); assertEquals(result.getPropertyMaps().size(), 2); assertTrue(result.getPropertyMaps().contains(queryResultRow1)); assertTrue(result.getPropertyMaps().contains(queryResultRow2)); Request request = requestCapture.getValue(); assertEquals(request.getQueryString(), "name:taxonomy*"); assertEquals(request.getAdditionalSelectProperties().size(), 0); assertEquals(request.getQueryProperties().size(), 1); 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(); TermPath termPath = new TermPath("testTaxonomy", "termName"); Collection<Map<String, Object>> queryResult = new ArrayList<>(); expect(queryFactory.createTermQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); replay(typeSystem, queryFactory, query); TermResourceProvider provider = new TermResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); Map<String, Object> requestProperties = new HashMap<>(); requestProperties.put("termPath", termPath); Request userRequest = new CollectionRequest(requestProperties, "name:taxonomy*"); Result result = provider.getResources(userRequest); assertEquals(0, result.getPropertyMaps().size()); Request request = requestCapture.getValue(); assertEquals(request.getQueryString(), "name:taxonomy*"); assertEquals(request.getAdditionalSelectProperties().size(), 0); assertEquals(request.getQueryProperties().size(), 1); verify(typeSystem, queryFactory, query); }