Merge "Remove CmHandle in DMI-Registry"
authorNiamh Core <niamh.core@est.tech>
Wed, 25 Aug 2021 15:19:17 +0000 (15:19 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 25 Aug 2021 15:19:17 +0000 (15:19 +0000)
1  2 
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy

@@@ -175,12 -177,23 +179,23 @@@ public class NetworkCmProxyDataServiceI
          }
      }
  
+     private void parseAndRemoveCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
+         for (final String cmHandle: dmiPluginRegistration.getRemovedCmHandles()) {
+             try {
+                 cpsDataService.deleteListNodeData(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
+                     "/dmi-registry/cm-handles[@id='" + cmHandle + "']");
+             } catch (final DataNodeNotFoundException e) {
+                 log.warn("Datanode {} not deleted message {}", cmHandle, e.getMessage());
+             }
+         }
+     }
      @Override
      public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle,
 -                                                        final @NotNull String resourceIdentifier,
 -                                                        final String acceptParam,
 -                                                        final String fieldsQueryParam,
 -                                                        final Integer depthQueryParam) {
 +        final @NotNull String resourceIdentifier,
 +        final String acceptParam,
 +        final String fieldsQueryParam,
 +        final Integer depthQueryParam) {
  
          final var dataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
          final var dmiServiceName = String.valueOf(dataNode.getLeaves().get("dmi-service-name"));
@@@ -122,30 -124,18 +124,33 @@@ class NetworkCmProxyDataServiceImplSpe
              objectUnderTest.updateDmiPluginRegistration(dmiPluginRegistration)
          then: 'the CPS save list node data is invoked with the expected parameters'
              expectedCallsToSaveNode * mockCpsDataService.saveListNodeData('NCMP-Admin', 'ncmp-dmi-registry', '/dmi-registry', expectedJsonData)
-         and: 'update Node and Child Data Nodes is invoked with correct parameter'
-             expectedCallsToUpdateNode * mockCpsDataService.updateNodeLeavesAndExistingDescendantLeaves('NCMP-Admin', dmiRegistryAnchor, '/dmi-registry', expectedJsonData)
+         and: 'update Node and Child Data Nodes is invoked with correct parameters'
+             expectedCallsToUpdateNode * mockCpsDataService.updateNodeLeavesAndExistingDescendantLeaves('NCMP-Admin',  'ncmp-dmi-registry', '/dmi-registry', expectedJsonData)
+         and : 'delete list data node is invoked with the correct parameters'
+             expectedCallsToDeleteListDataNode * mockCpsDataService.deleteListNodeData('NCMP-Admin', 'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='cmHandle001']")
          where:
-             scenario                | createdCmHandles       | updatedCmHandles       || expectedCallsToSaveNode   | expectedCallsToUpdateNode
-             'create'                | [persistenceCmHandle ] | []                     || 1                         | 0
-             'update'                | []                     | [persistenceCmHandle ] || 0                         | 1
-             'create and update'     | [persistenceCmHandle ] | [persistenceCmHandle ] || 1                         | 1
+             scenario                        | createdCmHandles       | updatedCmHandles       | removedCmHandles || expectedCallsToSaveNode   | expectedCallsToUpdateNode | expectedCallsToDeleteListDataNode
+             'create'                        | [persistenceCmHandle ] | []                     | []               || 1                         | 0                         | 0
+             'update'                        | []                     | [persistenceCmHandle ] | []               || 0                         | 1                         | 0
+             'delete'                        | []                     | []                     | cmHandlesArray   || 0                         | 0                         | 1
+             'create, update and delete'     | [persistenceCmHandle ] | [persistenceCmHandle ] | cmHandlesArray   || 1                         | 1                         | 1
  
      }
 +
 +    def 'Register a DMI Plugin for the given cmHandle without additional properties.'() {
 +        given: 'a registration without cmHandle properties '
 +            def dmiPluginRegistration = new DmiPluginRegistration()
 +            dmiPluginRegistration.dmiPlugin = 'my-server'
 +            persistenceCmHandle.cmHandleID = '123'
 +            persistenceCmHandle.cmHandleProperties = null
 +            dmiPluginRegistration.createdCmHandles = [persistenceCmHandle ]
 +            def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","additional-properties":[]}]}'
 +        when: 'registration is updated'
 +            objectUnderTest.updateDmiPluginRegistration(dmiPluginRegistration)
 +        then: 'the CPS save list node data is invoked with the expected parameters'
 +            1 * mockCpsDataService.saveListNodeData('NCMP-Admin', 'ncmp-dmi-registry', '/dmi-registry', expectedJsonData)
 +    }
 +
      def 'Get resource data for pass-through operational from dmi.'() {
          given: 'xpath'
              def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"