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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.rest.controller
23 import org.mapstruct.factory.Mappers
24 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
25 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
26 import org.onap.cps.ncmp.rest.model.RestInputCmHandle
27 import org.onap.cps.ncmp.rest.model.RestModuleReference
28 import org.onap.cps.spi.model.ModuleReference
29 import spock.lang.Specification
31 class NcmpRestInputMapperSpec extends Specification {
33 def objectUnderTest = Mappers.getMapper(NcmpRestInputMapper.class)
35 def 'Convert a created REST CM Handle Input to an NCMP Service CM Handle with #scenario'() {
36 given: 'a rest cm handle input'
37 def inputRestCmHandle = new RestInputCmHandle(cmHandle : 'example-id', cmHandleProperties: dmiProperties,
38 publicCmHandleProperties: publicProperties)
39 def restDmiPluginRegistration = new RestDmiPluginRegistration(
40 createdCmHandles: [inputRestCmHandle])
41 when: 'to plugin dmi registration is called'
42 def result = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
43 then: 'the result returns the correct number of cm handles'
44 result.createdCmHandles.size() == 1
45 and: 'the converted cm handle has the same id'
46 result.createdCmHandles[0].cmHandleId == 'example-id'
47 and: '(empty) properties are converted correctly'
48 result.createdCmHandles[0].dmiProperties == expectedDmiProperties
49 result.createdCmHandles[0].publicProperties == expectedPublicProperties
50 where: 'the following parameters are used'
51 scenario | dmiProperties | publicProperties || expectedDmiProperties | expectedPublicProperties
52 'dmi and public properties' | ['Property-Example': 'example property'] | ['Public-Property-Example': 'public example property'] || ['Property-Example': 'example property'] | ['Public-Property-Example': 'public example property']
53 'no properties' | null | null || [:] | [:]
56 def 'Handling empty dmi registration'() {
57 given: 'a rest cm handle input without any cm handles'
58 def restDmiPluginRegistration = new RestDmiPluginRegistration()
59 when: 'to plugin dmi registration is called'
60 def result = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
61 then: 'unspecified lists remain as empty lists'
62 assert result.createdCmHandles == []
63 assert result.updatedCmHandles == []
64 assert result.removedCmHandles == []
67 def 'Handling non-empty dmi registration'() {
68 given: 'a rest cm handle input with cm handles'
69 def restDmiPluginRegistration = new RestDmiPluginRegistration(
70 createdCmHandles: [new RestInputCmHandle()],
71 updatedCmHandles: [new RestInputCmHandle()],
72 removedCmHandles: ["some-cmHandle"]
74 when: 'to dmi plugin registration is called'
75 def result = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
76 then: 'Lists contain values'
77 assert result.createdCmHandles[0].class == NcmpServiceCmHandle.class
78 assert result.updatedCmHandles[0].class == NcmpServiceCmHandle.class
79 assert result.removedCmHandles == ["some-cmHandle"]
82 def 'Convert a ModuleReference to a RestModuleReference'() {
83 given: 'a ModuleReference'
84 def moduleReference = new ModuleReference()
85 when: 'toRestModuleReference is called'
86 def result = objectUnderTest.toRestModuleReference(moduleReference)
87 then: 'the result is of the correct class RestModuleReference'
88 result.class == RestModuleReference.class