ForQuery extends TraversData { @Override public void traverse(@Nonnull BindingContext context, FilterBy filter, @Nonnull List<Action> actions, @Nonnull StringBuilder output, boolean dryRun) throws PersistenceException, AecuException { ResourceResolver resourceResolver = context.getResolver(); Iterator<Resource> queryResult = resourceResolver.findResources(query, queryType); while (queryResult.hasNext()) { Resource resource = queryResult.next(); applyActionsOnResource(resource, filter, actions, output, dryRun); } } ForQuery(@Nonnull String query, @Nonnull String queryType); @Override void traverse(@Nonnull BindingContext context, FilterBy filter, @Nonnull List<Action> actions,
            @Nonnull StringBuilder output, boolean dryRun);  }
@Test public void traverse() throws PersistenceException, AecuException { ForQuery traverser = new ForQuery(QUERY, TYPE); traverser.traverse(context, null, actions, output, false); verify(action, times(1)).doAction(resource); verify(resolver, never()).commit(); }
@Test public void traverse_many() throws PersistenceException, AecuException { List<Resource> results = new ArrayList<>(); for (int i = 0; i < 1500; i++) { results.add(resource); } when(resolver.findResources(QUERY, TYPE)).thenReturn(results.iterator()); ForQuery traverser = new ForQuery(QUERY, TYPE); traverser.traverse(context, null, actions, output, false); verify(action, times(1500)).doAction(resource); verify(resolver, times(1)).commit(); }
@Test public void traverse_dry() throws PersistenceException, AecuException { ForQuery traverser = new ForQuery(QUERY, TYPE); traverser.traverse(context, null, actions, output, true); verify(action, times(1)).doAction(resource); verify(resolver, never()).commit(); }