Data Sync Watchdog Process
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / models / YangModelCmHandleSpec.groovy
1 /*
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
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.ncmp.api.models
22
23 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
24 import org.onap.cps.ncmp.api.inventory.CmHandleState
25 import spock.lang.Specification
26
27 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
28 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL
29
30 class YangModelCmHandleSpec extends Specification {
31
32     def 'Creating yang model cm handle from a service api cm handle.'() {
33         given: 'a cm handle with properties'
34             def ncmpServiceCmHandle = new NcmpServiceCmHandle()
35             ncmpServiceCmHandle.cmHandleId = 'cm-handle-id01'
36             ncmpServiceCmHandle.dmiProperties = [myDmiProperty:'value1']
37             ncmpServiceCmHandle.publicProperties = [myPublicProperty:'value2']
38         when: 'it is converted to a yang model cm handle'
39             def objectUnderTest = YangModelCmHandle.toYangModelCmHandle('','','', CmHandleState.ADVISED, ncmpServiceCmHandle)
40         then: 'the result has the right size'
41             assert objectUnderTest.dmiProperties.size() == 1
42         and: 'the DMI property in the result has the correct name and value'
43             assert objectUnderTest.dmiProperties[0].name == 'myDmiProperty'
44             assert objectUnderTest.dmiProperties[0].value == 'value1'
45         and: 'the public property in the result has the correct name and value'
46             assert objectUnderTest.publicProperties[0].name == 'myPublicProperty'
47             assert objectUnderTest.publicProperties[0].value == 'value2'
48     }
49
50     def 'Resolve DMI service name: #scenario and #requiredService service require.'() {
51         given: 'a yang model cm handle'
52             def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, CmHandleState.ADVISED, new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'))
53         expect:
54             assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService
55         where:
56             scenario                        | dmiServiceName     | dmiDataServiceName | dmiModelServiceName | requiredService || expectedService
57             'common service registered'     | 'common service'   | 'does not matter'  | 'does not matter'   | DATA            || 'common service'
58             'common service registered'     | 'common service'   | 'does not matter'  | 'does not matter'   | MODEL           || 'common service'
59             'common service empty'          | ''                 | 'data service'     | 'does not matter'   | DATA            || 'data service'
60             'common service empty'          | ''                 | 'does not matter'  | 'model service'     | MODEL           || 'model service'
61             'common service blank'          | '   '              | 'data service'     | 'does not matter'   | DATA            || 'data service'
62             'common service blank'          | '   '              | 'does not matter'  | 'model service'     | MODEL           || 'model service'
63             'common service null '          | null               | 'data service'     | 'does not matter'   | DATA            || 'data service'
64             'common service null'           | null               | 'does not matter'  | 'model service'     | MODEL           || 'model service'
65             'only model service registered' | null               | null               | 'does not matter'   | DATA            || null
66             'only data service registered'  | null               | 'does not matter'  | null                | MODEL           || null
67     }
68
69 }