// test createBatch
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(SalesforceEndpointConfig.JOB_ID, jobInfo.getId());
headers.put(SalesforceEndpointConfig.CONTENT_TYPE, jobInfo.getContentType());
BatchInfo batchInfo = template().requestBodyAndHeaders("direct:createBatch",
request.stream, headers, BatchInfo.class);
assertNotNull("Null batch", batchInfo);
assertNotNull("Null batch id", batchInfo.getId());
// test getAllBatches
@SuppressWarnings("unchecked")
List<BatchInfo> batches = template().requestBody("direct:getAllBatches", jobInfo, List.class);
assertNotNull("Null batches", batches);
assertFalse("Empty batch list", batches.isEmpty());
// test getBatch
batchInfo = batches.get(0);
batchInfo = getBatchInfo(batchInfo);
// test getRequest
InputStream requestStream = template().requestBody("direct:getRequest", batchInfo, InputStream.class);
assertNotNull("Null batch request", requestStream);
// wait for batch to finish
log.info("Waiting for batch to finish...");
while (!batchProcessed(batchInfo)) {
// sleep 5 seconds
Thread.sleep(5000);
// check again
batchInfo = getBatchInfo(batchInfo);
}
log.info("Batch finished with state " + batchInfo.getState());
assertEquals("Batch did not succeed", BatchStateEnum.COMPLETED, batchInfo.getState());
// test getResults
InputStream results = template().requestBody("direct:getResults", batchInfo, InputStream.class);
assertNotNull("Null batch results", results);