8b31db68d082706f6c8cb7d46bbd67715744d764
[cps.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 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.inventory.models.NcmpServiceCmHandle
25 import org.onap.cps.ncmp.init.DataMigration
26 import org.onap.cps.utils.ContentType
27 import org.springframework.beans.factory.annotation.Autowired
28 import org.springframework.test.context.TestPropertySource
29
30 @TestPropertySource(properties = ["ncmp.inventory.model.upgrade.r20250722.enabled=true"])
31 class DataMigrationIntegrationSpec extends CpsIntegrationSpecBase {
32
33     @Autowired
34     DataMigration objectUnderTest
35
36     def 'Migrate inventory with batch processing.'() {
37         given: 'DMI will return modules when requested'
38             dmiDispatcher1.moduleNamesPerCmHandleId = (1..2).collectEntries{ ['ch-'+it, ['M1']] }
39         and: 'multiple CM handles registered, (top level) status is null'
40             (1..2).each {
41                 registerCmHandle(DMI1_URL, 'ch-'+it, NO_MODULE_SET_TAG)
42                 cpsDataService.saveListElements('NCMP-Admin', 'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='ch-${it}']",
43                         '{"additional-properties":[{"name":"prop1","value":"value1"}]}', now, ContentType.JSON)
44                 def someCmHandle = networkCmProxyInventoryFacade.getNcmpServiceCmHandle('ch-'+it)
45                 assert someCmHandle.getCmHandleStatus() == null
46                 assert someCmHandle.getCompositeState().getCmHandleState().name() == 'READY'
47                 assert someCmHandle.getDmiProperties() == null
48                 assert someCmHandle.getAdditionalProperties() == ['prop1':'value1']
49             }
50         when: 'migration is executed'
51             objectUnderTest.migrateInventoryToModelRelease20250722(1)
52         then: 'all CM handles are processed successfully,' +
53                 'the (top level) status is set to the same value as the name of the complex state value'
54             (1..2).each {
55                 def someCmHandle = networkCmProxyInventoryFacade.getNcmpServiceCmHandle('ch-'+it)
56                 assert someCmHandle.getCmHandleStatus() == 'READY'
57                 assert someCmHandle.getCompositeState().getCmHandleState().name() == 'READY'
58                 assert someCmHandle.getDmiProperties() == '{"prop1":"value1"}'
59                 assert someCmHandle.getAdditionalProperties() == ['prop1':'value1']
60             }
61         cleanup: 'deregister CM handles'
62             deregisterCmHandles(DMI1_URL, (1..2).collect{ 'ch-'+it })
63     }
64 }