c48a8ed360ae4d10940b043a7522c7a4a8bd37ee
[cps.git] / cps-ncmp-rest / src / test / groovy / org / onap / cps / ncmp / rest / controller / RestInputMapperSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 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.rest.controller
22
23 import org.mapstruct.factory.Mappers
24 import org.onap.cps.ncmp.rest.model.RestCmHandle
25 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
26 import spock.lang.Specification
27
28 class RestInputMapperSpec extends Specification {
29
30     def objectUnderTest = Mappers.getMapper(RestInputMapper.class)
31
32     def 'Convert a created REST CM Handle Input to an NCMP Service CM Handle with #scenario'() {
33         given: 'a rest cm handle input'
34             def inputRestCmHandle = new RestCmHandle(cmHandle : 'example-id', cmHandleProperties: dmiProperties,
35                 publicCmHandleProperties: publicProperties)
36             def restDmiPluginRegistration = new RestDmiPluginRegistration(
37                 createdCmHandles: [inputRestCmHandle])
38         when: 'to plugin dmi registration is called'
39             def result  = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
40         then: 'the result returns the correct number of cm handles'
41             result.createdCmHandles.size() == 1
42         and: 'the converted cm handle has the same id'
43             result.createdCmHandles[0].cmHandleID == 'example-id'
44         and: '(empty) properties are converted correctly'
45             result.createdCmHandles[0].dmiProperties == expectedDmiProperties
46             result.createdCmHandles[0].publicProperties == expectedPublicProperties
47         where: 'the following parameters are used'
48             scenario                    | dmiProperties                            | publicProperties                                         || expectedDmiProperties                     | expectedPublicProperties
49             'dmi and public properties' | ['Property-Example': 'example property'] | ['Public-Property-Example': 'public example property']   || ['Property-Example': 'example property']  | ['Public-Property-Example': 'public example property']
50             'no properties'             | null                                     | null                                                     || [:]                                       | [:]
51     }
52
53     def 'Handling empty dmi registration'() {
54         given: 'a rest cm handle input without any cm handles'
55             def restDmiPluginRegistration = new RestDmiPluginRegistration()
56         when: 'to plugin dmi registration is called'
57             def result  = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
58         then: 'unspecified lists remain as empty lists'
59             assert result.createdCmHandles == []
60             assert result.updatedCmHandles == []
61             assert result.removedCmHandles == []
62     }
63
64 }