diff options
author | lukegleeson <luke.gleeson@est.tech> | 2022-03-02 14:32:47 +0000 |
---|---|---|
committer | lukegleeson <luke.gleeson@est.tech> | 2022-03-10 17:58:57 +0000 |
commit | d5bda8848a661465f214b0bf11211e63b272cfd6 (patch) | |
tree | 58a6a5e01ca0d5a80d0ada491e3b59c9ee7781c5 /cps-ncmp-rest/src/test | |
parent | 3d02e9210625b75419089a3f5612f386c3b997ea (diff) |
Replacing ModelMapper with MapStruct
- Removed Model Mapper from pom files
- Replaced ModelMapper with MapStruct
- Added Tests for MapStruct
- Changed mapstruct annotations for individual variables to be null safe rather than all variables
- Excluded generated code from code coverage
- Set ModuleReferences input to required for SchemaSet so that ModuleReferences list set to empty list rather than null
Issue-ID: CPS-127
Signed-off-by: lukegleeson <luke.gleeson@est.tech>
Change-Id: I43f874aea79f58dda5526c6fdead27d8474d90af
Diffstat (limited to 'cps-ncmp-rest/src/test')
-rw-r--r-- | cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy (renamed from cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/RestInputMapperSpec.groovy) | 30 | ||||
-rw-r--r-- | cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy | 7 | ||||
-rw-r--r-- | cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy | 4 | ||||
-rw-r--r-- | cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy | 11 |
4 files changed, 38 insertions, 14 deletions
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/RestInputMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy index ed938810c0..3d54a0b089 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/RestInputMapperSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy @@ -21,13 +21,16 @@ 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 + } } diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy index c99771443a..a506e6ae02 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy @@ -22,7 +22,7 @@ package org.onap.cps.ncmp.rest.controller - +import org.mapstruct.factory.Mappers import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH @@ -36,7 +36,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE import com.fasterxml.jackson.databind.ObjectMapper -import org.modelmapper.ModelMapper import org.onap.cps.TestUtils import org.onap.cps.spi.model.ModuleReference import org.onap.cps.utils.JsonObjectMapper @@ -60,10 +59,10 @@ class NetworkCmProxyControllerSpec extends Specification { NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock() @SpringBean - ModelMapper modelMapper = new ModelMapper() + JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) @SpringBean - JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) + NcmpRestInputMapper ncmpRestInputMapper = Mappers.getMapper(NcmpRestInputMapper) @Value('${rest.api.ncmp-base-path}/v1') def ncmpBasePathV1 diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy index 079554a22d..9b1c2e87c0 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy @@ -49,7 +49,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock() @SpringBean - RestInputMapper restInputMapper = Mock() + NcmpRestInputMapper ncmpRestInputMapper = Mock() DmiPluginRegistration mockDmiPluginRegistration = Mock() @@ -64,7 +64,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { and: 'the expected rest input as an object' def expectedRestDmiPluginRegistration = jsonObjectMapper.convertJsonString(jsonData, RestDmiPluginRegistration) and: 'the converter returns a dmi registration (only for the expected input object)' - restInputMapper.toDmiPluginRegistration(expectedRestDmiPluginRegistration) >> mockDmiPluginRegistration + ncmpRestInputMapper.toDmiPluginRegistration(expectedRestDmiPluginRegistration) >> mockDmiPluginRegistration when: 'post request is performed & registration is called with correct DMI plugin information' def response = mvc.perform( post("$ncmpBasePathV1/ch") diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy index 8004328bc2..3c39a3307e 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy @@ -21,13 +21,15 @@ package org.onap.cps.ncmp.rest.exceptions +import com.fasterxml.jackson.databind.ObjectMapper import groovy.json.JsonSlurper -import org.modelmapper.ModelMapper +import org.mapstruct.factory.Mappers import org.onap.cps.TestUtils import org.onap.cps.ncmp.api.NetworkCmProxyDataService import org.onap.cps.ncmp.api.impl.exception.DmiRequestException import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException -import org.onap.cps.ncmp.rest.controller.RestInputMapper +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle +import org.onap.cps.ncmp.rest.controller.NcmpRestInputMapper import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.exceptions.DataNodeNotFoundException import org.onap.cps.spi.exceptions.DataValidationException @@ -58,13 +60,10 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification { NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock() @SpringBean - ModelMapper modelMapper = Stub() - - @SpringBean JsonObjectMapper jsonObjectMapper = Stub() @SpringBean - RestInputMapper restInputMapper = Mock() + NcmpRestInputMapper ncmpRestInputMapper = Mappers.getMapper(NcmpRestInputMapper) @Value('${rest.api.ncmp-base-path}') def basePathNcmp |