AecuServiceMBeanImpl extends AnnotatedStandardMBean implements AecuServiceMBean { @Override public String executeWithHistory(String path) throws AecuException { HistoryEntry history = aecuService.createHistoryEntry(); List<String> files = aecuService.getFiles(path); StringBuilder result = new StringBuilder("Found " + files.size() + " files to execute\n\n"); try (ResourceResolver resolver = serviceResourceResolver.getAdminResourceResolver()) { Session session = resolver.adaptTo(Session.class); for (String file : files) { result.append(file + "\n"); HookExecutionHistory executionHistory = new HookExecutionHistory(session, file); if (!file.endsWith(AecuTrackerListener.ALWAYS_SUFFIX) && executionHistory.hasBeenExecutedBefore()) { result.append("Skipped due to history\n\n"); continue; } ExecutionResult singleResult = aecuService.execute(file); executionHistory.setExecuted(); aecuService.storeExecutionInHistory(history, singleResult); result.append(singleResult.toString()); result.append("\n\n"); } } catch (LoginException e) { throw new AecuException(e.getMessage(), e); } aecuService.finishHistoryEntry(history); return result.toString(); } AecuServiceMBeanImpl(); @Override String getVersion(); @Override List<String> getFiles(String path); @Override String execute(String path); @Override String executeWithHistory(String path); @Override String getHistory(int start, int count);  }
@Test public void executeWithHistory() throws AecuException, LoginException { ExecutionResult result = mock(ExecutionResult.class); when(service.execute(FILE1)).thenReturn(result); String out = bean.executeWithHistory(PATH); verify(serviceResourceResolverService, times(1)).getAdminResourceResolver(); verify(service, times(1)).getFiles(PATH); verify(service, times(1)).createHistoryEntry(); verify(service, times(1)).execute(FILE1); verify(service, times(1)).execute(FILE1); verify(service, times(1)).finishHistoryEntry(Mockito.any()); }