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.RestModuleDefinition
28 import org.onap.cps.ncmp.rest.model.RestModuleReference
29 import org.onap.cps.spi.model.ModuleDefinition
30 import org.onap.cps.spi.model.ModuleReference
31 import spock.lang.Specification
33 class NcmpRestInputMapperSpec extends Specification {
35 def objectUnderTest = Mappers.getMapper(NcmpRestInputMapper.class)
37 def 'Convert a created REST CM Handle Input to an NCMP Service CM Handle with #scenario'() {
38 given: 'a rest cm handle input'
39 def inputRestCmHandle = new RestInputCmHandle(cmHandle : 'example-id', cmHandleProperties: dmiProperties,
40 publicCmHandleProperties: publicProperties)
41 def restDmiPluginRegistration = new RestDmiPluginRegistration(
42 createdCmHandles: [inputRestCmHandle])
43 when: 'to plugin dmi registration is called'
44 def result = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
45 then: 'the result returns the correct number of cm handles'
46 result.createdCmHandles.size() == 1
47 and: 'the converted cm handle has the same id'
48 result.createdCmHandles[0].cmHandleId == 'example-id'
49 and: '(empty) properties are converted correctly'
50 result.createdCmHandles[0].dmiProperties == expectedDmiProperties
51 result.createdCmHandles[0].publicProperties == expectedPublicProperties
52 where: 'the following parameters are used'
53 scenario | dmiProperties | publicProperties || expectedDmiProperties | expectedPublicProperties
54 'dmi and public properties' | ['Property-Example': 'example property'] | ['Public-Property-Example': 'public example property'] || ['Property-Example': 'example property'] | ['Public-Property-Example': 'public example property']
55 'no properties' | null | null || [:] | [:]
58 def 'Handling empty dmi registration'() {
59 given: 'a rest cm handle input without any cm handles'
60 def restDmiPluginRegistration = new RestDmiPluginRegistration()
61 when: 'to plugin dmi registration is called'
62 def result = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
63 then: 'unspecified lists remain as empty lists'
64 assert result.createdCmHandles == []
65 assert result.updatedCmHandles == []
66 assert result.removedCmHandles == []
69 def 'Handling non-empty dmi registration'() {
70 given: 'a rest cm handle input with cm handles'
71 def restDmiPluginRegistration = new RestDmiPluginRegistration(
72 createdCmHandles: [new RestInputCmHandle()],
73 updatedCmHandles: [new RestInputCmHandle()],
74 removedCmHandles: ["some-cmHandle"]
76 when: 'to dmi plugin registration is called'
77 def result = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
78 then: 'Lists contain values'
79 assert result.createdCmHandles[0].class == NcmpServiceCmHandle.class
80 assert result.updatedCmHandles[0].class == NcmpServiceCmHandle.class
81 assert result.removedCmHandles == ["some-cmHandle"]
84 def 'Convert a ModuleReference to a RestModuleReference'() {
85 given: 'a ModuleReference'
86 def moduleReference = new ModuleReference()
87 when: 'toRestModuleReference is called'
88 def result = objectUnderTest.toRestModuleReference(moduleReference)
89 then: 'the result is of the correct class RestModuleReference'
90 result.class == RestModuleReference.class
93 def 'Convert a ModuleDefinition to a RestModuleDefinition'() {
94 given: 'a ModuleDefinition'
95 def moduleDefinition = new ModuleDefinition('moduleName','revision', 'content')
96 when: 'toRestModuleDefinition is called'
97 def result = objectUnderTest.toRestModuleDefinition(moduleDefinition)
98 then: 'the result is of the correct class RestModuleDefinition'
99 result.class == RestModuleDefinition.class
100 and: 'all contents are mapped correctly'
101 result.toString()=='class RestModuleDefinition {\n' +
102 ' moduleName: moduleName\n' +
103 ' revision: revision\n' +
104 ' content: content\n' +