NONRTRIC - Implement DMaaP mediator producer service in Java 55/6755/1
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 27 Sep 2021 08:02:50 +0000 (10:02 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 27 Sep 2021 08:02:50 +0000 (10:02 +0200)
Added test of delete information job.

Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Issue-ID: NONRTRIC-597
Change-Id: I25bdd5347fa8e65f662dc0a74c1e83c3aeae51c9

dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/ApplicationTest.java
dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/EcsSimulatorController.java
dmaap-adaptor-java/src/test/java/org/oran/dmaapadapter/IntegrationWithEcs.java

index 9dd7f8b..aa300c5 100644 (file)
@@ -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());
     }
 
 }
index c042034..7542e0b 100644 (file)
@@ -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();
 
     }
 }
index 9ca9413..1cceef0 100644 (file)
@@ -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());