DMI-NCMP Asynchronously Publish Response Event to Client Topic 21/129421/3
authorsourabh_sourabh <sourabh.sourabh@est.tech>
Mon, 30 May 2022 12:20:47 +0000 (13:20 +0100)
committersourabh_sourabh <sourabh.sourabh@est.tech>
Wed, 1 Jun 2022 09:04:28 +0000 (10:04 +0100)
- [NCMP] Added Unit Tests for NcmpAsyncRequestResponseEventMapper.java

Issue-ID: CPS-830
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Change-Id: I64dad7f0bb9b64e1864f19db5a5d74922dc6a83b

cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventMapperSpec.groovy [new file with mode: 0644]

diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventMapperSpec.groovy
new file mode 100644 (file)
index 0000000..07e9b49
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2022 Nordix Foundation
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.async
+
+import org.mapstruct.factory.Mappers
+import org.onap.cps.ncmp.event.model.DmiAsyncRequestResponseEvent
+import org.onap.cps.ncmp.event.model.EventContent
+import org.onap.cps.ncmp.event.model.NcmpAsyncRequestResponseEvent
+import org.onap.cps.ncmp.event.model.ResponseData
+import spock.lang.Specification
+
+class NcmpAsyncRequestResponseEventMapperSpec extends Specification {
+
+    def objectUnderTest = Mappers.getMapper(NcmpAsyncRequestResponseEventMapper.class)
+
+    def 'Convert dmi async request response event to ncmp async request response event'() {
+        given: 'a dmi async request response event'
+            def dmiAsyncRequestResponseEvent = new DmiAsyncRequestResponseEvent()
+                    .withEventCorrelationId("correlation-id-123").withEventContent(new EventContent()
+                    .withResponseData(new ResponseData()))
+        and: 'the event Id and time are empty'
+            dmiAsyncRequestResponseEvent.withEventId('').withEventTime('')
+        when: 'mapper is called'
+            def result = objectUnderTest.toNcmpAsyncEvent(dmiAsyncRequestResponseEvent)
+        then: 'result is of the correct type'
+            assert result.class == NcmpAsyncRequestResponseEvent.class
+        and: 'eventId and eventTime should be overridden by custom method with non-empty values'
+            assert result.eventId != ''
+            assert result.eventTime != ''
+        and: 'target eventCorrelationId of mapped object should be same as source eventCorrelationId'
+            assert result.eventCorrelationId == "correlation-id-123"
+    }
+
+    def 'Dmi async request response event is mapped correctly to forwarded event'() {
+        given: 'a dmi async request response event'
+            def dmiAsyncRequestResponseEvent = new DmiAsyncRequestResponseEvent()
+                    .withEventContent(new EventContent().withResponseCode('200')
+                            .withResponseData(new ResponseData().withAdditionalProperty('property1', 'value1')
+                                    .withAdditionalProperty('property2', 'value2')))
+        when: 'mapper is called'
+            def result = objectUnderTest.toNcmpAsyncEvent(dmiAsyncRequestResponseEvent)
+        then: 'result is of the correct type'
+            assert result.class == NcmpAsyncRequestResponseEvent.class
+        and: 'forwarded event content response code is mapped correctly'
+            assert result.forwardedEvent.responseCode == '200'
+        and: 'after mapping additional properties should be stored'
+            result.forwardedEvent.additionalProperties.'response-data' == ['property2': 'value2', 'property1': 'value1']
+    }
+}