EntityTagResourceProvider extends BaseResourceProvider implements ResourceProvider { @Override public Result getResources(Request request) throws InvalidQueryException, ResourceNotFoundException { AtlasQuery atlasQuery = queryFactory.createEntityTagQuery(request); return new Result(atlasQuery.execute()); } EntityTagResourceProvider(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);  }
@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("name", "testTaxonomy.termName"); queryResultRow1.put("description", "test term description"); Map<String, Object> queryResultRow2 = new HashMap<>(); queryResult.add(queryResultRow2); queryResultRow2.put("name", "testTaxonomy.termName2"); queryResultRow2.put("description", "test term 2 description"); expect(queryFactory.createEntityTagQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); replay(typeSystem, queryFactory, query); EntityTagResourceProvider provider = new EntityTagResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); Map<String, Object> requestProperties = new HashMap<>(); requestProperties.put("id", "1"); Request userRequest = new CollectionRequest(requestProperties, "name:testTaxonomy.*"); 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:testTaxonomy.*", request.getQueryString()); assertEquals(0, request.getAdditionalSelectProperties().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.createEntityTagQuery(capture(requestCapture))).andReturn(query); expect(query.execute()).andReturn(queryResult); replay(typeSystem, queryFactory, query); EntityTagResourceProvider provider = new EntityTagResourceProvider(typeSystem); provider.setQueryFactory(queryFactory); Map<String, Object> requestProperties = new HashMap<>(); requestProperties.put("id", "1"); Request userRequest = new CollectionRequest(requestProperties, "name:testTaxonomy.*"); Result result = provider.getResources(userRequest); assertEquals(0, result.getPropertyMaps().size()); Request request = requestCapture.getValue(); assertEquals("name:testTaxonomy.*", request.getQueryString()); assertEquals(0, request.getAdditionalSelectProperties().size()); verify(typeSystem, queryFactory, query); }