2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 Nordix Foundation
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.ncmp.api.models
23 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
24 import org.onap.cps.ncmp.api.inventory.CmHandleState
25 import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
26 import org.onap.cps.ncmp.api.inventory.LockReasonCategory
27 import org.onap.cps.ncmp.api.inventory.SyncState
28 import spock.lang.Specification
30 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
31 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL
33 class YangModelCmHandleSpec extends Specification {
35 def 'Creating yang model cm handle from a service api cm handle.'() {
36 given: 'a cm handle with properties'
37 def ncmpServiceCmHandle = new NcmpServiceCmHandle()
38 ncmpServiceCmHandle.cmHandleId = 'cm-handle-id01'
39 ncmpServiceCmHandle.dmiProperties = [myDmiProperty:'value1']
40 ncmpServiceCmHandle.publicProperties = [myPublicProperty:'value2']
41 and: 'with a composite state'
42 def compositeState = new CompositeStateBuilder()
43 .withCmHandleState(CmHandleState.LOCKED)
44 .withLastUpdatedTime('some-update-time')
45 .withLockReason(LockReasonCategory.LOCKED_MISBEHAVING, 'locked other details')
46 .withOperationalDataStores(SyncState.SYNCHRONIZED, 'some-sync-time').build()
47 ncmpServiceCmHandle.setCompositeState(compositeState)
48 when: 'it is converted to a yang model cm handle'
49 def objectUnderTest = YangModelCmHandle.toYangModelCmHandle('', '', '', ncmpServiceCmHandle)
50 then: 'the result has the right size'
51 assert objectUnderTest.dmiProperties.size() == 1
52 and: 'the DMI property in the result has the correct name and value'
53 assert objectUnderTest.dmiProperties[0].name == 'myDmiProperty'
54 assert objectUnderTest.dmiProperties[0].value == 'value1'
55 and: 'the public property in the result has the correct name and value'
56 assert objectUnderTest.publicProperties[0].name == 'myPublicProperty'
57 assert objectUnderTest.publicProperties[0].value == 'value2'
58 and: 'the composite state matches the composite state of the ncmpServiceCmHandle'
59 objectUnderTest.getCompositeState().cmHandleState == CmHandleState.LOCKED
60 objectUnderTest.getCompositeState() == ncmpServiceCmHandle.getCompositeState()
63 def 'Resolve DMI service name: #scenario and #requiredService service require.'() {
64 given: 'a yang model cm handle'
65 def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'))
67 assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService
69 scenario | dmiServiceName | dmiDataServiceName | dmiModelServiceName | requiredService || expectedService
70 'common service registered' | 'common service' | 'does not matter' | 'does not matter' | DATA || 'common service'
71 'common service registered' | 'common service' | 'does not matter' | 'does not matter' | MODEL || 'common service'
72 'common service empty' | '' | 'data service' | 'does not matter' | DATA || 'data service'
73 'common service empty' | '' | 'does not matter' | 'model service' | MODEL || 'model service'
74 'common service blank' | ' ' | 'data service' | 'does not matter' | DATA || 'data service'
75 'common service blank' | ' ' | 'does not matter' | 'model service' | MODEL || 'model service'
76 'common service null ' | null | 'data service' | 'does not matter' | DATA || 'data service'
77 'common service null' | null | 'does not matter' | 'model service' | MODEL || 'model service'
78 'only model service registered' | null | null | 'does not matter' | DATA || null
79 'only data service registered' | null | 'does not matter' | null | MODEL || null