fix for sync and passthough usecase 33/124833/4
authortragait <rahul.tyagi@est.tech>
Mon, 11 Oct 2021 15:31:59 +0000 (16:31 +0100)
committertragait <rahul.tyagi@est.tech>
Tue, 12 Oct 2021 10:19:20 +0000 (11:19 +0100)
fixed unknown modules issue, if unknown modules are size 0
dmi should not be called.

fixed 2xx issue for create resource.

fixed options = null issue.

Issue-ID: CPS-730
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: If6226f65e72753189c27648ad903c45a5d8fa14e

cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
cps-ncmp-service/src/test/resources/cmHandleModules.json

index 5594a2a..d6aaf36 100755 (executable)
@@ -284,7 +284,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     }
 
     private static void handleResponseForPost(final @NotNull ResponseEntity<String> responseEntity) {
-        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+        if (!HttpStatus.valueOf(responseEntity.getStatusCodeValue()).is2xxSuccessful()) {
             throw new NcmpException("Not able to create resource data.",
                     "DMI status code: " + responseEntity.getStatusCodeValue()
                             + ", DMI response body: " + responseEntity.getBody());
@@ -387,9 +387,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
         final List<ModuleReference> unknownModuleReferences = new ArrayList<>();
         prepareModuleSubsets(moduleReferencesFromCmHandle, existingModuleReferences, unknownModuleReferences);
 
-        final Map<String, String> newYangResourcesModuleNameToContentMap =
-            getNewYangResourcesFromDmi(persistenceCmHandle, unknownModuleReferences, cmHandlePropertiesAsMap);
-
+        final Map<String, String> newYangResourcesModuleNameToContentMap;
+        if (unknownModuleReferences.size() > 0) {
+            newYangResourcesModuleNameToContentMap = getNewYangResourcesFromDmi(persistenceCmHandle,
+                    unknownModuleReferences, cmHandlePropertiesAsMap);
+        } else {
+            newYangResourcesModuleNameToContentMap = new HashMap<>();
+        }
         cpsModuleService.createSchemaSetFromModules(NF_PROXY_DATASPACE_NAME, persistenceCmHandle.getId(),
             newYangResourcesModuleNameToContentMap, existingModuleReferences);
     }
index 363b0ef..f7421cd 100644 (file)
@@ -203,7 +203,9 @@ public class DmiOperations {
 
     private void appendOptionsQuery(final StringBuilder stringBuilder,
                                     final String optionsParamInQuery) {
-        stringBuilder.append("&").append(OPTIONS_QUERY_KEY).append("=").append(optionsParamInQuery);
+        if (optionsParamInQuery != null) {
+            stringBuilder.append("&").append(OPTIONS_QUERY_KEY).append("=").append(optionsParamInQuery);
+        }
     }
 
     private HttpHeaders prepareHeader(final String acceptParam) {
index b5d4713..1bad8ce 100644 (file)
@@ -371,7 +371,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
                 'testResourceId',
                 '{"operation":"create","dataType":"application/json","data":"{some-json}","cmHandleProperties":'
                 + expectedJsonForCmhandleProperties+ '}')
-                >> { new ResponseEntity<>(HttpStatus.OK) }
+                >> { new ResponseEntity<>(HttpStatus.CREATED) }
         where:
             scenario  | includeCmHandleProperties || expectedJsonForCmhandleProperties
             'with'    | true                      || '{"testName":"testValue"}'
@@ -398,10 +398,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
     }
 
     def 'Sync model for a (new) cm handle with #scenario'() {
-        given: 'DMI Plug-in returns a list of module references'
-            def knownModule1 = new ModuleReference('module1', '1')
-            def knownOtherModule = new ModuleReference('some other module', 'some revision')
-        and: 'persistence cm handle is given'
+        given: 'persistence cm handle is given'
             def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name')
         and: 'additional properties are set as required'
             if (additionalProperties!=null) {
@@ -415,23 +412,23 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
             def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK)
             mockDmiOperations.getResourceFromDmiWithJsonData('some service name', expectedJsonBody, 'some cm handle', 'modules') >> moduleReferencesFromCmHandleAsJson
         and: 'CPS-Core returns list of known modules'
-            mockCpsModuleService.getYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule]
+            mockCpsModuleService.getYangResourceModuleReferences(_) >> existingModuleResourcesInCps
         and: 'DMI-Plugin returns resource(s) for "new" module(s)'
             def moduleResources = new ResponseEntity<String>(sdncReponseBody, HttpStatus.OK)
-            def jsonDataToFetchYangResource = '{"data":{"modules":[{"name":"module2","revision":"1"}]},"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
+            def jsonDataToFetchYangResource = '{"data":{"modules":[{"name":"module1","revision":"1"}]},"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
             mockDmiOperations.getResourceFromDmiWithJsonData('some service name', jsonDataToFetchYangResource, 'some cm handle', 'moduleResources') >> moduleResources
         when: 'module Sync is triggered'
             objectUnderTest.syncModulesAndCreateAnchor(cmHandleForModelSync)
         then: 'the CPS module service is called once with the correct parameters'
-            1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, [knownModule1])
+            1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, expectedKnownModules)
         and: 'admin service create anchor method has been called with correct parameters'
             1 * mockCpsAdminService.createAnchor(expectedDataspaceName, cmHandleForModelSync.getId(), cmHandleForModelSync.getId())
         where: 'the following responses are received from SDNC'
-            scenario                         | additionalProperties | sdncReponseBody                                                                        || expectedYangResourceToContentMap | expectedJsonForAdditionalProperties
-            'one unknown module'             | ['name1':'value1']   | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{"name1":"value1"}'
-            'no add. properties'             | [:]                  | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{}'
-            'additional properties is null'  | null                 | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source'] | '{}'
-            'no unknown module'              | [:]                  | '[]'                                                                                   || [:]                              | '{}'
+            scenario                         | additionalProperties | existingModuleResourcesInCps                                                  | sdncReponseBody                                                                     || expectedYangResourceToContentMap | expectedKnownModules                                                       | expectedJsonForAdditionalProperties
+            'one unknown module'             | ['name1':'value1']   | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')]    | '[{"moduleName" : "module1", "revision" : "1","yangSource": "[some yang source]"}]' || [module1: 'some yang source']    | [new ModuleReference('module2', '2')]                                      |'{"name1":"value1"}'
+            'no add. properties'             | [:]                  | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')]    | '[{"moduleName" : "module1", "revision" : "1","yangSource": "[some yang source]"}]' || [module1: 'some yang source']    | [new ModuleReference('module2', '2')]                                      |'{}'
+            'additional properties is null'  | null                 | [new ModuleReference('module2', '2'), new ModuleReference('module3', '3')]    | '[{"moduleName" : "module1", "revision" : "1","yangSource": "[some yang source]"}]' || [module1: 'some yang source']    | [new ModuleReference('module2', '2')]                                      |'{}'
+            'no unknown module'              | [:]                  | [new ModuleReference('module1', '1'),    new ModuleReference('module2', '2')] | '[]'                                                                                || [:]                              | [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')] |'{}'
     }
 
     def 'Getting Yang Resources.'() {
index 8e0fb76..9405b66 100644 (file)
@@ -41,27 +41,41 @@ class DmiOperationsSpec extends Specification {
 
     def 'call get resource data for pass-through:operational datastore from DMI.'() {
         given: 'expected url'
-        def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
-                '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child&options=(a=1,b=2)'
+            def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
+                    '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child&options=(a=1,b=2)'
         when: 'get resource data is called to DMI'
-        objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath',
-                'testCmhandle',
-                'parent/child',
-                '(a=1,b=2)',
-                'testAcceptJson',
-                'testJsonbody')
+            objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath',
+                    'testCmhandle',
+                    'parent/child',
+                    '(a=1,b=2)',
+                    'testAcceptJson',
+                    'testJsonbody')
         then: 'the put operation is executed with the correct URL'
-        1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
+            1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
     }
     def 'call get resource data for pass-through:running datastore from DMI.'() {
+        given: 'expected url'
+            def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
+                    '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child&options=(a=1,b=2)'
+        when: 'get resource data is called to DMI'
+            objectUnderTest.getResourceDataPassThroughRunningFromDmi('testDmiBasePath',
+                    'testCmhandle',
+                    'parent/child',
+                    '(a=1,b=2)',
+                    'testAcceptJson',
+                    'testJsonbody')
+        then: 'the put operation is executed with the correct URL'
+            1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
+    }
+    def 'call get resource data for pass-through:operational datastore from DMI when options is null.'() {
         given: 'expected url'
         def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
-                '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child&options=(a=1,b=2)'
+                '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child'
         when: 'get resource data is called to DMI'
-        objectUnderTest.getResourceDataPassThroughRunningFromDmi('testDmiBasePath',
+        objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath',
                 'testCmhandle',
                 'parent/child',
-                '(a=1,b=2)',
+                null,
                 'testAcceptJson',
                 'testJsonbody')
         then: 'the put operation is executed with the correct URL'
@@ -69,15 +83,15 @@ class DmiOperationsSpec extends Specification {
     }
     def 'call create resource data for pass-through:running datastore from DMI.'() {
         given: 'expected url'
-        def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
-                '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child'
+            def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' +
+                    '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child'
         when: 'get resource data is called to DMI'
-        objectUnderTest.createResourceDataPassThroughRunningFromDmi('testDmiBasePath',
-                'testCmhandle',
-                'parent/child',
-                'testJsonbody')
+            objectUnderTest.createResourceDataPassThroughRunningFromDmi('testDmiBasePath',
+                    'testCmhandle',
+                    'parent/child',
+                    'testJsonbody')
         then: 'the put operation is executed with the correct URL'
-        1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
+            1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
     }
 
     def 'Call get resource from dmi.'() {
index d1665be..43e8175 100644 (file)
@@ -6,7 +6,7 @@
   },
   {
     "moduleName": "module2",
-    "revision": "1",
+    "revision": "2",
     "namespace": "some namespace"
   }]
 }
\ No newline at end of file