Merge "Define response objects(schemas) in cps-ncmp"
authorNiamh Core <niamh.core@est.tech>
Mon, 13 Dec 2021 15:05:19 +0000 (15:05 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 13 Dec 2021 15:05:19 +0000 (15:05 +0000)
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/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
csit/tests/ncmp-passthrough/ncmp-passthrough.robot
docs/release-notes.rst

index 363dbc2..faa2efe 100755 (executable)
@@ -24,6 +24,7 @@
 package org.onap.cps.ncmp.api.impl;
 
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum;
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -289,13 +290,15 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
     }
 
     protected void syncModulesAndCreateAnchor(final PersistenceCmHandle persistenceCmHandle) {
-        fetchAndSyncModules(persistenceCmHandle);
+        syncAndCreateSchemaSet(persistenceCmHandle);
         createAnchor(persistenceCmHandle);
     }
 
     private void parseAndRemoveCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
         for (final String cmHandle : dmiPluginRegistration.getRemovedCmHandles()) {
             try {
+                cpsModuleService.deleteSchemaSet(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle,
+                    CASCADE_DELETE_ALLOWED);
                 cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
                     "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP);
             } catch (final DataNodeNotFoundException e) {
@@ -304,7 +307,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
         }
     }
 
-    private void fetchAndSyncModules(final PersistenceCmHandle persistenceCmHandle) {
+    private void syncAndCreateSchemaSet(final PersistenceCmHandle persistenceCmHandle) {
 
         final List<ModuleReference> moduleReferencesFromCmHandle =
             toModuleReferences(dmiModelOperations.getModuleReferences(persistenceCmHandle));
index 86c01b4..4108454 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.impl
 import com.fasterxml.jackson.core.JsonProcessingException
 import com.fasterxml.jackson.databind.ObjectMapper
 import org.onap.cps.api.CpsDataService
+import org.onap.cps.api.CpsModuleService
 import org.onap.cps.ncmp.api.impl.exception.NcmpException
 import org.onap.cps.ncmp.api.models.CmHandle
 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
@@ -31,6 +32,8 @@ import org.onap.cps.spi.exceptions.DataValidationException
 import spock.lang.Shared
 import spock.lang.Specification
 
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
+
 class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
 
     @Shared
@@ -40,6 +43,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
     def cmHandlesArray = ['cmHandle001']
 
     def mockCpsDataService = Mock(CpsDataService)
+    def mockCpsModuleService = Mock(CpsModuleService)
     def spyObjectMapper = Spy(ObjectMapper)
 
     def noTimestamp = null
@@ -62,16 +66,18 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
         and: 'update node and child data nodes is invoked with correct parameters'
             expectedCallsToUpdateNode * mockCpsDataService.updateNodeLeavesAndExistingDescendantLeaves('NCMP-Admin',
                     'ncmp-dmi-registry', '/dmi-registry', expectedJsonData, noTimestamp)
-        and : 'delete list or list element is invoked with the correct parameters'
-            expectedCallsToDeleteListElement * mockCpsDataService.deleteListOrListElement('NCMP-Admin',
+        and: 'delete schema set is invoked with the correct parameters'
+            expectedCallsToDeleteSchemaSetAndListElement * mockCpsModuleService.deleteSchemaSet('NFP-Operational', 'cmHandle001', CASCADE_DELETE_ALLOWED)
+        and: 'delete list or list element is invoked with the correct parameters'
+            expectedCallsToDeleteSchemaSetAndListElement * mockCpsDataService.deleteListOrListElement('NCMP-Admin',
                     'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='cmHandle001']", noTimestamp)
         where:
-            scenario                        | createdCmHandles      | updatedCmHandles      | removedCmHandles || expectedCallsToSaveNode   | expectedCallsToUpdateNode | expectedCallsToDeleteListElement
-            '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
-            'no valid data'                 | null                  | null                  |  null            || 0                         | 0                         | 0
+            scenario                    | createdCmHandles      | updatedCmHandles      | removedCmHandles || expectedCallsToSaveNode | expectedCallsToUpdateNode | expectedCallsToDeleteSchemaSetAndListElement
+            '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
+            'no valid data'             | null                  | null                  | null             || 0                       | 0                         | 0
     }
 
     def 'Register a DMI Plugin for the given cm-handle(s) without additional properties.'() {
@@ -159,7 +165,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
     }
 
     def getObjectUnderTestWithModelSyncDisabled() {
-        def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(null, null, null,
+        def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(null, null, mockCpsModuleService,
                 mockCpsDataService, null, null, spyObjectMapper))
         objectUnderTest.syncModulesAndCreateAnchor(*_) >> null
         return objectUnderTest
index 77d7f41..51eabc8 100644 (file)
@@ -95,4 +95,24 @@ Verify update to bookstore using passthrough-running did not remove category 02
     ${responseJson}=     Set Variable       ${response.json()}
     Should Be Equal As Strings              ${response.status_code}   200
     ${schemaCount}=      Get length         ${responseJson['stores:bookstore']['categories']}
-    Should Be Equal As Numbers              ${schemaCount}  2
\ No newline at end of file
+    Should Be Equal As Numbers              ${schemaCount}  2
+
+Delete Bookstore using passthrough-running for Category 01
+    ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore/categories=01
+    ${headers}=          Create Dictionary  Content-Type=application/json   Authorization=${auth}
+    ${response}=         DELETE On Session     CPS_URL   ${uri}   headers=${headers}   data=''
+    Should Be Equal As Strings              ${response.status_code}   204
+
+Verify delete to bookstore using passthrough-running removed only category 01
+    ${uri}=              Set Variable       ${ncmpBasePath}/v1/ch/PNFDemo/data/ds/ncmp-datastore:passthrough-running?resourceIdentifier=stores:bookstore
+    ${headers}=          Create Dictionary  Authorization=${auth}
+    ${response}=         Get On Session     CPS_URL   ${uri}   headers=${headers}
+    ${responseJson}=     Set Variable       ${response.json()}
+    Should Be Equal As Strings              ${response.status_code}   200
+    ${schemaCount}=      Get length         ${responseJson['stores:bookstore']['categories']}
+    Should Be Equal As Numbers              ${schemaCount}  1
+    FOR   ${item}   IN  @{responseJson['stores:bookstore']['categories']}
+        IF   "${item['code']}" == "02"
+            Should Be Equal As Strings              "${item['name']}"  "Horror"
+        END
+    END
index 58baeb9..da96970 100755 (executable)
@@ -38,6 +38,7 @@ Bug Fixes
 
    - `CPS-762 <https://jira.onap.org/browse/CPS-762>`_ Query cm handles for module names returns incorrect cm handle identifiers
    - `CPS-788 <https://jira.onap.org/browse/CPS-788>`_ Yang Resource formatting is incorrect
+   - `CPS-783 <https://jira.onap.org/browse/CPS-783>`_ Remove cm handle does not completely remove all cm handle information
 
 Known Limitations, Issues and Workarounds
 -----------------------------------------