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.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
30 @TestPropertySource(properties = ["ncmp.inventory.model.upgrade.r20250722.enabled=true"])
31 class DataMigrationIntegrationSpec extends CpsIntegrationSpecBase {
34 DataMigration objectUnderTest
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'
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']
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'
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']
61 cleanup: 'deregister CM handles'
62 deregisterCmHandles(DMI1_URL, (1..2).collect{ 'ch-'+it })