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
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.impl.inventory.InventoryPersistence
25 import org.onap.cps.ncmp.init.InventoryModelLoader
26 import org.onap.cps.utils.ContentType
27 import org.springframework.beans.factory.annotation.Autowired
28 import org.springframework.test.util.ReflectionTestUtils
30 class DataMigrationIntegrationSpec extends CpsIntegrationSpecBase {
33 InventoryModelLoader objectUnderTest
36 InventoryPersistence inventoryPersistence
38 def 'Migrate inventory with batch processing.'() {
39 given: 'start with the old models (ignore upgrade)'
40 ReflectionTestUtils.setField(inventoryPersistence, 'ignoreModelR20250722', true)
41 and: 'DMI will return modules when requested'
42 dmiDispatcher1.moduleNamesPerCmHandleId = (1..2).collectEntries{ ['ch-'+it, ['M1']] }
43 and: 'multiple CM handles registered with old model'
45 registerCmHandle(DMI1_URL, 'ch-'+it, NO_MODULE_SET_TAG)
46 cpsDataService.saveListElements('NCMP-Admin', 'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='ch-${it}']",
47 '{"additional-properties":[{"name":"prop1","value":"value1"}]}', now, ContentType.JSON)
48 def someCmHandle = networkCmProxyInventoryFacade.getNcmpServiceCmHandle('ch-'+it)
49 assert someCmHandle.getCmHandleStatus() == null
50 assert someCmHandle.getCompositeState().getCmHandleState().name() == 'READY'
52 when: 'the new (more performant) model is enabled (no longer ignored)'
53 ReflectionTestUtils.setField(inventoryPersistence, 'ignoreModelR20250722', false)
54 ReflectionTestUtils.setField(objectUnderTest, 'ignoreModelR20250722', false)
55 and: 'inventory is upgraded to the new revision'
56 objectUnderTest.onboardOrUpgradeModel()
57 then: 'all CM handles have top-level cm-handle-state populated'
59 def someCmHandle = networkCmProxyInventoryFacade.getNcmpServiceCmHandle('ch-'+it)
60 assert someCmHandle.getCmHandleStatus() == 'READY'
61 assert someCmHandle.getCompositeState().getCmHandleState().name() == 'READY'
63 cleanup: 'deregister CM handles'
64 deregisterCmHandles(DMI1_URL, (1..2).collect{ 'ch-'+it })