@Test
void testWholeChain() throws Exception {
- await().untilAsserted(() -> assertThat(producerRegstrationTask.isRegisteredInEcs()).isTrue());
+ final String JOB_ID = "ID";
- this.ecsSimulatorController.addJob(consumerJobInfo(), restClient());
+ // Register producer, Register types
+ await().untilAsserted(() -> assertThat(producerRegstrationTask.isRegisteredInEcs()).isTrue());
+ // Create a job
+ this.ecsSimulatorController.addJob(consumerJobInfo(), JOB_ID, restClient());
await().untilAsserted(() -> assertThat(this.jobs.size()).isEqualTo(1));
+ // Return two messages from DMAAP and verify that these are sent to the owner of
+ // the job (consumer)
DmaapSimulatorController.dmaapResponses.add("DmaapResponse1");
DmaapSimulatorController.dmaapResponses.add("DmaapResponse2");
-
ConsumerController.TestResults consumer = this.consumerController.testResults;
await().untilAsserted(() -> assertThat(consumer.receivedBodies.size()).isEqualTo(2));
assertThat(consumer.receivedBodies.get(0)).isEqualTo("DmaapResponse1");
+ // Delete the job
+ this.ecsSimulatorController.deleteJob(JOB_ID, restClient());
+ await().untilAsserted(() -> assertThat(this.jobs.size()).isZero());
}
}
return new ResponseEntity<>(HttpStatus.OK);
}
- public void addJob(ConsumerJobInfo job, AsyncRestClient restClient) {
+ public void addJob(ConsumerJobInfo job, String jobId, AsyncRestClient restClient) {
String url = this.testResults.registrationInfo.jobCallbackUrl;
ProducerJobInfo request =
- new ProducerJobInfo(job.jobDefinition, "ID", job.infoTypeId, job.jobResultUri, job.owner, "TIMESTAMP");
+ new ProducerJobInfo(job.jobDefinition, jobId, job.infoTypeId, job.jobResultUri, job.owner, "TIMESTAMP");
String body = gson.toJson(request);
logger.info("ECS Simulator PUT job: {}", body);
restClient.post(url, body).block();
+ }
+
+ public void deleteJob(String jobId, AsyncRestClient restClient) {
+ String url = this.testResults.registrationInfo.jobCallbackUrl + "/" + jobId;
+ logger.info("ECS Simulator DELETE job: {}", url);
+ restClient.delete(url).block();
}
}
})
class IntegrationWithEcs {
+ private static final String EI_JOB_ID = "EI_JOB_ID";
+
@Autowired
private ApplicationConfig applicationConfig;
return applicationConfig.getEcsBaseUrl();
}
- private void createInformationJobInEcs() {
- String url = ecsBaseUrl() + "/data-consumer/v1/info-jobs/jobId";
+ private String jobUrl(String jobId) {
+ return ecsBaseUrl() + "/data-consumer/v1/info-jobs/" + jobId;
+ }
+
+ private void createInformationJobInEcs(String jobId) {
String body = gson.toJson(consumerJobInfo());
try {
// Delete the job if it already exists
- restClient().delete(url).block();
+ deleteInformationJobInEcs(jobId);
} catch (Exception e) {
}
- restClient().putForEntity(url, body).block();
+ restClient().putForEntity(jobUrl(jobId), body).block();
+ }
+
+ private void deleteInformationJobInEcs(String jobId) {
+ restClient().delete(jobUrl(jobId)).block();
}
private ConsumerJobInfo consumerJobInfo() {
InfoType type = this.types.getAll().iterator().next();
- return consumerJobInfo(type.getId(), "EI_JOB_ID");
+ return consumerJobInfo(type.getId(), EI_JOB_ID);
}
private Object jsonObject() {
void testWholeChain() throws Exception {
await().untilAsserted(() -> assertThat(producerRegstrationTask.isRegisteredInEcs()).isTrue());
- createInformationJobInEcs();
+ createInformationJobInEcs(EI_JOB_ID);
await().untilAsserted(() -> assertThat(this.jobs.size()).isEqualTo(1));
await().untilAsserted(() -> assertThat(results.receivedBodies.size()).isEqualTo(2));
assertThat(results.receivedBodies.get(0)).isEqualTo("DmaapResponse1");
+ deleteInformationJobInEcs(EI_JOB_ID);
+
+ await().untilAsserted(() -> assertThat(this.jobs.size()).isZero());
+
synchronized (this) {
// logger.warn("**************** Keeping server alive! " +
// this.applicationConfig.getLocalServerHttpPort());