2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the 'License');
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an 'AS IS' BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.integration.functional.ncmp.inventory
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.ncmp.api.NcmpResponseStatus
25 import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse
26 import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration
27 import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
28 import org.onap.cps.ncmp.events.lcm.v1.LcmEvent
29 import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl
31 class CmHandleUpdateSpec extends CpsIntegrationSpecBase {
33 NetworkCmProxyInventoryFacadeImpl objectUnderTest
36 objectUnderTest = networkCmProxyInventoryFacade
37 subscribeAndClearPreviousMessages('test-group-for-update', 'ncmp-events')
41 kafkaConsumer.unsubscribe()
45 def 'Update of CM-handle with new or unchanged alternate ID succeeds.'() {
46 given: 'DMI will return modules when requested'
47 dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': ['M1', 'M2']]
48 and: "existing CM-handle with alternate ID: $oldAlternateId"
49 registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, oldAlternateId)
51 when: "CM-handle is registered for update with new alternate ID: $newAlternateId"
52 def cmHandleToUpdate = new NcmpServiceCmHandle(cmHandleId: 'ch-1', alternateId: newAlternateId)
53 def dmiPluginRegistrationResponse =
54 objectUnderTest.updateDmiRegistration(new DmiPluginRegistration(dmiPlugin: DMI1_URL, updatedCmHandles: [cmHandleToUpdate]))
56 then: 'registration gives successful response'
57 assert dmiPluginRegistrationResponse.updatedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse('ch-1')]
59 and: 'the CM-handle has expected alternate ID'
60 assert objectUnderTest.getNcmpServiceCmHandle('ch-1').alternateId == expectedAlternateId
62 cleanup: 'deregister CM handles'
63 deregisterCmHandle(DMI1_URL, 'ch-1')
66 oldAlternateId | newAlternateId || expectedAlternateId
69 'old' | 'old' || 'old'
75 def 'Update of CM-handle with previously set alternate ID fails.'() {
76 given: 'DMI will return modules when requested'
77 dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': ['M1', 'M2']]
78 and: 'existing CM-handle with alternate ID'
79 registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, 'original')
81 when: 'a CM-handle is registered for update with new alternate ID'
82 def cmHandleToUpdate = new NcmpServiceCmHandle(cmHandleId: 'ch-1', alternateId: 'new')
83 def dmiPluginRegistrationResponse =
84 objectUnderTest.updateDmiRegistration(new DmiPluginRegistration(dmiPlugin: DMI1_URL, updatedCmHandles: [cmHandleToUpdate]))
86 then: 'registration gives failure response, due to cm-handle already existing'
87 assert dmiPluginRegistrationResponse.updatedCmHandles == [CmHandleRegistrationResponse.createFailureResponse('ch-1', NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST)]
89 and: 'the CM-handle still has the old alternate ID'
90 assert objectUnderTest.getNcmpServiceCmHandle('ch-1').alternateId == 'original'
92 cleanup: 'deregister CM handles'
93 deregisterCmHandle(DMI1_URL, 'ch-1')
96 def 'CM Handle registration to verify changes in data producer identifier'() {
97 given: 'DMI will return modules when requested'
98 def cmHandleId = 'ch-id-for-update'
99 dmiDispatcher1.moduleNamesPerCmHandleId[cmHandleId] = ['M1', 'M2']
101 when: 'a CM-handle is registered for creation'
103 def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: cmHandleId)
104 def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: DMI1_URL, createdCmHandles: [cmHandleToCreate])
105 def dmiPluginRegistrationResponse = objectUnderTest.updateDmiRegistration(dmiPluginRegistration)
107 then: 'registration gives successful response'
108 assert dmiPluginRegistrationResponse.createdCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)]
110 then: 'the module sync watchdog is triggered'
111 moduleSyncWatchdog.moduleSyncAdvisedCmHandles()
113 and: 'flush the latest cm handle registration events( state transition from NONE to ADVISED and ADVISED to READY)'
114 getLatestConsumerRecordsWithMaxPollOf1Second(2)
116 and: 'cm handle updated with the data producer identifier'
117 def cmHandleToUpdate = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dataProducerIdentifier: 'my-data-producer-id')
118 def dmiPluginRegistrationForUpdate = new DmiPluginRegistration(dmiPlugin: DMI1_URL, updatedCmHandles: [cmHandleToUpdate])
119 def dmiPluginRegistrationResponseForUpdate = objectUnderTest.updateDmiRegistration(dmiPluginRegistrationForUpdate)
121 then: 'registration gives successful response'
122 assert dmiPluginRegistrationResponseForUpdate.updatedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)]
124 and: 'get the latest message'
125 def consumerRecords = getLatestConsumerRecordsWithMaxPollOf1Second(1)
127 and: 'the message has the updated data producer identifier'
128 def notificationMessages = []
129 for (def consumerRecord : consumerRecords) {
130 notificationMessages.add(jsonObjectMapper.convertJsonString(consumerRecord.value().toString(), LcmEvent))
132 assert notificationMessages[0].event.cmHandleId.contains(cmHandleId)
133 assert notificationMessages[0].event.dataProducerIdentifier == 'my-data-producer-id'
135 cleanup: 'deregister CM handle'
136 deregisterCmHandle(DMI1_URL, cmHandleId)