From b1e5b94de8424a481e5152cc8e89d920268f31ee Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Mon, 30 May 2022 13:20:47 +0100 Subject: DMI-NCMP Asynchronously Publish Response Event to Client Topic - [NCMP] Added Unit Tests for NcmpAsyncRequestResponseEventMapper.java Issue-ID: CPS-830 Signed-off-by: sourabh_sourabh Change-Id: I64dad7f0bb9b64e1864f19db5a5d74922dc6a83b --- .../NcmpAsyncRequestResponseEventMapperSpec.groovy | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/NcmpAsyncRequestResponseEventMapperSpec.groovy 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 000000000..07e9b49ff --- /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'] + } +} -- cgit 1.2.3-korg