8b3fc24abfa1609a75c4323e1350ae66c1fced0a
[cps.git] /
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.integration.functional.ncmp.inventory
22
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
29
30 class CmHandleUpdateSpec extends CpsIntegrationSpecBase {
31
32     NetworkCmProxyInventoryFacadeImpl objectUnderTest
33
34     def setup() {
35         objectUnderTest = networkCmProxyInventoryFacade
36     }
37
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)
43
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]))
48
49         then: 'registration gives successful response'
50             assert dmiPluginRegistrationResponse.updatedCmHandles == [CmHandleRegistrationResponse.createSuccessResponse('ch-1')]
51
52         and: 'the CM-handle has expected alternate ID'
53             assert objectUnderTest.getNcmpServiceCmHandle('ch-1').alternateId == expectedAlternateId
54
55         cleanup: 'deregister CM handles'
56             deregisterCmHandle(DMI1_URL, 'ch-1')
57
58         where:
59             oldAlternateId | newAlternateId || expectedAlternateId
60             ''             | ''             || ''
61             ''             | 'new'          || 'new'
62             'old'          | 'old'          || 'old'
63             'old'          | null           || 'old'
64             'old'          | ''             || 'old'
65             'old'          | '  '           || 'old'
66     }
67
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')
73
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]))
78
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)]
81
82         and: 'the CM-handle still has the old alternate ID'
83             assert objectUnderTest.getNcmpServiceCmHandle('ch-1').alternateId == 'original'
84
85         cleanup: 'deregister CM handles'
86             deregisterCmHandle(DMI1_URL, 'ch-1')
87     }
88
89 }