Replacing ModelMapper with MapStruct
[cps.git] / cps-ncmp-rest / src / test / groovy / org / onap / cps / ncmp / rest / controller / NcmpRestInputMapperSpec.groovy
 package org.onap.cps.ncmp.rest.controller
 
 import org.mapstruct.factory.Mappers
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
 import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
 import org.onap.cps.ncmp.rest.model.RestInputCmHandle
+import org.onap.cps.ncmp.rest.model.RestModuleReference
+import org.onap.cps.spi.model.ModuleReference
 import spock.lang.Specification
 
-class RestInputMapperSpec extends Specification {
+class NcmpRestInputMapperSpec extends Specification {
 
-    def objectUnderTest = Mappers.getMapper(RestInputMapper.class)
+    def objectUnderTest = Mappers.getMapper(NcmpRestInputMapper.class)
 
     def 'Convert a created REST CM Handle Input to an NCMP Service CM Handle with #scenario'() {
         given: 'a rest cm handle input'
@@ -61,4 +64,27 @@ class RestInputMapperSpec extends Specification {
             assert result.removedCmHandles == []
     }
 
+    def 'Handling non-empty dmi registration'() {
+        given: 'a rest cm handle input with cm handles'
+            def restDmiPluginRegistration = new RestDmiPluginRegistration(
+                createdCmHandles: [new RestInputCmHandle()],
+                updatedCmHandles: [new RestInputCmHandle()],
+                removedCmHandles: ["some-cmHandle"]
+            )
+        when: 'to dmi plugin registration is called'
+            def result  = objectUnderTest.toDmiPluginRegistration(restDmiPluginRegistration)
+        then: 'Lists contain values'
+            assert result.createdCmHandles[0].class == NcmpServiceCmHandle.class
+            assert result.updatedCmHandles[0].class == NcmpServiceCmHandle.class
+            assert result.removedCmHandles == ["some-cmHandle"]
+    }
+
+    def 'Convert a ModuleReference to a RestModuleReference'() {
+        given: 'a ModuleReference'
+            def moduleReference = new ModuleReference()
+        when: 'toRestModuleReference is called'
+            def result = objectUnderTest.toRestModuleReference(moduleReference)
+        then: 'the result is of the correct class RestModuleReference'
+            result.class == RestModuleReference.class
+    }
 }