2 * ============LICENSE_START========================================================
3 * Copyright (c) 2023 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.impl.utils
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import io.cloudevents.core.builder.CloudEventBuilder
25 import org.onap.cps.ncmp.events.avcsubscription1_0_0.dmi_to_ncmp.SubscriptionEventResponse
26 import org.onap.cps.ncmp.utils.TestUtils
27 import org.onap.cps.utils.JsonObjectMapper
28 import org.springframework.beans.factory.annotation.Autowired
29 import org.springframework.boot.test.context.SpringBootTest
30 import spock.lang.Specification
32 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper])
33 class SubscriptionEventResponseCloudMapperSpec extends Specification {
36 JsonObjectMapper jsonObjectMapper
39 ObjectMapper objectMapper
41 def spyObjectMapper = Spy(ObjectMapper)
43 def objectUnderTest = new SubscriptionEventResponseCloudMapper(spyObjectMapper)
45 def 'Map the cloud event to subscription event response'() {
46 given: 'a cloud event having a subscription event response in the data part'
47 def jsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
48 def testEventData = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventResponse.class)
49 def testCloudEvent = CloudEventBuilder.v1()
50 .withData(objectMapper.writeValueAsBytes(testEventData))
51 .withId('some-event-id')
52 .withType('subscriptionCreatedStatus')
53 .withSource(URI.create('some-resource'))
54 .withExtension('correlationid', 'test-cmhandle1').build()
55 when: 'the cloud event map to subscription event response'
56 def resultSubscriptionEvent = objectUnderTest.toSubscriptionEventResponse(testCloudEvent)
57 then: 'the subscription event resulted having expected values'
58 resultSubscriptionEvent.getData() == testEventData.getData()
61 def 'Map null of the data of the cloud event to subscription event response'() {
62 given: 'a cloud event having a null subscription event response in the data part'
63 def testCloudEvent = CloudEventBuilder.v1()
65 .withId('some-event-id')
66 .withType('subscriptionCreatedStatus')
67 .withSource(URI.create('some-resource'))
68 .withExtension('correlationid', 'test-cmhandle1').build()
69 when: 'the cloud event map to subscription event response'
70 def resultSubscriptionEvent = objectUnderTest.toSubscriptionEventResponse(testCloudEvent)
71 then: 'the subscription event response resulted having a null value'
72 resultSubscriptionEvent == null