summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2022-06-01 13:19:14 +0000
committerGerrit Code Review <gerrit@onap.org>2022-06-01 13:19:14 +0000
commit8acaa7d71bca663aeeb7006f90474843b602ffb6 (patch)
treea2019f85a0c861e98ecaff782c26924ed8b93126 /cps-ncmp-service/src/test/groovy
parent5d3ed6ff2fe76e2510867379fdf58d4e99b2cc9f (diff)
parentb1e5b94de8424a481e5152cc8e89d920268f31ee (diff)
Merge "DMI-NCMP Asynchronously Publish Response Event to Client Topic"
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventMapperSpec.groovy67
1 files changed, 67 insertions, 0 deletions
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
index 0000000000..07e9b49ff6
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventMapperSpec.groovy
@@ -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']
+ }
+}