Add "dataProducerId" and "dmiServiceName" values to SubJobWriteResponse in sendReques... 05/140005/4
authoregernug <gerard.nugent@est.tech>
Mon, 13 Jan 2025 10:16:34 +0000 (10:16 +0000)
committeregernug <gerard.nugent@est.tech>
Wed, 29 Jan 2025 15:03:49 +0000 (15:03 +0000)
- DMI call only returns subJobId
- SubJobWriteResponse created using DMI response and request values

Issue-ID: CPS-2497

Change-Id: Ib38132f2337de6a12b0b05bc6eebeed99f8d435d
Signed-off-by: egernug <gerard.nugent@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandler.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/datajobs/DmiSubJobRequestHandlerSpec.groovy
integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/WriteSubJobSpec.groovy

index a118d53..d74863a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation
+ *  Copyright (C) 2024-2025 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -79,8 +79,11 @@ public class DmiSubJobRequestHandler {
                     jsonObjectMapper.asJsonString(subJobWriteRequest),
                     OperationType.CREATE,
                     authorization);
-            final SubJobWriteResponse subJobWriteResponse = jsonObjectMapper
-                                            .convertToValueType(responseEntity.getBody(), SubJobWriteResponse.class);
+            final Map<String, String> responseAsKeyValuePairs = jsonObjectMapper
+                    .convertToValueType(responseEntity.getBody(), Map.class);
+            final String subJobId = responseAsKeyValuePairs.get("subJobId");
+            final SubJobWriteResponse subJobWriteResponse = new SubJobWriteResponse(subJobId,
+                    producerKey.dmiServiceName(), producerKey.dataProducerIdentifier());
             log.debug("Sub job write response: {}", subJobWriteResponse);
             subJobWriteResponses.add(subJobWriteResponse);
         });
index 041fbd9..93362f2 100644 (file)
@@ -29,12 +29,13 @@ class DmiSubJobRequestHandlerSpec extends Specification {
             def dmiWriteOperationsPerProducerKey = [new ProducerKey('dmi1', 'prod1'): [dmiWriteOperation]]
             def authorization = 'my authorization header'
         and: 'the dmi rest client will return a response (for the correct parameters)'
-            def responseEntity = new ResponseEntity<>(new SubJobWriteResponse('my-sub-job-id', 'dmi1', 'prod1'), HttpStatus.OK)
+            def responseAsKeyValuePairs = [subJobId:'my-sub-job-id']
+            def responseEntity = new ResponseEntity<>(responseAsKeyValuePairs, HttpStatus.OK)
             def expectedJson = '{"destination":"d1","dataAcceptType":"t1","dataContentType":"t2","dataProducerId":"prod1","dataJobId":"some-job-id","data":[{"path":"p","op":"operation","moduleSetTag":"tag","value":null,"operationId":"o1","privateProperties":{}}]}'
             mockDmiRestClient.synchronousPostOperationWithJsonData(RequiredDmiService.DATA, _, expectedJson, OperationType.CREATE, authorization) >> responseEntity
         when: 'sending request to DMI invoked'
             objectUnderTest.sendRequestsToDmi(authorization, dataJobId, dataJobMetadata, dmiWriteOperationsPerProducerKey)
         then: 'the result contains the expected sub-job id'
-            assert responseEntity.body.subJobId == 'my-sub-job-id'
+            assert responseEntity.body.get('subJobId') == 'my-sub-job-id'
     }
 }
index f3cca80..b9b1c16 100644 (file)
@@ -260,7 +260,7 @@ abstract class CpsIntegrationSpecBase extends Specification {
     }
 
     def registerCmHandleWithoutWaitForReady(dmiPlugin, cmHandleId, moduleSetTag, alternateId) {
-        def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: cmHandleId, moduleSetTag: moduleSetTag, alternateId: alternateId)
+        def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: cmHandleId, moduleSetTag: moduleSetTag, alternateId: alternateId, dataProducerIdentifier: 'some data producer id')
         networkCmProxyInventoryFacade.updateDmiRegistration(new DmiPluginRegistration(dmiPlugin: dmiPlugin, createdCmHandles: [cmHandleToCreate]))
     }
 
index 35a7b6a..c790521 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation
+ *  Copyright (C) 2024-2025 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the 'License');
  *  you may not use this file except in compliance with the License.
@@ -113,7 +113,7 @@ class DmiDispatcher extends Dispatcher {
         def destination = Matcher.lastMatcher[0][1]
         def subJobWriteRequest = jsonSlurper.parseText(request.getBody().readUtf8())
         this.receivedSubJobs.put(destination, subJobWriteRequest)
-        def response = '{"subJobId":"some sub job id", "dmiServiceName":"some dmi service name", "dataProducerId":"some data producer id"}'
+        def response = '{"subJobId":"some sub job id"}'
         return mockResponseWithBody(HttpStatus.OK, response)
     }
 
index 834e139..5d3ea19 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation
+ *  Copyright (C) 2024-2025 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the 'License');
  *  you may not use this file except in compliance with the License.
@@ -59,9 +59,9 @@ class WriteSubJobSpec extends CpsIntegrationSpecBase {
         then: 'each DMI received the expected sub-jobs and the response has the expected values'
             assert response.size() == 2
             assert response[0].class == SubJobWriteResponse.class
-            assert response[0].subJobId == "some sub job id"
-            assert response[0].dmiServiceName == "some dmi service name"
-            assert response[0].dataProducerId == "some data producer id"
+            assert response[0].subJobId == 'some sub job id'
+            assert response[0].dmiServiceName.startsWith('http://localhost:')
+            assert response[0].dataProducerId == 'some data producer id'
         and: 'dmi 1 received the correct job details'
             def receivedSubJobsForDispatcher1 = dmiDispatcher1.receivedSubJobs['?destination=d1']['data'].collect()
             assert receivedSubJobsForDispatcher1.size() == 2