Agreed outstanding comments including package refactoring 78/134778/2
authorhalil.cakal <halil.cakal@est.tech>
Tue, 6 Jun 2023 15:20:55 +0000 (16:20 +0100)
committerhalil.cakal <halil.cakal@est.tech>
Wed, 7 Jun 2023 11:21:17 +0000 (12:21 +0100)
- Change package of AVC Subscription relevent codes into their place
- Change package of Subscription Event Cache config inot its place
- Add more branches for subscription outcome mapper
- Add more branches for subscription event response consumer
- Change unit test method params in order not to use deprecated methods

Issue-ID: CPS-1730
Change-Id: Ieda587d5be318db8360d52d49dc38d7ce3dd85cd
Signed-off-by: halil.cakal <halil.cakal@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfig.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/ForwardedSubscriptionEventCacheConfig.java with 97% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/ResponseTimeoutTask.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/ResponseTimeoutTask.java with 94% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarder.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumer.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumer.java with 95% similarity]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcome.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapper.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionOutcomeMapper.java with 98% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfigSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/ForwardedSubscriptionEventCacheConfigSpec.groovy with 98% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumerSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy with 69% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapperSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionOutcomeMapperSpec.groovy with 70% similarity]

  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.ncmp.api.impl.event.avc;
+package org.onap.cps.ncmp.api.impl.events.avcsubscription;
 
 import com.hazelcast.map.IMap;
 import java.util.Set;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseOutcome;
 
 @Slf4j
 @RequiredArgsConstructor
index 19a0f12..9e363f3 100644 (file)
@@ -35,8 +35,7 @@ import java.util.stream.Collectors;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.common.header.Headers;
-import org.onap.cps.ncmp.api.impl.event.avc.ForwardedSubscriptionEventCacheConfig;
-import org.onap.cps.ncmp.api.impl.event.avc.ResponseTimeoutTask;
+import org.onap.cps.ncmp.api.impl.config.embeddedcache.ForwardedSubscriptionEventCacheConfig;
 import org.onap.cps.ncmp.api.impl.events.EventsPublisher;
 import org.onap.cps.ncmp.api.impl.utils.DmiServiceNameOrganizer;
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
@@ -18,7 +18,7 @@
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.ncmp.api.impl.event.avc;
+package org.onap.cps.ncmp.api.impl.events.avcsubscription;
 
 import com.hazelcast.map.IMap;
 import java.util.Set;
@@ -26,8 +26,7 @@ import java.util.concurrent.TimeUnit;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 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.config.embeddedcache.ForwardedSubscriptionEventCacheConfig;
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence;
 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
 import org.onap.cps.ncmp.api.models.SubscriptionEventResponse;
index ade3f22..a746825 100644 (file)
@@ -30,7 +30,6 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.common.header.Headers;
 import org.apache.kafka.common.header.internals.RecordHeaders;
-import org.onap.cps.ncmp.api.impl.event.avc.SubscriptionOutcomeMapper;
 import org.onap.cps.ncmp.api.impl.events.EventsPublisher;
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence;
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus;
index 63ddcef..a9eaaee 100644 (file)
@@ -137,14 +137,14 @@ class SubscriptionEventForwarderSpec extends MessagingBaseSpec {
             0 * mockForwardedSubscriptionEventCache.put("SCO-9989752cm-subscription-001", ["DMIName1", "DMIName2"] as Set)
         and: 'the event is forwarded twice with the CMHandle private properties and provides a valid listenable future'
             0 * mockSubscriptionEventPublisher.publishEvent("ncmp-dmi-cm-avc-subscription-DMIName1", "SCO-9989752-cm-subscription-001-DMIName1",
-                subscriptionEvent -> {
+                consumerRecord.headers(),subscriptionEvent -> {
                     Map targets = subscriptionEvent.getEvent().getPredicates().getTargets().get(0)
                     targets["CMHandle1"] == ["shape":"circle"]
                     targets["CMHandle2"] == ["shape":"square"]
                 }
             )
             0 * mockSubscriptionEventPublisher.publishEvent("ncmp-dmi-cm-avc-subscription-DMIName2", "SCO-9989752-cm-subscription-001-DMIName2",
-                subscriptionEvent -> {
+                consumerRecord.headers(),subscriptionEvent -> {
                     Map targets = subscriptionEvent.getEvent().getPredicates().getTargets().get(0)
                     targets["CMHandle3"] == ["shape":"triangle"]
                 }
@@ -154,6 +154,8 @@ class SubscriptionEventForwarderSpec extends MessagingBaseSpec {
             0 * mockForwardedSubscriptionEventCache.get(_)
         and: 'the subscription id is removed from the event cache map returning the asynchronous blocking variable'
             0 * mockForwardedSubscriptionEventCache.remove("SCO-9989752cm-subscription-001") >> {block.set(_)}
+        and: 'subscription outcome has been sent'
+            1 * mockSubscriptionEventResponseOutcome.sendResponse('SCO-9989752', 'cm-subscription-001', true)
     }
 
     static def createYangModelCmHandleWithDmiProperty(id, dmiId,propertyName, propertyValue) {
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.ncmp.api.impl.event.avc
+package org.onap.cps.ncmp.api.impl.events.avcsubscription
 
 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
@@ -49,7 +47,7 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
 
     def 'Consume Subscription Event Response where all DMIs have responded'() {
         given: 'a subscription event response and notifications are enabled'
-            objectUnderTest.notificationFeatureEnabled = true
+            objectUnderTest.notificationFeatureEnabled = isNotificationFeatureEnabled
         and: 'subscription model loader is enabled'
             objectUnderTest.subscriptionModelLoaderEnabled = true
         when: 'the valid event is consumed'
@@ -62,7 +60,13 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
         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)
+            numberOfExpectedCallToSendResponse * mockSubscriptionEventResponseOutcome.sendResponse('some-client-id', 'some-subscription-name', isFullOutcomeResponse)
+        where: 'the following values are used'
+            scenario             | isNotificationFeatureEnabled | isFullOutcomeResponse             || numberOfExpectedCallToSendResponse
+            'Response sent'      | true                         | true                              || 1
+            'Response not sent'  | true                         | false                             || 0
+            'Response not sent'  | false                        | true                              || 0
+            'Response not sent'  | false                        | false                             || 0
     }
 
     def 'Consume Subscription Event Response where another DMI has not yet responded'() {
@@ -82,4 +86,21 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec {
         and: 'a response outcome has not been created'
             0 * mockSubscriptionEventResponseOutcome.sendResponse(*_)
     }
+
+    def 'Update subscription event when the model loader flag is enabled'() {
+        given: 'subscription model loader is enabled as per #scenario'
+            objectUnderTest.subscriptionModelLoaderEnabled = isSubscriptionModelLoaderEnabled
+        when: 'the valid event is consumed'
+            objectUnderTest.consumeSubscriptionEventResponse(consumerRecord)
+        then: 'the forwarded subscription event cache does not return dmiName for the subscription create event'
+            1 * mockForwardedSubscriptionEventCache.containsKey('some-client-idsome-subscription-name') >> false
+        and: 'the mapper returns yang model subscription event with #numberOfExpectedCall'
+            numberOfExpectedCall * mockSubscriptionEventResponseMapper.toYangModelSubscriptionEvent(_)
+        and: 'subscription event has been updated into DB with #numberOfExpectedCall'
+            numberOfExpectedCall * mockSubscriptionPersistence.saveSubscriptionEvent(_)
+        where: 'the following values are used'
+            scenario                   | isSubscriptionModelLoaderEnabled || numberOfExpectedCall
+            'The event is updated'     | true                             || 1
+            'The event is not updated' | false                            || 0
+    }
 }
index 53c5cd2..3570a9e 100644 (file)
@@ -22,7 +22,6 @@ package org.onap.cps.ncmp.api.impl.events.avcsubscription
 
 import com.fasterxml.jackson.databind.ObjectMapper
 import org.mapstruct.factory.Mappers
-import org.onap.cps.ncmp.api.impl.event.avc.SubscriptionOutcomeMapper
 import org.onap.cps.ncmp.api.impl.events.EventsPublisher
 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence
 import org.onap.cps.ncmp.api.impl.utils.DataNodeBaseSpec
@@ -32,7 +31,6 @@ import org.onap.cps.utils.JsonObjectMapper
 import org.spockframework.spring.SpringBean
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.context.SpringBootTest
-import org.testcontainers.shaded.org.bouncycastle.crypto.engines.EthereumIESEngine
 
 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper, SubscriptionOutcomeMapper, SubscriptionEventResponseOutcome])
 class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec {
@@ -56,14 +54,14 @@ class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec {
         when: 'a response is generated'
             def result = objectUnderTest.generateResponse('some-client-id', 'some-subscription-name', isFullOutcomeResponse)
         then: 'the result will have the same values as same as in dataNode4'
-            result.eventType == eventType
+            result.eventType == expectedEventType
             result.getEvent().getSubscription().getClientID() == 'some-client-id'
             result.getEvent().getSubscription().getName() == 'some-subscription-name'
             result.getEvent().getPredicates().getPendingTargets() == ['CMHandle3']
             result.getEvent().getPredicates().getRejectedTargets() == ['CMHandle1']
             result.getEvent().getPredicates().getAcceptedTargets() == ['CMHandle2']
         where: 'the following values are used'
-            scenario             | isFullOutcomeResponse || eventType
+            scenario             | isFullOutcomeResponse || expectedEventType
             'is full outcome'    | true                  || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
             'is partial outcome' | false                 || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
     }
@@ -74,7 +72,7 @@ class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec {
         and: 'an outcome event'
             def jsonData = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
             def eventOutcome = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventOutcome.class)
-            eventOutcome.setEventType(eventType)
+            eventOutcome.setEventType(expectedEventType)
         when: 'a subscription outcome message formed'
             def result = objectUnderTest.formSubscriptionOutcomeMessage(cmHandleIdToStatus, 'SCO-9989752',
                 'cm-subscription-001', isFullOutcomeResponse)
@@ -82,8 +80,8 @@ class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec {
         then: 'the result will be equal to event outcome'
             result == eventOutcome
         where: 'the following values are used'
-            scenario             | isFullOutcomeResponse | eventType
-            'is full outcome'    | true                  | SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
-            'is partial outcome' | false                 | SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
+            scenario             | isFullOutcomeResponse || expectedEventType
+            'is full outcome'    | true                  || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
+            'is partial outcome' | false                 || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
     }
 }
@@ -18,7 +18,7 @@
  *  ============LICENSE_END=========================================================
  */
 
-package org.onap.cps.ncmp.api.impl.event.avc
+package org.onap.cps.ncmp.api.impl.events.avcsubscription
 
 import com.fasterxml.jackson.databind.ObjectMapper
 import org.mapstruct.factory.Mappers
@@ -41,15 +41,20 @@ class SubscriptionOutcomeMapperSpec extends Specification {
 
     def 'Map subscription event response to subscription event outcome'() {
         given: 'a Subscription Response Event'
-            def jsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
-            def testEventToMap = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventResponse.class)
+            def subscriptionResponseJsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
+            def subscriptionResponseEvent = jsonObjectMapper.convertJsonString(subscriptionResponseJsonData, SubscriptionEventResponse.class)
         and: 'a Subscription Outcome Event'
             def jsonDataOutcome = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
-            def testEventTarget = jsonObjectMapper.convertJsonString(jsonDataOutcome, SubscriptionEventOutcome.class)
+            def expectedEventOutcome = jsonObjectMapper.convertJsonString(jsonDataOutcome, SubscriptionEventOutcome.class)
+            expectedEventOutcome.setEventType(expectedEventType)
         when: 'the subscription response event is mapped to a subscription event outcome'
-            def result = objectUnderTest.toSubscriptionEventOutcome(testEventToMap)
-            result.setEventType(SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME)
+            def result = objectUnderTest.toSubscriptionEventOutcome(subscriptionResponseEvent)
+            result.setEventType(expectedEventType)
         then: 'the resulting subscription event outcome contains the correct clientId'
-            assert result == testEventTarget
+            assert result == expectedEventOutcome
+        where: 'the following values are used'
+            scenario              || expectedEventType
+            'is full outcome'     || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
+            'is partial outcome'  || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
     }
 }
\ No newline at end of file