1 package org.onap.cps.ncmp.api.impl.async
3 import io.cloudevents.CloudEvent
4 import io.cloudevents.core.builder.CloudEventBuilder
5 import io.cloudevents.kafka.CloudEventSerializer
6 import org.apache.kafka.clients.producer.KafkaProducer
7 import org.apache.kafka.clients.producer.ProducerRecord
8 import org.onap.cps.ncmp.api.impl.events.EventsPublisher
9 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
10 import org.spockframework.spring.SpringBean
11 import org.springframework.beans.factory.annotation.Autowired
12 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
13 import org.springframework.boot.test.context.SpringBootTest
14 import org.springframework.kafka.config.KafkaListenerEndpointRegistry
15 import org.springframework.kafka.test.utils.ContainerTestUtils
16 import org.springframework.test.annotation.DirtiesContext
17 import org.testcontainers.spock.Testcontainers
18 import java.util.concurrent.TimeUnit
20 @SpringBootTest(classes =[NcmpAsyncDataOperationEventConsumer, DataOperationRecordFilterStrategy])
23 @EnableAutoConfiguration
24 class NcmpAsyncDataOperationEventConsumerIntegrationSpec extends MessagingBaseSpec {
27 private KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry
30 EventsPublisher mockEventsPublisher = Mock()
32 def activateListeners() {
33 kafkaListenerEndpointRegistry.getListenerContainers().forEach(
34 messageListenerContainer -> { ContainerTestUtils.waitForAssignment(messageListenerContainer, 1) }
38 def 'Filtering Events.'() {
39 given: 'a cloud event of type: #eventType'
40 def cloudEvent = CloudEventBuilder.v1().withId("some-uuid")
42 .withSource(URI.create("sample-test-source"))
44 and: 'activate message listener container'
46 when: 'send the cloud event'
47 ProducerRecord<String, CloudEvent> record = new ProducerRecord<>('ncmp-async-m2m', cloudEvent)
48 KafkaProducer<String, CloudEvent> producer = new KafkaProducer<>(eventProducerConfigProperties(CloudEventSerializer))
49 producer.send(record);
50 and: 'wait a little for async processing of message'
51 TimeUnit.MILLISECONDS.sleep(100)
52 then: 'the event has only been forwarded for the correct type'
53 expectedNUmberOfCallsToPublishForwardedEvent * mockEventsPublisher.publishCloudEvent(_, _, _)
55 eventType || expectedNUmberOfCallsToPublishForwardedEvent
56 'DataOperationEvent' || 1
58 'any type contain the word "DataOperationEvent"' || 1