LastRunHealthCheck implements HealthCheck { @Override public Result execute() { final FormattingResultLog resultLog = new FormattingResultLog(); try { List<HistoryEntry> history = aecuService.getHistory(0, 1); if (history.isEmpty()) { resultLog.info("No runs found"); } else { HistoryEntry entry = history.get(0); switch (entry.getResult()) { case FAILURE: resultLog.critical("Last execution failed"); break; case SUCCESS: resultLog.info("Last run was successful"); break; case UNKNOWN: resultLog.warn("Last execution is still running"); break; default: resultLog.warn("Last execution is still ongoing"); } } } catch (AecuException e) { resultLog.critical(e.getMessage()); } return new Result(resultLog); }  @Override Result execute();  }
@Test public void execute_fail() { HistoryEntryImpl entry = new HistoryEntryImpl(); entry.setState(STATE.FINISHED); ExecutionResult singleResult = new ExecutionResult(ExecutionState.FAILED, "", "", "", null, ""); entry.getSingleResults().add(singleResult); history.add(entry); Result result = check.execute(); assertEquals(Result.Status.CRITICAL, result.getStatus()); }
@Test public void execute_noHistory() { Result result = check.execute(); assertEquals(Result.Status.OK, result.getStatus()); }
@Test public void execute_unknown() { HistoryEntryImpl entry = new HistoryEntryImpl(); entry.setState(STATE.RUNNING); history.add(entry); Result result = check.execute(); assertEquals(Result.Status.WARN, result.getStatus()); }
@Test public void execute_ok() { HistoryEntryImpl entry = new HistoryEntryImpl(); entry.setState(STATE.FINISHED); ExecutionResult singleResult = new ExecutionResult(ExecutionState.SUCCESS, "", "", "", null, ""); entry.getSingleResults().add(singleResult); history.add(entry); Result result = check.execute(); assertEquals(Result.Status.OK, result.getStatus()); }