Add event to mapper as well 12/133712/3
authormpriyank <priyank.maheshwari@est.tech>
Tue, 21 Mar 2023 09:59:00 +0000 (09:59 +0000)
committermpriyank <priyank.maheshwari@est.tech>
Tue, 21 Mar 2023 11:08:19 +0000 (11:08 +0000)
- Explicitly add event to the mapper
- Also parameterized the cm-events topic to be overridden later

Issue-ID: CPS-1554
Change-Id: Ia6e75117dbb4214648d40318989c4c5fe6fd69f1
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
cps-application/src/main/resources/application.yml
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventMapper.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventProducer.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/notifications/avc/AvcEventProducerIntegrationSpec.groovy
cps-ncmp-service/src/test/resources/application.yml

index 02902de..0007bc8 100644 (file)
@@ -99,6 +99,7 @@ app:
             topic: ${NCMP_ASYNC_M2M_TOPIC:ncmp-async-m2m}\r
         avc:\r
             subscription-topic: ${NCMP_CM_AVC_SUBSCRIPTION:cm-avc-subscription}\r
+            cm-events-topic: ${NCMP_CM_EVENTS_TOPIC:cm-events}\r
     lcm:\r
         events:\r
             topic: ${LCM_EVENTS_TOPIC:ncmp-events}\r
index b6dc467..aaa06c6 100644 (file)
@@ -40,6 +40,7 @@ public interface AvcEventMapper {
     @Mapping(source = "eventSchemaVersion", target = "eventSchemaVersion")
     @Mapping(source = "eventSource", target = "eventSource")
     @Mapping(source = "eventType", target = "eventType")
+    @Mapping(source = "event", target = "event")
     AvcEvent toOutgoingAvcEvent(AvcEvent incomingAvcEvent);
 
     @Named("avcEventId")
index 049f661..b8fe730 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.impl.notifications.avc;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.ncmp.event.model.AvcEvent;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.kafka.core.KafkaTemplate;
 import org.springframework.stereotype.Service;
 
@@ -38,6 +39,9 @@ public class AvcEventProducer {
 
     private final AvcEventMapper avcEventMapper;
 
+    @Value("${app.ncmp.avc.cm-events-topic}")
+    private String cmEventsTopic;
+
     /**
      * Sends message to the configured topic with a message key.
      *
@@ -46,7 +50,7 @@ public class AvcEventProducer {
     public void sendMessage(final AvcEvent incomingAvcEvent) {
         // generate new event id while keeping other data
         final AvcEvent outgoingAvcEvent = avcEventMapper.toOutgoingAvcEvent(incomingAvcEvent);
-        log.debug("Forwarding AVC event {} to topic {} ", outgoingAvcEvent.getEventId(), "cm-events");
-        kafkaTemplate.send("cm-events", outgoingAvcEvent.getEventId(), outgoingAvcEvent);
+        log.debug("Forwarding AVC event {} to topic {} ", outgoingAvcEvent.getEventId(), cmEventsTopic);
+        kafkaTemplate.send(cmEventsTopic, outgoingAvcEvent.getEventId(), outgoingAvcEvent);
     }
 }
index 7447370..a251ecb 100644 (file)
@@ -56,8 +56,10 @@ class AvcEventProducerIntegrationSpec extends MessagingBaseSpec {
     def kafkaConsumer = new KafkaConsumer<>(consumerConfigProperties('ncmp-group'))
 
     def 'Consume and forward valid message'() {
-        given: 'consumer has a subscription'
-            kafkaConsumer.subscribe(['cm-events'] as List<String>)
+        given: 'consumer has a subscription on a topic'
+            def cmEventsTopic = 'cm-events'
+            avcEventProducer.cmEventsTopic = cmEventsTopic
+            kafkaConsumer.subscribe([cmEventsTopic] as List<String>)
         and: 'an event is sent'
             def jsonData = TestUtils.getResourceFileContent('sampleAvcInputEvent.json')
             def testEventSent = jsonObjectMapper.convertJsonString(jsonData, AvcEvent.class)
index b7dfe86..e66f23d 100644 (file)
@@ -20,6 +20,7 @@ app:
     ncmp:
         avc:
             subscription-topic: cm-avc-subscription
+            cm-events-topic: cm-events
 
 ncmp:
     dmi: