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