NONRTRIC - Implement DMaaP mediator producer service in Java
[nonrtric.git] / dmaap-adaptor-java / src / test / java / org / oran / dmaapadapter / EcsSimulatorController.java
index 7d309cf..8d1dda6 100644 (file)
@@ -45,8 +45,8 @@ import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
-@RestController("EcsSimulatorController")
-@Tag(name = "EcsSimulator")
+@RestController("IcsSimulatorController")
+@Tag(name = "Information Coordinator Service Simulator (exists only in test)")
 public class EcsSimulatorController {
 
     private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -54,14 +54,16 @@ public class EcsSimulatorController {
 
     public static class TestResults {
 
-        ProducerRegistrationInfo registrationInfo;
+        ProducerRegistrationInfo registrationInfo = null;
         Map<String, ProducerInfoTypeInfo> types = new HashMap<>();
+        String infoProducerId = null;
 
         public TestResults() {}
 
         public void reset() {
             registrationInfo = null;
             types.clear();
+            infoProducerId = null;
         }
     }
 
@@ -77,7 +79,6 @@ public class EcsSimulatorController {
         } else {
             return new ResponseEntity<>(HttpStatus.NOT_FOUND);
         }
-
     }
 
     @PutMapping(path = API_ROOT + "/info-producers/{infoProducerId}", //
@@ -86,6 +87,7 @@ public class EcsSimulatorController {
             @PathVariable("infoProducerId") String infoProducerId, //
             @RequestBody ProducerRegistrationInfo registrationInfo) {
         testResults.registrationInfo = registrationInfo;
+        testResults.infoProducerId = infoProducerId;
         return new ResponseEntity<>(HttpStatus.OK);
     }
 
@@ -97,12 +99,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();
 
     }
 }