Merge "Callback to delete job"
authorHenrik Andersson <henrik.b.andersson@est.tech>
Mon, 27 Sep 2021 10:55:53 +0000 (10:55 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Mon, 27 Sep 2021 10:55:53 +0000 (10:55 +0000)
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
onap/oran
policy-agent/pom.xml

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());
index 65cf80b..38d5562 160000 (submodule)
--- a/onap/oran
+++ b/onap/oran
@@ -1 +1 @@
-Subproject commit 65cf80bbd2eba0ab60d174c04f981ff6cf929e36
+Subproject commit 38d5562bc4417a85d65570f9450948837f0a6fbe
index 986b95a..0ca4230 100644 (file)
             <artifactId>mockwebserver</artifactId>
             <scope>test</scope>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/com.github.erosb/everit-json-schema -->
+        <dependency>
+            <groupId>com.github.erosb</groupId>
+            <artifactId>everit-json-schema</artifactId>
+            <version>1.13.0</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>