Subscription Create Event Outcome Kafka Part
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / event / avc / SubscriptionEventResponseConsumerSpec.groovy
index e9f6689..80c9b69 100644 (file)
@@ -22,7 +22,9 @@ package org.onap.cps.ncmp.api.impl.event.avc
 
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.hazelcast.map.IMap
+import org.apache.kafka.clients.consumer.ConsumerRecord
 import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseMapper
+import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseOutcome
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistenceImpl
 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
 import org.onap.cps.ncmp.api.models.SubscriptionEventResponse
@@ -34,24 +36,24 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
 
     IMap<String, Set<String>> mockForwardedSubscriptionEventCache = Mock(IMap<String, Set<String>>)
     def mockSubscriptionPersistence = Mock(SubscriptionPersistenceImpl)
-    def mockSubscriptionEventResponseMapper = Mock(SubscriptionEventResponseMapper)
+    def mockSubscriptionEventResponseMapper  = Mock(SubscriptionEventResponseMapper)
+    def mockSubscriptionEventResponseOutcome = Mock(SubscriptionEventResponseOutcome)
 
     def objectUnderTest = new SubscriptionEventResponseConsumer(mockForwardedSubscriptionEventCache,
-        mockSubscriptionPersistence, mockSubscriptionEventResponseMapper)
+        mockSubscriptionPersistence, mockSubscriptionEventResponseMapper, mockSubscriptionEventResponseOutcome)
 
+    def cmHandleToStatusMap = [CMHandle1: 'PENDING', CMHandle2: 'ACCEPTED'] as Map
+    def testEventReceived = new SubscriptionEventResponse(clientId: 'some-client-id',
+        subscriptionName: 'some-subscription-name', dmiName: 'some-dmi-name', cmHandleIdToStatus: cmHandleToStatusMap)
+    def consumerRecord = new ConsumerRecord<String, SubscriptionEventResponse>('topic-name', 0, 0, 'event-key', testEventReceived)
 
     def 'Consume Subscription Event Response where all DMIs have responded'() {
-        given: 'a subscription event response with a clientId, subscriptionName and dmiName'
-            def testEventReceived = new SubscriptionEventResponse()
-            testEventReceived.clientId = 'some-client-id'
-            testEventReceived.subscriptionName = 'some-subscription-name'
-            testEventReceived.dmiName = 'some-dmi-name'
-        and: 'notifications are enabled'
+        given: 'a subscription event response and notifications are enabled'
             objectUnderTest.notificationFeatureEnabled = true
         and: 'subscription model loader is enabled'
             objectUnderTest.subscriptionModelLoaderEnabled = true
         when: 'the valid event is consumed'
-            objectUnderTest.consumeSubscriptionEventResponse(testEventReceived)
+            objectUnderTest.consumeSubscriptionEventResponse(consumerRecord)
         then: 'the forwarded subscription event cache returns only the received dmiName existing for the subscription create event'
             1 * mockForwardedSubscriptionEventCache.containsKey('some-client-idsome-subscription-name') >> true
             1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> (['some-dmi-name'] as Set)
@@ -59,20 +61,17 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
             1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> ([] as Set)
         and: 'the subscription event is removed from the map'
             1 * mockForwardedSubscriptionEventCache.remove('some-client-idsome-subscription-name')
+        and: 'a response outcome has been created'
+            1 * mockSubscriptionEventResponseOutcome.sendResponse('some-client-id', 'some-subscription-name', true)
     }
 
     def 'Consume Subscription Event Response where another DMI has not yet responded'() {
-        given: 'a subscription event response with a clientId, subscriptionName and dmiName'
-            def testEventReceived = new SubscriptionEventResponse()
-            testEventReceived.clientId = 'some-client-id'
-            testEventReceived.subscriptionName = 'some-subscription-name'
-            testEventReceived.dmiName = 'some-dmi-name'
-        and: 'notifications are enabled'
+        given: 'a subscription event response and notifications are enabled'
             objectUnderTest.notificationFeatureEnabled = true
         and: 'subscription model loader is enabled'
             objectUnderTest.subscriptionModelLoaderEnabled = true
         when: 'the valid event is consumed'
-            objectUnderTest.consumeSubscriptionEventResponse(testEventReceived)
+            objectUnderTest.consumeSubscriptionEventResponse(consumerRecord)
         then: 'the forwarded subscription event cache returns only the received dmiName existing for the subscription create event'
             1 * mockForwardedSubscriptionEventCache.containsKey('some-client-idsome-subscription-name') >> true
             1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> (['some-dmi-name', 'non-responded-dmi'] as Set)
@@ -80,5 +79,7 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
             1 * mockForwardedSubscriptionEventCache.get('some-client-idsome-subscription-name') >> (['non-responded-dmi'] as Set)
         and: 'the subscription event is not removed from the map'
             0 * mockForwardedSubscriptionEventCache.remove(_)
+        and: 'a response outcome has not been created'
+            0 * mockSubscriptionEventResponseOutcome.sendResponse(*_)
     }
 }