JiraStatusJob implements Job { @Override public void execute() { JiraClient.Response response = jiraClient.requestIssueStatus(address, issues); if (!response.ok()) { logger.warn("Requesting statuses for issues {} failed: {}", issues, response.errorDetails()); newPollIn(60); } else if (positiveTargetStatus != null) { Map<String, String> issueStatuses = response.issueStatuses(); if (!issueStatuses.entrySet().stream().map(Map.Entry::getValue).allMatch(status -> status.equals(positiveTargetStatus))) { logger.info("Statuses for issues {} are not yet {} (they are {}) [{} ms]", issues, positiveTargetStatus, issueStatuses, response.requestDuration()); newPollIn(10); } else { logger.info("Success - statuses for issues {} are now {} [{} ms]", issues, issueStatuses, response.requestDuration()); newCallbackJob(); } } else if (negativeTargetStatus != null) { Map<String, String> issueStatuses = response.issueStatuses(); if (issueStatuses.entrySet().stream().map(Map.Entry::getValue).anyMatch(status -> status.equals(negativeTargetStatus))) { logger.info("Statuses for issues {} are still {}) [{} ms]", issues, negativeTargetStatus, response.requestDuration()); newPollIn(10); } else { logger.info("Success - statuses for issues {} are now not {} (they are {}) [{} ms]", issues, negativeTargetStatus, issueStatuses, response.requestDuration()); newCallbackJob(); } } else { throw new IllegalStateException("No target status defined"); } }  @SuppressWarnings("unused") URL getAddress(); @SuppressWarnings("unused") URL getCallbackAddress(); @SuppressWarnings("unused") List<String> getIssues(); @SuppressWarnings("unused") String getPositiveTargetStatus(); @SuppressWarnings("unused") String getNegativeTargetStatus(); @Override void execute(); @Override String id(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void givenIssueStatusIsDifferentThanRequestedWhenExecutingJobThenJobIsRescheduledInTenSeconds() throws Exception { givenIssueStatusIs(anIssue(), "3"); Job job = jiraStatusJob(anIssue(), "7"); job.execute(); thenJobIsRescheduled(job, 10); }
@Test public void givenIssueStatusIsSameAsRequestedWhenExecutingJobThenCallbackCommandIsScheduled() throws Exception { givenIssueStatusIs(anIssue(), "4"); Job job = jiraStatusJob(anIssue(), "4"); job.execute(); thenCallbackJobIsScheduled(); }
@Test public void givenIssueStatusIsDifferentThanNegativeRequestedWhenExecutingJobThenCallbackCommandIsScheduled() throws Exception { givenIssueStatusIs(anIssue(), "3"); Job job = jiraNegativeStatusJob(anIssue(), "7"); job.execute(); thenCallbackJobIsScheduled(); }
@Test public void givenIssueStatusIsSameAsNegativeRequestedWhenExecutingJobThenJobIsRescheduledInTenSeconds() throws Exception { givenIssueStatusIs(anIssue(), "8"); Job job = jiraNegativeStatusJob(anIssue(), "8"); job.execute(); thenJobIsRescheduled(job, 10); }
@Test public void givenJiraRequestFailsWhenExecutingJobThenNewCommandIsScheduledInSixtySeconds() throws MalformedURLException { givenJiraRequestFails(); Job job = jiraStatusJob(anIssue(), "4"); job.execute(); thenJobIsRescheduled(job, 60); }