Update depcrecated method in KafaConfig
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / async / NcmpAsyncRequestResponseEventMapperSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2022 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.api.impl.async
22
23 import org.mapstruct.factory.Mappers
24 import org.onap.cps.ncmp.event.model.DmiAsyncRequestResponseEvent
25 import org.onap.cps.ncmp.event.model.EventContent
26 import org.onap.cps.ncmp.event.model.NcmpAsyncRequestResponseEvent
27 import org.onap.cps.ncmp.event.model.ResponseData
28 import spock.lang.Specification
29
30 class NcmpAsyncRequestResponseEventMapperSpec extends Specification {
31
32     def objectUnderTest = Mappers.getMapper(NcmpAsyncRequestResponseEventMapper.class)
33
34     def 'Convert dmi async request response event to ncmp async request response event'() {
35         given: 'a dmi async request response event'
36             def dmiAsyncRequestResponseEvent = new DmiAsyncRequestResponseEvent()
37                     .withEventCorrelationId("correlation-id-123").withEventContent(new EventContent()
38                     .withResponseData(new ResponseData()))
39         and: 'the event Id and time are empty'
40             dmiAsyncRequestResponseEvent.withEventId('').withEventTime('')
41         when: 'mapper is called'
42             def result = objectUnderTest.toNcmpAsyncEvent(dmiAsyncRequestResponseEvent)
43         then: 'result is of the correct type'
44             assert result.class == NcmpAsyncRequestResponseEvent.class
45         and: 'eventId and eventTime should be overridden by custom method with non-empty values'
46             assert result.eventId != ''
47             assert result.eventTime != ''
48         and: 'target eventCorrelationId of mapped object should be same as source eventCorrelationId'
49             assert result.eventCorrelationId == "correlation-id-123"
50     }
51
52     def 'Dmi async request response event is mapped correctly to forwarded event'() {
53         given: 'a dmi async request response event'
54             def dmiAsyncRequestResponseEvent = new DmiAsyncRequestResponseEvent()
55                     .withEventContent(new EventContent().withResponseCode('200')
56                             .withResponseData(new ResponseData().withAdditionalProperty('property1', 'value1')
57                                     .withAdditionalProperty('property2', 'value2')))
58         when: 'mapper is called'
59             def result = objectUnderTest.toNcmpAsyncEvent(dmiAsyncRequestResponseEvent)
60         then: 'result is of the correct type'
61             assert result.class == NcmpAsyncRequestResponseEvent.class
62         and: 'forwarded event content response code is mapped correctly'
63             assert result.forwardedEvent.responseCode == '200'
64         and: 'after mapping additional properties should be stored'
65             result.forwardedEvent.additionalProperties.'response-data' == ['property2': 'value2', 'property1': 'value1']
66     }
67 }