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.async
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import io.cloudevents.core.builder.CloudEventBuilder
25 import org.onap.cps.ncmp.api.impl.config.kafka.KafkaConfig
26 import org.onap.cps.ncmp.api.impl.events.EventsPublisher
27 import org.onap.cps.ncmp.api.kafka.ConsumerBaseSpec
28 import org.onap.cps.ncmp.events.async1_0_0.Data
29 import org.onap.cps.ncmp.events.async1_0_0.DataOperationEvent
30 import org.onap.cps.ncmp.events.async1_0_0.Response
31 import org.spockframework.spring.SpringBean
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.beans.factory.annotation.Value
34 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
35 import org.springframework.boot.test.context.SpringBootTest
36 import org.springframework.test.annotation.DirtiesContext
37 import org.testcontainers.spock.Testcontainers
39 import java.util.concurrent.TimeUnit
41 @SpringBootTest(classes =[DataOperationEventConsumer, RecordFilterStrategies, KafkaConfig])
44 @EnableAutoConfiguration
45 class SerializationIntegrationSpec extends ConsumerBaseSpec {
48 EventsPublisher mockEventsPublisher = Mock()
51 private ObjectMapper objectMapper
53 @Value('${app.ncmp.async-m2m.topic}')
56 def capturedForwardedEvent
58 def 'Forwarding DataOperation Event Data.'() {
59 given: 'a data operation cloud event'
60 def cloudEventSent = createCloudEvent()
61 when: 'send the event'
62 cloudEventKafkaTemplate.send(topic, cloudEventSent)
63 and: 'wait a little for async processing of message'
64 TimeUnit.MILLISECONDS.sleep(300)
65 then: 'the event has been forwarded'
66 1 * mockEventsPublisher.publishCloudEvent('some client topic', 'my-event-id', _) >> { args -> { capturedForwardedEvent = args[2] } }
67 and: 'the forwarded event is identical to the event that was sent'
68 assert capturedForwardedEvent == cloudEventSent
71 def createCloudEvent() {
72 def dataOperationEvent = new DataOperationEvent(data: new Data(responses: [new Response()]))
73 return CloudEventBuilder.v1()
74 .withId('my-event-id')
75 .withType('DataOperationEvent')
76 .withSource(URI.create('some-source'))
77 .withExtension('destination','some client topic')
78 .withData(objectMapper.writeValueAsBytes(dataOperationEvent))