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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.ncmp.api.impl
24 import org.onap.cps.ncmp.api.models.UpgradedCmHandles
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
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
56 class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
59 def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id')
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 trustLevelPerCmHandle = [:]
72 def objectUnderTest = getObjectUnderTest()
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(*_)
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
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)
132 scenario | dmiPlugin | dmiModelPlugin | dmiDataPlugin
133 'combined DMI plugin' | 'service1' | '' | ''
134 'data & model DMI plugins' | '' | 'service1' | 'service2'
135 'data & model using same service' | '' | 'service1' | 'service1'
138 def 'Create CM-handle Validation: Invalid DMI plugin service name with #scenario'() {
139 given: 'a registration '
140 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: dmiPlugin, dmiModelPlugin: dmiModelPlugin,
141 dmiDataPlugin: dmiDataPlugin)
142 dmiPluginRegistration.createdCmHandles = [ncmpServiceCmHandle]
143 when: 'registration is called with incorrect DMI plugin information'
144 objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
145 then: 'a DMI Request Exception is thrown with correct message details'
146 def exceptionThrown = thrown(DmiRequestException.class)
147 assert exceptionThrown.getMessage().contains(expectedMessageDetails)
148 and: 'registration is not called'
149 0 * objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration)
151 scenario | dmiPlugin | dmiModelPlugin | dmiDataPlugin || expectedMessageDetails
152 'empty DMI plugins' | '' | '' | '' || 'No DMI plugin service names'
153 'blank DMI plugins' | ' ' | ' ' | ' ' || 'No DMI plugin service names'
154 'null DMI plugins' | null | null | null || 'No DMI plugin service names'
155 'all DMI plugins' | 'service1' | 'service2' | 'service3' || 'Cannot register combined plugin service name and other service names'
156 '(combined)DMI and Data Plugin' | 'service1' | '' | 'service2' || 'Cannot register combined plugin service name and other service names'
157 '(combined)DMI and model Plugin' | 'service1' | 'service2' | '' || 'Cannot register combined plugin service name and other service names'
158 'only model DMI plugin' | '' | 'service1' | '' || 'Cannot register just a Data or Model plugin service name'
159 'only data DMI plugin' | '' | '' | 'service1' || 'Cannot register just a Data or Model plugin service name'
162 def 'Create CM-Handle Successfully: #scenario.'() {
163 given: 'a registration without cm-handle properties'
164 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
165 dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: 'cmhandle', dmiProperties: dmiProperties, publicProperties: publicProperties)]
166 when: 'registration is updated'
167 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
168 then: 'a successful response is received'
169 response.createdCmHandles.size() == 1
170 with(response.createdCmHandles[0]) {
171 assert it.status == Status.SUCCESS
172 assert it.cmHandle == 'cmhandle'
174 and: 'state handler is invoked with the expected parameters'
175 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> {
178 def cmHandleStatePerCmHandle = (args[0] as Map)
179 cmHandleStatePerCmHandle.each {
180 assert (it.key.id == 'cmhandle'
181 && it.key.dmiServiceName == 'my-server'
182 && it.value == CmHandleState.ADVISED)
187 scenario | dmiProperties | publicProperties || expectedDmiProperties | expectedPublicProperties
188 'with dmi & public properties' | ['dmi-key': 'dmi-value'] | ['public-key': 'public-value'] || '[{"name":"dmi-key","value":"dmi-value"}]' | '[{"name":"public-key","value":"public-value"}]'
189 'with only public properties' | [:] | ['public-key': 'public-value'] || '[]' | '[{"name":"public-key","value":"public-value"}]'
190 'with only dmi properties' | ['dmi-key': 'dmi-value'] | [:] || '[{"name":"dmi-key","value":"dmi-value"}]' | '[]'
191 'without dmi & public properties' | [:] | [:] || '[]' | '[]'
194 def 'Add CM-Handle to trustLevelPerCmHandle Successfully with: #scenario.'() {
195 given: 'a registration with trustLevel and populated cache'
196 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
197 dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: 'ch-1', registrationTrustLevel: TrustLevel.NONE),
198 new NcmpServiceCmHandle(cmHandleId: cmHandleId, registrationTrustLevel: registrationTrustLevel)]
199 when: 'registration is updated'
200 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
201 then: 'a successful response is received'
202 assert response.createdCmHandles.size() == expectedNumberOfCreatedCmHandles
203 and: 'trustLevel is set for the created cm-handle'
204 assert trustLevelPerCmHandle.get(cmHandleId) == expectedTrustLevel
206 scenario | cmHandleId | registrationTrustLevel || expectedNumberOfCreatedCmHandles | expectedTrustLevel
207 'new cmHandleId and trustLevel' | 'ch-new' | TrustLevel.COMPLETE || 2 | TrustLevel.COMPLETE
208 'existing cmHandleId with null trustLevel' | 'ch-1' | null || 1 | TrustLevel.NONE
209 'cmHandleId with null trustLevel' | 'ch-new' | null || 2 | TrustLevel.COMPLETE
212 def 'Create CM-Handle Multiple Requests: All cm-handles creation requests are processed with some failures'() {
213 given: 'a registration with three cm-handles to be created'
214 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
215 createdCmHandles: [new NcmpServiceCmHandle(cmHandleId: 'cmhandle1'),
216 new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'),
217 new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')])
218 and: 'cm-handle creation is successful for 1st and 3rd; failed for 2nd'
219 def xpath = "somePathWithId[@id='cmhandle2']"
220 mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw AlreadyDefinedException.forDataNodes([xpath], 'some-context') }
221 when: 'registration is updated to create cm-handles'
222 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
223 then: 'a response is received for all cm-handles'
224 response.createdCmHandles.size() == 1
225 and: 'all cm-handles creation fails'
226 response.createdCmHandles.each {
227 assert it.cmHandle == 'cmhandle2'
228 assert it.status == Status.FAILURE
229 assert it.ncmpResponseStatus == CM_HANDLE_ALREADY_EXIST
230 assert it.errorText == 'cm-handle already exists'
234 def 'Create CM-Handle Error Handling: Registration fails: #scenario'() {
235 given: 'a registration without cm-handle properties'
236 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
237 dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: 'cmhandle')]
238 and: 'cm-handler registration fails: #scenario'
239 mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw exception }
240 when: 'registration is updated'
241 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
242 then: 'a failure response is received'
243 response.createdCmHandles.size() == 1
244 with(response.createdCmHandles[0]) {
245 assert it.status == Status.FAILURE
246 assert it.cmHandle == 'cmhandle'
247 assert it.ncmpResponseStatus == expectedError
248 assert it.errorText == expectedErrorText
251 scenario | exception || expectedError | expectedErrorText
252 'cm-handle already exist' | AlreadyDefinedException.forDataNodes(["path[@id='cmhandle']"], 'some-context') || CM_HANDLE_ALREADY_EXIST | 'cm-handle already exists'
253 'unknown exception while registering cm-handle' | new RuntimeException('Failed') || UNKNOWN_ERROR | 'Failed'
256 def 'Update CM-Handle: Update Operation Response is added to the response'() {
257 given: 'a registration to update CmHandles'
258 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server', updatedCmHandles: [{}])
259 and: 'cm-handle updates can be processed successfully'
260 def updateOperationResponse = [CmHandleRegistrationResponse.createSuccessResponse('cm-handle-1'),
261 CmHandleRegistrationResponse.createFailureResponse('cm-handle-2', new Exception("Failed")),
262 CmHandleRegistrationResponse.createFailureResponse('cm-handle-3', CM_HANDLES_NOT_FOUND),
263 CmHandleRegistrationResponse.createFailureResponse('cm handle 4', CM_HANDLE_INVALID_ID)]
264 mockNetworkCmProxyDataServicePropertyHandler.updateCmHandleProperties(_) >> updateOperationResponse
265 when: 'registration is updated'
266 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
267 then: 'the response contains updateOperationResponse'
268 assert response.updatedCmHandles.size() == 4
269 assert response.updatedCmHandles.containsAll(updateOperationResponse)
272 def 'Remove CmHandle Successfully: #scenario'() {
273 given: 'a registration'
274 addPersistedYangModelCmHandles(['cmhandle'])
275 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
276 removedCmHandles: ['cmhandle'])
278 mockCpsModuleService.deleteSchemaSetsWithCascade(_, ['cmhandle']) >>
279 { if (!schemaSetExist) { throw new SchemaSetNotFoundException("", "") } }
280 when: 'registration is updated to delete cmhandle'
281 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
282 then: 'the cmHandle state is updated to "DELETING"'
283 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_)
284 and: 'method to delete relevant schema set is called once'
285 1 * mockInventoryPersistence.deleteSchemaSetsWithCascade(_)
286 and: 'method to delete relevant list/list element is called once'
287 1 * mockInventoryPersistence.deleteDataNodes(_)
288 and: 'successful response is received'
289 assert response.removedCmHandles.size() == 1
290 with(response.removedCmHandles[0]) {
291 assert it.status == Status.SUCCESS
292 assert it.cmHandle == 'cmhandle'
294 and: 'the cmHandle state is updated to "DELETED"'
295 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_)
297 scenario | schemaSetExist
298 'schema-set exists and can be deleted successfully' | true
299 'schema-set does not exist' | false
302 def 'Remove CmHandle: Partial Success'() {
303 given: 'some unique yang model cm handles'
304 addPersistedYangModelCmHandles(['cmhandle1', 'cmhandle2', 'cmhandle3'])
305 and: 'a registration with three cm-handles to be deleted'
306 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
307 removedCmHandles: ['cmhandle1', 'cmhandle2', 'cmhandle3'])
308 and: 'cm-handle deletion fails on batch'
309 mockInventoryPersistence.deleteDataNodes(_) >> { throw new RuntimeException("Failed") }
310 and: 'cm-handle deletion is successful for 1st and 3rd; failed for 2nd'
311 mockInventoryPersistence.deleteDataNode("/dmi-registry/cm-handles[@id='cmhandle2']") >> { throw new RuntimeException("Failed") }
312 when: 'registration is updated to delete cmhandles'
313 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
314 then: 'the cmHandle states are all updated to "DELETING"'
315 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch({ assert it.every { entry -> entry.value == CmHandleState.DELETING } })
316 and: 'a response is received for all cm-handles'
317 response.removedCmHandles.size() == 3
318 and: 'successfully de-registered cm handle 1 is removed from in progress map'
319 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle1')
320 and: 'successfully de-registered cm handle 3 is removed from in progress map even though it was already being removed'
321 1 * mockModuleSyncStartedOnCmHandles.remove('cmhandle3') >> 'already in progress'
322 and: 'failed de-registered cm handle entries should not be removed from in progress map'
323 0 * mockModuleSyncStartedOnCmHandles.remove('cmhandle2')
324 and: '1st and 3rd cm-handle deletes successfully'
325 with(response.removedCmHandles[0]) {
326 assert it.status == Status.SUCCESS
327 assert it.cmHandle == 'cmhandle1'
329 with(response.removedCmHandles[2]) {
330 assert it.status == Status.SUCCESS
331 assert it.cmHandle == 'cmhandle3'
333 and: '2nd cm-handle deletion fails'
334 with(response.removedCmHandles[1]) {
335 assert it.status == Status.FAILURE
336 assert it.ncmpResponseStatus == UNKNOWN_ERROR
337 assert it.errorText == 'Failed'
338 assert it.cmHandle == 'cmhandle2'
340 and: 'the cmHandle state is updated to DELETED for 1st and 3rd'
341 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch({
342 assert it.size() == 2
343 assert it.every { entry -> entry.value == CmHandleState.DELETED }
347 def 'Remove CmHandle Error Handling: Schema Set Deletion failed'() {
348 given: 'a registration'
349 addPersistedYangModelCmHandles(['cmhandle'])
350 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
351 removedCmHandles: ['cmhandle'])
352 and: 'schema set batch deletion failed with unknown error'
353 mockInventoryPersistence.deleteSchemaSetsWithCascade(_) >> { throw new RuntimeException('Failed') }
354 and: 'schema set single deletion failed with unknown error'
355 mockInventoryPersistence.deleteSchemaSetWithCascade(_) >> { throw new RuntimeException('Failed') }
356 when: 'registration is updated to delete cmhandle'
357 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
358 then: 'no exception is thrown'
360 and: 'cm-handle is not deleted'
361 0 * mockInventoryPersistence.deleteDataNodes(_)
362 and: 'the cmHandle state is not updated to "DELETED"'
363 0 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch([yangModelCmHandle: CmHandleState.DELETED])
364 and: 'a failure response is received'
365 assert response.removedCmHandles.size() == 1
366 with(response.removedCmHandles[0]) {
367 assert it.status == Status.FAILURE
368 assert it.cmHandle == 'cmhandle'
369 assert it.errorText == 'Failed'
370 assert it.ncmpResponseStatus == UNKNOWN_ERROR
374 def 'Remove CmHandle Error Handling: #scenario'() {
375 given: 'a registration'
376 addPersistedYangModelCmHandles(['cmhandle'])
377 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
378 removedCmHandles: ['cmhandle'])
379 and: 'cm-handle deletion fails on batch'
380 mockInventoryPersistence.deleteDataNodes(_) >> { throw deleteListElementException }
381 and: 'cm-handle deletion fails on individual delete'
382 mockInventoryPersistence.deleteDataNode(_) >> { throw deleteListElementException }
383 when: 'registration is updated to delete cmhandle'
384 def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
385 then: 'a failure response is received'
386 assert response.removedCmHandles.size() == 1
387 with(response.removedCmHandles[0]) {
388 assert it.status == Status.FAILURE
389 assert it.cmHandle == 'cmhandle'
390 assert it.ncmpResponseStatus == expectedError
391 assert it.errorText == expectedErrorText
393 and: 'the cm handle state is not updated to "DELETED"'
394 0 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_, CmHandleState.DELETED)
396 scenario | cmHandleId | deleteListElementException || expectedError | expectedErrorText
397 'cm-handle does not exist' | 'cmhandle' | new DataNodeNotFoundException('', '', '') || CM_HANDLES_NOT_FOUND | 'cm handle id(s) not found'
398 'cm-handle has invalid name' | 'cm handle with space' | new DataValidationException('', '') || CM_HANDLE_INVALID_ID | 'cm-handle has an invalid character(s) in id'
399 'an unexpected exception' | 'cmhandle' | new RuntimeException('Failed') || UNKNOWN_ERROR | 'Failed'
402 def getObjectUnderTest() {
403 return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
404 mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCmHandleQueries,
405 stubbedNetworkCmProxyCmHandlerQueryService, mockLcmEventsCmHandleStateHandler, mockCpsDataService,
406 mockModuleSyncStartedOnCmHandles, trustLevelPerCmHandle))
409 def addPersistedYangModelCmHandles(ids) {
410 def yangModelCmHandles = ids.collect { new YangModelCmHandle(id:it) }
411 mockInventoryPersistence.getYangModelCmHandles(ids) >> yangModelCmHandles