Merge "Bug fix for delete data node not working for root node"
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / models / PersistenceCmHandleSpec.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 spock.lang.Specification
24
25 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
26 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL
27
28 class PersistenceCmHandleSpec extends Specification {
29
30     def 'Creating persistence cm handle from a cm handle.'() {
31         given: 'a cm handle with properties'
32             def cmHandle = new CmHandle()
33             cmHandle.dmiProperties = [myDmiProperty:'value1']
34             cmHandle.publicProperties = [myPublicProperty:'value2']
35         when: 'it is converted to a persistence cm handle'
36             def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle('','','', cmHandle)
37         then: 'the result has the right size'
38             assert objectUnderTest.dmiProperties.size() == 1
39         and: 'the DMI property in the result has the correct name and value'
40             assert objectUnderTest.dmiProperties[0].name == 'myDmiProperty'
41             assert objectUnderTest.dmiProperties[0].value == 'value1'
42         and: 'the public property in the result has the correct name and value'
43             assert objectUnderTest.publicProperties[0].name == 'myPublicProperty'
44             assert objectUnderTest.publicProperties[0].value == 'value2'
45     }
46
47     def 'Resolve DMI service name: #scenario and #requiredService service require.'() {
48         given: 'a Persistence CM Handle'
49             def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new CmHandle())
50         expect:
51             assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService
52         where:
53             scenario                        | dmiServiceName     | dmiDataServiceName | dmiModelServiceName | requiredService || expectedService
54             'common service registered'     | 'common service'   | 'does not matter'  | 'does not matter'   | DATA            || 'common service'
55             'common service registered'     | 'common service'   | 'does not matter'  | 'does not matter'   | MODEL           || 'common service'
56             'common service empty'          | ''                 | 'data service'     | 'does not matter'   | DATA            || 'data service'
57             'common service empty'          | ''                 | 'does not matter'  | 'model service'     | MODEL           || 'model service'
58             'common service blank'          | '   '              | 'data service'     | 'does not matter'   | DATA            || 'data service'
59             'common service blank'          | '   '              | 'does not matter'  | 'model service'     | MODEL           || 'model service'
60             'common service null '          | null               | 'data service'     | 'does not matter'   | DATA            || 'data service'
61             'common service null'           | null               | 'does not matter'  | 'model service'     | MODEL           || 'model service'
62             'only model service registered' | null               | null               | 'does not matter'   | DATA            || null
63             'only data service registered'  | null               | 'does not matter'  | null                | MODEL           || null
64     }
65
66 }