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.impl.NetworkCmProxyInventoryFacadeImpl
26 import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse
27 import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration
28 import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
30 class CmHandleUpdateSpec extends CpsIntegrationSpecBase {
32 NetworkCmProxyInventoryFacadeImpl objectUnderTest
35 objectUnderTest = networkCmProxyInventoryFacade
38 def 'Update of CM-handle with new or unchanged alternate ID succeeds.'() {
39 given: 'DMI will return modules when requested'
40 dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': ['M1', 'M2']]
41 and: "existing CM-handle with alternate ID: $oldAlternateId"
42 registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, oldAlternateId)
44 when: "CM-handle is registered for update with new alternate ID: $newAlternateId"
45 def cmHandleToUpdate = new NcmpServiceCmHandle(cmHandleId: 'ch-1', alternateId: newAlternateId)
46 def dmiPluginRegistrationResponse =
47 objectUnderTest.updateDmiRegistration(new DmiPluginRegistration(dmiPlugin: DMI1_URL, updatedCmHandles: [cmHandleToUpdate]))
49 then: 'registration gives successful response'
50 assert dmiPluginRegistrationResponse.updatedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse('ch-1')]
52 and: 'the CM-handle has expected alternate ID'
53 assert objectUnderTest.getNcmpServiceCmHandle('ch-1').alternateId == expectedAlternateId
55 cleanup: 'deregister CM handles'
56 deregisterCmHandle(DMI1_URL, 'ch-1')
59 oldAlternateId | newAlternateId || expectedAlternateId
62 'old' | 'old' || 'old'
68 def 'Update of CM-handle with previously set alternate ID fails.'() {
69 given: 'DMI will return modules when requested'
70 dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': ['M1', 'M2']]
71 and: 'existing CM-handle with alternate ID'
72 registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, 'original')
74 when: 'a CM-handle is registered for update with new alternate ID'
75 def cmHandleToUpdate = new NcmpServiceCmHandle(cmHandleId: 'ch-1', alternateId: 'new')
76 def dmiPluginRegistrationResponse =
77 objectUnderTest.updateDmiRegistration(new DmiPluginRegistration(dmiPlugin: DMI1_URL, updatedCmHandles: [cmHandleToUpdate]))
79 then: 'registration gives failure response, due to cm-handle already existing'
80 assert dmiPluginRegistrationResponse.updatedCmHandles == [CmHandleRegistrationResponse.createFailureResponse('ch-1', NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST)]
82 and: 'the CM-handle still has the old alternate ID'
83 assert objectUnderTest.getNcmpServiceCmHandle('ch-1').alternateId == 'original'
85 cleanup: 'deregister CM handles'
86 deregisterCmHandle(DMI1_URL, 'ch-1')