Replacing ModelMapper with MapStruct
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / controller / CpsRestInputMapperSpec.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.rest.controller
22
23 import org.mapstruct.factory.Mappers
24 import org.onap.cps.rest.model.AnchorDetails
25 import org.onap.cps.rest.model.SchemaSetDetails
26 import org.onap.cps.spi.model.Anchor
27 import org.onap.cps.rest.model.ModuleReferences
28 import org.onap.cps.spi.model.ModuleReference
29 import org.onap.cps.spi.model.SchemaSet
30 import spock.lang.Specification
31
32 class CpsRestInputMapperSpec extends Specification {
33
34     def objectUnderTest = Mappers.getMapper(CpsRestInputMapper.class)
35
36     def 'Convert a SchemaSet to a SchemaSetDetails a ModuleReference'() {
37         given: 'a ModuleReference'
38             def moduleReference = new ModuleReference()
39         and: 'a SchemaSet containing the ModuleReference'
40             def schemaSet = new SchemaSet(name: 'some-schema-set', dataspaceName: 'some-dataspace',
41                 moduleReferences: [moduleReference])
42         when: 'to schemaSetDetails is called'
43             def result = objectUnderTest.toSchemaSetDetails(schemaSet)
44         then: 'the result returns a SchemaSetDetails'
45             result.class == SchemaSetDetails.class
46         and: 'the results ModuleReferences are of type ModuleReference'
47             result.moduleReferences[0].class == ModuleReferences.class
48     }
49
50     def 'Convert a schemaSet to a SchemaSetDetails without an ModuleReference'() {
51         given: 'a SchemaSet'
52             def schemaSet = new SchemaSet()
53         when: 'to schemaSetDetails is called'
54             def result = objectUnderTest.toSchemaSetDetails(schemaSet)
55         then: 'the result returns a SchemaSetDetails'
56             result.class == SchemaSetDetails.class
57         and: 'the ModuleReferences of SchemaSetDetails is an empty collection'
58             result.moduleReferences.size() == 0
59     }
60
61     def 'Convert an Anchor to an AnchorDetails'() {
62         given: 'an Anchor'
63             def anchor = new Anchor()
64         when: 'to anchorDetails is called'
65             def result = objectUnderTest.toAnchorDetails(anchor)
66         then: 'the result returns an AnchorDetails'
67             result.class == AnchorDetails.class
68     }
69 }