c66eaa9b42770296e37c1e0054cf25943d9a3984
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / models / PersistenceCmHandleSpec.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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 package org.onap.cps.ncmp.api.models
21
22 import spock.lang.Specification
23
24 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
25 import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL
26
27 class PersistenceCmHandleSpec extends Specification {
28
29     def 'Setting and getting additional properties.'() {
30         given: 'a map of one property is added'
31             def objectUnderTest = new PersistenceCmHandle()
32             objectUnderTest.asAdditionalProperties([myProperty: 'some value'])
33         when: 'the additional properties are retrieved'
34             def result = objectUnderTest.getAdditionalProperties()
35         then: 'the result has the right size'
36             assert result.size() == 1
37         and: 'the property in the result has the correct name and value'
38             def actualAdditionalProperty = result.get(0)
39             def expectedAdditionalProperty = new PersistenceCmHandle.AdditionalProperty('myProperty','some value')
40             assert actualAdditionalProperty.name == expectedAdditionalProperty.name
41             assert actualAdditionalProperty.value == expectedAdditionalProperty.value
42     }
43
44     def 'Resolve dmi service name: #scenario and #requiredService service require.'() {
45         given: 'a Persistence CM Handle'
46             def objectUnderTest = PersistenceCmHandle.toPersistenceCmHandle(dmiServiceName, dmiDataServiceName, dmiModelServiceName, new CmHandle('some id', null))
47         expect:
48             assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService
49         where:
50             scenario                        | dmiServiceName     | dmiDataServiceName | dmiModelServiceName | requiredService || expectedService
51             'common service registered'     | 'common service'   | 'does not matter'  | 'does not matter'   | DATA            || 'common service'
52             'common service registered'     | 'common service'   | 'does not matter'  | 'does not matter'   | MODEL           || 'common service'
53             'common service empty'          | ''                 | 'data service'     | 'does not matter'   | DATA            || 'data service'
54             'common service empty'          | ''                 | 'does not matter'  | 'model service'     | MODEL           || 'model service'
55             'common service blank'          | '   '              | 'data service'     | 'does not matter'   | DATA            || 'data service'
56             'common service blank'          | '   '              | 'does not matter'  | 'model service'     | MODEL           || 'model service'
57             'common service null '          | null               | 'data service'     | 'does not matter'   | DATA            || 'data service'
58             'common service null'           | null               | 'does not matter'  | 'model service'     | MODEL           || 'model service'
59             'only model service registered' | null               | null               | 'does not matter'   | DATA            || null
60             'only data service registered'  | null               | 'does not matter'  | null                | MODEL           || null
61     }
62
63 }