From b5fecf5c17cfa8663aea3a3432ee5a9717ebb0cc Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Mon, 27 Sep 2021 10:02:50 +0200 Subject: [PATCH] NONRTRIC - Implement DMaaP mediator producer service in Java Added test of delete information job. Signed-off-by: PatrikBuhr Issue-ID: NONRTRIC-597 Change-Id: I25bdd5347fa8e65f662dc0a74c1e83c3aeae51c9 --- .../org/oran/dmaapadapter/ApplicationTest.java | 13 ++++++++--- .../oran/dmaapadapter/EcsSimulatorController.java | 10 +++++++-- .../org/oran/dmaapadapter/IntegrationWithEcs.java | 25 ++++++++++++++++------ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/ApplicationTest.java b/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/ApplicationTest.java index 9dd7f8b7..aa300c5f 100644 --- a/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/ApplicationTest.java +++ b/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/ApplicationTest.java @@ -212,19 +212,26 @@ class ApplicationTest { @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()); } } diff --git a/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/EcsSimulatorController.java b/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/EcsSimulatorController.java index c0420342..7542e0bd 100644 --- a/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/EcsSimulatorController.java +++ b/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/EcsSimulatorController.java @@ -97,13 +97,19 @@ public class EcsSimulatorController { 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(); } } diff --git a/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/IntegrationWithEcs.java b/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/IntegrationWithEcs.java index 9ca94133..1cceef08 100644 --- a/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/IntegrationWithEcs.java +++ b/dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/IntegrationWithEcs.java @@ -62,6 +62,8 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; }) class IntegrationWithEcs { + private static final String EI_JOB_ID = "EI_JOB_ID"; + @Autowired private ApplicationConfig applicationConfig; @@ -161,20 +163,27 @@ class IntegrationWithEcs { 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() { @@ -202,7 +211,7 @@ class IntegrationWithEcs { void testWholeChain() throws Exception { await().untilAsserted(() -> assertThat(producerRegstrationTask.isRegisteredInEcs()).isTrue()); - createInformationJobInEcs(); + createInformationJobInEcs(EI_JOB_ID); await().untilAsserted(() -> assertThat(this.jobs.size()).isEqualTo(1)); @@ -213,6 +222,10 @@ class IntegrationWithEcs { 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()); -- 2.16.6