Add trust level notification schema
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / NetworkCmProxyDataServiceImplRegistrationSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2023 Nordix Foundation
4  *  Modifications Copyright (C) 2022 Bell Canada
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.ncmp.api.impl
23
24 import org.onap.cps.ncmp.api.models.UpgradedCmHandles
25
26 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND
27 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST
28 import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID
29 import static org.onap.cps.ncmp.api.NcmpResponseStatus.UNKNOWN_ERROR
30 import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status
31
32 import com.fasterxml.jackson.databind.ObjectMapper
33 import com.hazelcast.map.IMap
34 import org.onap.cps.api.CpsDataService
35 import org.onap.cps.api.CpsModuleService
36 import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService
37 import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler
38 import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
39 import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
40 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
41 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
42 import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
43 import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
44 import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
45 import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
46 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
47 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
48 import org.onap.cps.spi.exceptions.AlreadyDefinedException
49 import org.onap.cps.spi.exceptions.DataNodeNotFoundException
50 import org.onap.cps.spi.exceptions.DataValidationException
51 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
52 import org.onap.cps.utils.JsonObjectMapper
53 import spock.lang.Shared
54 import spock.lang.Specification
55
56 class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
57
58     @Shared
59     def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id')
60
61     def mockCpsModuleService = Mock(CpsModuleService)
62     def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
63     def mockDmiDataOperations = Mock(DmiDataOperations)
64     def mockNetworkCmProxyDataServicePropertyHandler = Mock(NetworkCmProxyDataServicePropertyHandler)
65     def mockInventoryPersistence = Mock(InventoryPersistence)
66     def mockCmHandleQueries = Mock(CmHandleQueries)
67     def stubbedNetworkCmProxyCmHandlerQueryService = Stub(NetworkCmProxyCmHandleQueryService)
68     def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler)
69     def mockCpsDataService = Mock(CpsDataService)
70     def mockModuleSyncStartedOnCmHandles = Mock(IMap<String, Object>)
71     def mockTrustLevelPerDmiPlugin = Mock(IMap<String, TrustLevel>)
72     def objectUnderTest = getObjectUnderTest()
73
74     def 'DMI Registration: Create, Update, Delete & Upgrade operations are processed in the right order'() {
75         given: 'a registration with operations of all three types'
76             def dmiRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
77             dmiRegistration.setCreatedCmHandles([new NcmpServiceCmHandle(cmHandleId: 'cmhandle-1', publicProperties: ['publicProp1': 'value'], dmiProperties: [:])])
78             dmiRegistration.setUpdatedCmHandles([new NcmpServiceCmHandle(cmHandleId: 'cmhandle-2', publicProperties: ['publicProp1': 'value'], dmiProperties: [:])])
79             dmiRegistration.setRemovedCmHandles(['cmhandle-2'])
80             dmiRegistration.setUpgradedCmHandles(new UpgradedCmHandles(cmHandles: ['cmhandle-3'], moduleSetTag: 'some-module-set-tag'))
81         and: 'cm handles are persisted'
82             mockInventoryPersistence.getYangModelCmHandles(['cmhandle-2']) >> [new YangModelCmHandle()]
83         and: 'cm handle is in READY state'
84             mockCmHandleQueries.cmHandleHasState('cmhandle-3', CmHandleState.READY) >> true
85         when: 'registration is processed'
86             objectUnderTest.updateDmiRegistrationAndSyncModule(dmiRegistration)
87         then: 'cm-handles are removed first'
88             1 * objectUnderTest.parseAndProcessDeletedCmHandlesInRegistration(*_)
89         and: 'de-registered cm handle entry is removed from in progress map'
90             1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle-2')
91         then: 'cm-handles are created'
92             1 * objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(*_)
93         then: 'cm-handles are updated'
94             1 * mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(*_)
95         then: 'cm-handles are upgraded'
96             1 * objectUnderTest.parseAndProcessUpgradedCmHandlesInRegistration(*_)
97     }
98
99     def 'DMI Registration: Response from all operations types are in response'() {
100         given: 'a registration with operations of all three types'
101             def dmiRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
102             dmiRegistration.setCreatedCmHandles([new NcmpServiceCmHandle(cmHandleId: 'cmhandle-1', publicProperties: ['publicProp1': 'value'], dmiProperties: [:])])
103             dmiRegistration.setUpdatedCmHandles([new NcmpServiceCmHandle(cmHandleId: 'cmhandle-2', publicProperties: ['publicProp1': 'value'], dmiProperties: [:])])
104             dmiRegistration.setRemovedCmHandles(['cmhandle-2'])
105         and: 'update cm-handles can be processed successfully'
106             def updateResponses = [CmHandleRegistrationResponse.createSuccessResponse('cmhandle-2')]
107             mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(*_) >> updateResponses
108         and: 'create cm-handles can be processed successfully'
109             def createdResponses = [CmHandleRegistrationResponse.createSuccessResponse('cmhandle-1')]
110             objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(*_) >> createdResponses
111         and: 'delete cm-handles can be processed successfully'
112             def removeResponses = [CmHandleRegistrationResponse.createSuccessResponse('cmhandle-3')]
113             objectUnderTest.parseAndProcessDeletedCmHandlesInRegistration(*_) >> removeResponses
114         when: 'registration is processed'
115             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiRegistration)
116         then: 'response has values from all operations'
117             response.removedCmHandles == removeResponses
118             response.createdCmHandles == createdResponses
119             response.updatedCmHandles == updateResponses
120     }
121
122     def 'Create CM-handle Validation: Registration with valid Service names: #scenario'() {
123         given: 'a registration '
124             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: dmiPlugin, dmiModelPlugin: dmiModelPlugin,
125                 dmiDataPlugin: dmiDataPlugin)
126             dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle]
127         when: 'update registration and sync module is called with correct DMI plugin information'
128             objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
129         then: 'create cm handles registration and sync modules is called with the correct plugin information'
130             1 * objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration)
131         and: 'dmi is added to the trustLevel map'
132             1 * mockTrustLevelPerDmiPlugin.put(dmiPluginRegisteredName, TrustLevel.COMPLETE)
133         where:
134             scenario                          | dmiPlugin  | dmiModelPlugin | dmiDataPlugin | dmiPluginRegisteredName
135             'combined DMI plugin'             | 'service1' | ''             | ''            | 'service1'
136             'data & model DMI plugins'        | ''         | 'service1'     | 'service2'    | 'service2'
137             'data & model using same service' | ''         | 'service1'     | 'service1'    | 'service1'
138     }
139
140     def 'Create CM-handle Validation: Invalid DMI plugin service name with #scenario'() {
141         given: 'a registration '
142             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: dmiPlugin, dmiModelPlugin: dmiModelPlugin,
143                 dmiDataPlugin: dmiDataPlugin)
144             dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle]
145         when: 'registration is called with incorrect DMI plugin information'
146             objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
147         then: 'a DMI Request Exception is thrown with correct message details'
148             def exceptionThrown = thrown(DmiRequestException.class)
149             assert exceptionThrown.getMessage().contains(expectedMessageDetails)
150         and: 'registration is not called'
151             0 * objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration)
152         where:
153             scenario                         | dmiPlugin  | dmiModelPlugin | dmiDataPlugin || expectedMessageDetails
154             'empty DMI plugins'              | ''         | ''             | ''            || 'No DMI plugin service names'
155             'blank DMI plugins'              | ' '        | ' '            | ' '           || 'No DMI plugin service names'
156             'null DMI plugins'               | null       | null           | null          || 'No DMI plugin service names'
157             'all DMI plugins'                | 'service1' | 'service2'     | 'service3'    || 'Cannot register combined plugin service name and other service names'
158             '(combined)DMI and Data Plugin'  | 'service1' | ''             | 'service2'    || 'Cannot register combined plugin service name and other service names'
159             '(combined)DMI and model Plugin' | 'service1' | 'service2'     | ''            || 'Cannot register combined plugin service name and other service names'
160             'only model DMI plugin'          | ''         | 'service1'     | ''            || 'Cannot register just a Data or Model plugin service name'
161             'only data DMI plugin'           | ''         | ''             | 'service1'    || 'Cannot register just a Data or Model plugin service name'
162     }
163
164     def 'Create CM-Handle Successfully: #scenario.'() {
165         given: 'a registration without cm-handle properties'
166             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
167             dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: 'cmhandle', dmiProperties: dmiProperties, publicProperties: publicProperties)]
168         when: 'registration is updated'
169             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
170         then: 'a successful response is received'
171             response.createdCmHandles.size() == 1
172             with(response.createdCmHandles[0]) {
173                 assert it.status == Status.SUCCESS
174                 assert it.cmHandle == 'cmhandle'
175             }
176         and: 'state handler is invoked with the expected parameters'
177             1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> {
178                 args ->
179                     {
180                         def cmHandleStatePerCmHandle = (args[0] as Map)
181                         cmHandleStatePerCmHandle.each {
182                             assert (it.key.id == 'cmhandle'
183                                     && it.key.dmiServiceName == 'my-server'
184                                     && it.value == CmHandleState.ADVISED)
185                         }
186                     }
187             }
188         where:
189             scenario                          | dmiProperties            | publicProperties               || expectedDmiProperties                      | expectedPublicProperties
190             'with dmi & public properties'    | ['dmi-key': 'dmi-value'] | ['public-key': 'public-value'] || '[{"name":"dmi-key","value":"dmi-value"}]' | '[{"name":"public-key","value":"public-value"}]'
191             'with only public properties'     | [:]                      | ['public-key': 'public-value'] || '[]'                                       | '[{"name":"public-key","value":"public-value"}]'
192             'with only dmi properties'        | ['dmi-key': 'dmi-value'] | [:]                            || '[{"name":"dmi-key","value":"dmi-value"}]' | '[]'
193             'without dmi & public properties' | [:]                      | [:]                            || '[]'                                       | '[]'
194     }
195
196     def 'Create CM-Handle Multiple Requests: All cm-handles creation requests are processed with some failures'() {
197         given: 'a registration with three cm-handles to be created'
198             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
199                     createdCmHandles: [new NcmpServiceCmHandle(cmHandleId: 'cmhandle1'),
200                                        new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'),
201                                        new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')])
202         and: 'cm-handle creation is successful for 1st and 3rd; failed for 2nd'
203             def xpath = "somePathWithId[@id='cmhandle2']"
204             mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw AlreadyDefinedException.forDataNodes([xpath], 'some-context') }
205         when: 'registration is updated to create cm-handles'
206             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
207         then: 'a response is received for all cm-handles'
208             response.createdCmHandles.size() == 1
209         and: 'all cm-handles creation fails'
210             response.createdCmHandles.each {
211                 assert it.cmHandle == 'cmhandle2'
212                 assert it.status == Status.FAILURE
213                 assert it.ncmpResponseStatus == CM_HANDLE_ALREADY_EXIST
214                 assert it.errorText == 'cm-handle already exists'
215             }
216     }
217
218     def 'Create CM-Handle Error Handling: Registration fails: #scenario'() {
219         given: 'a registration without cm-handle properties'
220             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
221             dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: 'cmhandle')]
222         and: 'cm-handler registration fails: #scenario'
223             mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw exception }
224         when: 'registration is updated'
225             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
226         then: 'a failure response is received'
227             response.createdCmHandles.size() == 1
228             with(response.createdCmHandles[0]) {
229                 assert it.status == Status.FAILURE
230                 assert it.cmHandle ==  'cmhandle'
231                 assert it.ncmpResponseStatus == expectedError
232                 assert it.errorText == expectedErrorText
233             }
234         where:
235             scenario                                        | exception                                                                      || expectedError           | expectedErrorText
236             'cm-handle already exist'                       | AlreadyDefinedException.forDataNodes(["path[@id='cmhandle']"], 'some-context') || CM_HANDLE_ALREADY_EXIST | 'cm-handle already exists'
237             'unknown exception while registering cm-handle' | new RuntimeException('Failed')                                                 || UNKNOWN_ERROR           | 'Failed'
238     }
239
240     def 'Update CM-Handle: Update Operation Response is added to the response'() {
241         given: 'a registration to update CmHandles'
242             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', updatedCmHandles: [{}])
243         and: 'cm-handle updates can be processed successfully'
244             def updateOperationResponse = [CmHandleRegistrationResponse.createSuccessResponse('cm-handle-1'),
245                                            CmHandleRegistrationResponse.createFailureResponse('cm-handle-2', new Exception("Failed")),
246                                            CmHandleRegistrationResponse.createFailureResponse('cm-handle-3', CM_HANDLES_NOT_FOUND),
247                                            CmHandleRegistrationResponse.createFailureResponse('cm handle 4', CM_HANDLE_INVALID_ID)]
248             mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(_) >> updateOperationResponse
249         when: 'registration is updated'
250             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
251         then: 'the response contains updateOperationResponse'
252             assert response.updatedCmHandles.size() == 4
253             assert response.updatedCmHandles.containsAll(updateOperationResponse)
254     }
255
256     def 'Remove CmHandle Successfully: #scenario'() {
257         given: 'a registration'
258             addPersistedYangModelCmHandles(['cmhandle'])
259             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
260                 removedCmHandles: ['cmhandle'])
261         and: '#scenario'
262             mockCpsModuleService.deleteSchemaSetsWithCascade(_, ['cmhandle']) >>
263                 { if (!schemaSetExist) { throw new SchemaSetNotFoundException("", "") } }
264         when: 'registration is updated to delete cmhandle'
265             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
266         then: 'the cmHandle state is updated to "DELETING"'
267             1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_)
268         and: 'method to delete relevant schema set is called once'
269             1 * mockInventoryPersistence.deleteSchemaSetsWithCascade(_)
270         and: 'method to delete relevant list/list element is called once'
271             1 * mockInventoryPersistence.deleteDataNodes(_)
272         and: 'successful response is received'
273             assert response.removedCmHandles.size() == 1
274             with(response.removedCmHandles[0]) {
275                 assert it.status == Status.SUCCESS
276                 assert it.cmHandle == 'cmhandle'
277             }
278         and: 'the cmHandle state is updated to "DELETED"'
279             1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_)
280         where:
281             scenario                                            | schemaSetExist
282             'schema-set exists and can be deleted successfully' | true
283             'schema-set does not exist'                         | false
284     }
285
286     def 'Remove CmHandle: Partial Success'() {
287         given: 'some unique yang model cm handles'
288             addPersistedYangModelCmHandles(['cmhandle1', 'cmhandle2', 'cmhandle3'])
289         and: 'a registration with three cm-handles to be deleted'
290             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
291                 removedCmHandles: ['cmhandle1', 'cmhandle2', 'cmhandle3'])
292         and: 'cm-handle deletion fails on batch'
293             mockInventoryPersistence.deleteDataNodes(_) >> { throw new RuntimeException("Failed") }
294         and: 'cm-handle deletion is successful for 1st and 3rd; failed for 2nd'
295             mockInventoryPersistence.deleteDataNode("/dmi-registry/cm-handles[@id='cmhandle2']") >> { throw new RuntimeException("Failed") }
296         when: 'registration is updated to delete cmhandles'
297             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
298         then: 'the cmHandle states are all updated to "DELETING"'
299             1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch({ assert it.every { entry -> entry.value == CmHandleState.DELETING } })
300         and: 'a response is received for all cm-handles'
301             response.removedCmHandles.size() == 3
302         and: 'successfully de-registered cm handle 1 is removed from in progress map'
303             1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle1')
304         and: 'successfully de-registered cm handle 3 is removed from in progress map even though it was already being removed'
305             1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle3') >> 'already in progress'
306         and: 'failed de-registered cm handle entries should not be removed from in progress map'
307             0 * mockModuleSyncStartedOnCmHandles.remove('cmhandle2')
308         and: '1st and 3rd cm-handle deletes successfully'
309             with(response.removedCmHandles[0]) {
310                 assert it.status == Status.SUCCESS
311                 assert it.cmHandle == 'cmhandle1'
312             }
313             with(response.removedCmHandles[2]) {
314                 assert it.status == Status.SUCCESS
315                 assert it.cmHandle == 'cmhandle3'
316             }
317         and: '2nd cm-handle deletion fails'
318             with(response.removedCmHandles[1]) {
319                 assert it.status == Status.FAILURE
320                 assert it.ncmpResponseStatus == UNKNOWN_ERROR
321                 assert it.errorText == 'Failed'
322                 assert it.cmHandle == 'cmhandle2'
323             }
324         and: 'the cmHandle state is updated to DELETED for 1st and 3rd'
325             1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch({
326                 assert it.size() == 2
327                 assert it.every { entry -> entry.value == CmHandleState.DELETED }
328             })
329     }
330
331     def 'Remove CmHandle Error Handling: Schema Set Deletion failed'() {
332         given: 'a registration'
333             addPersistedYangModelCmHandles(['cmhandle'])
334             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
335                 removedCmHandles: ['cmhandle'])
336         and: 'schema set batch deletion failed with unknown error'
337             mockInventoryPersistence.deleteSchemaSetsWithCascade(_) >> { throw new RuntimeException('Failed') }
338         and: 'schema set single deletion failed with unknown error'
339             mockInventoryPersistence.deleteSchemaSetWithCascade(_) >> { throw new RuntimeException('Failed') }
340         when: 'registration is updated to delete cmhandle'
341             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
342         then: 'no exception is thrown'
343             noExceptionThrown()
344         and: 'cm-handle is not deleted'
345             0 * mockInventoryPersistence.deleteDataNodes(_)
346         and: 'the cmHandle state is not updated to "DELETED"'
347             0 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch([yangModelCmHandle: CmHandleState.DELETED])
348         and: 'a failure response is received'
349             assert response.removedCmHandles.size() == 1
350             with(response.removedCmHandles[0]) {
351                 assert it.status == Status.FAILURE
352                 assert it.cmHandle == 'cmhandle'
353                 assert it.errorText == 'Failed'
354                 assert it.ncmpResponseStatus == UNKNOWN_ERROR
355             }
356     }
357
358     def 'Remove CmHandle Error Handling: #scenario'() {
359         given: 'a registration'
360             addPersistedYangModelCmHandles(['cmhandle'])
361             def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
362                 removedCmHandles: ['cmhandle'])
363         and: 'cm-handle deletion fails on batch'
364             mockInventoryPersistence.deleteDataNodes(_) >> { throw deleteListElementException }
365         and: 'cm-handle deletion fails on individual delete'
366             mockInventoryPersistence.deleteDataNode(_) >> { throw deleteListElementException }
367         when: 'registration is updated to delete cmhandle'
368             def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
369         then: 'a failure response is received'
370             assert response.removedCmHandles.size() == 1
371             with(response.removedCmHandles[0]) {
372                 assert it.status == Status.FAILURE
373                 assert it.cmHandle == 'cmhandle'
374                 assert it.ncmpResponseStatus == expectedError
375                 assert it.errorText == expectedErrorText
376             }
377         and: 'the cm handle state is not updated to "DELETED"'
378             0 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_, CmHandleState.DELETED)
379         where:
380         scenario                     | cmHandleId             | deleteListElementException                || expectedError        | expectedErrorText
381         'cm-handle does not exist'   | 'cmhandle'             | new DataNodeNotFoundException('', '', '') || CM_HANDLES_NOT_FOUND | 'cm handle id(s) not found'
382         'cm-handle has invalid name' | 'cm handle with space' | new DataValidationException('', '')       || CM_HANDLE_INVALID_ID | 'cm-handle has an invalid character(s) in id'
383         'an unexpected exception'    | 'cmhandle'             | new RuntimeException('Failed')            || UNKNOWN_ERROR        | 'Failed'
384     }
385
386     def getObjectUnderTest() {
387         return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
388                 mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCmHandleQueries,
389                 stubbedNetworkCmProxyCmHandlerQueryService, mockLcmEventsCmHandleStateHandler, mockCpsDataService,
390                 mockModuleSyncStartedOnCmHandles, mockTrustLevelPerDmiPlugin))
391     }
392
393     def addPersistedYangModelCmHandles(ids) {
394         def yangModelCmHandles = ids.collect { new YangModelCmHandle(id:it) }
395         mockInventoryPersistence.getYangModelCmHandles(ids) >> yangModelCmHandles
396     }
397 }