public void testJobLaunch() throws Exception {
RestTemplate template = new RestTemplate();
ResponseEntity<String> result = template.exchange(serverRunning.getUrl() + "/jobs/job2.json?jobParameters=fail=true", 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"));
// 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);
Map<?, ?> map = wrapper.get("jobExecution.stepExecutions", Map.class);
return map.isEmpty() || wrapper.get("jobExecution.stepExecutions['job2.step1']['resource']") == null ? null
: wrapper;
}
});
JsonWrapper jobExecution = poll.get(500L, TimeUnit.MILLISECONDS);
assertNotNull(jobExecution);
// System.err.println(jobExecution);
// Verify that there is a step execution in the result
result = template.exchange(
jobExecution.get("jobExecution.stepExecutions['job2.step1'].resource", String.class), HttpMethod.GET,
null, String.class);
wrapper = new JsonWrapper(result.getBody());
// System.err.println(wrapper);
assertNotNull(wrapper.get("stepExecution.id"));
assertNotNull(wrapper.get("stepExecution.status"));
assertNotNull(wrapper.get("jobExecution.resource"));
assertNotNull(wrapper.get("jobExecution.status"));