RestTemplate template = new RestTemplate();
ResponseEntity<String> result = template.exchange(serverRunning.getUrl()
+ "/jobs/infinite.json?jobParameters=timestamp=" + System.currentTimeMillis(), HttpMethod.POST, null,
String.class);
JsonWrapper wrapper = new JsonWrapper(result.getBody());
// System.err.println(wrapper);
assertNotNull(wrapper.get("jobExecution.resource"));
assertNotNull(wrapper.get("jobExecution.status"));
assertNotNull(wrapper.get("jobExecution.id"));
template.exchange(wrapper.get("jobExecution.resource", String.class), HttpMethod.DELETE, null, String.class);
// Poll for the completed job execution
final String resource = wrapper.get("jobExecution.resource", String.class);
Poller<JsonWrapper> poller = new DirectPoller<JsonWrapper>(100L);
Future<JsonWrapper> poll = poller.poll(new Callable<JsonWrapper>() {
public JsonWrapper call() throws Exception {
RestTemplate template = new RestTemplate();
ResponseEntity<String> result = template.exchange(resource, HttpMethod.GET, null, String.class);
JsonWrapper wrapper = new JsonWrapper(result.getBody());
// System.err.println(wrapper);
BatchStatus status = wrapper.get("jobExecution.status", BatchStatus.class);
return status.isGreaterThan(BatchStatus.STOPPING) ? wrapper : null;
}
});
JsonWrapper jobExecution = poll.get(500L, TimeUnit.MILLISECONDS);
assertNotNull(jobExecution);
BatchStatus status = jobExecution.get("jobExecution.status", BatchStatus.class);
assertEquals(BatchStatus.STOPPED, status);
}