Schedule response to client 35/137835/1
authormpriyank <priyank.maheshwari@est.tech>
Fri, 3 May 2024 09:48:04 +0000 (10:48 +0100)
committermpriyank <priyank.maheshwari@est.tech>
Fri, 3 May 2024 09:48:09 +0000 (10:48 +0100)
- Scheduling sending the response by reading whatever is present in the
  cache for subscription after a pre-configured time.
- Also added test validation for the same

Issue-ID: CPS-2209
Change-Id: Ifacb0b12734a0529e671b0b63836189a243e453c
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionHandlerServiceImpl.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/cmsubscription/service/CmNotificationSubscriptionHandlerServiceImplSpec.groovy

index 395c511..7872ba0 100644 (file)
@@ -57,20 +57,26 @@ public class CmNotificationSubscriptionHandlerServiceImpl implements CmNotificat
         if (cmNotificationSubscriptionPersistenceService.isUniqueSubscriptionId(subscriptionId)) {
             dmiCmNotificationSubscriptionCacheHandler.add(subscriptionId, predicates);
             sendSubscriptionCreateRequestToDmi(subscriptionId);
+            scheduleCmNotificationSubscriptionNcmpOutEventResponse(subscriptionId);
         } else {
-            final Set<String> subscriptionTargetFilters = predicates.stream().flatMap(
-                    predicate -> predicate.getTargetFilter().stream()).collect(Collectors.toSet());
             rejectAndPublishCmNotificationSubscriptionCreateRequest(subscriptionId,
-                    new ArrayList<>(subscriptionTargetFilters));
+                    predicates);
         }
     }
 
+    private void scheduleCmNotificationSubscriptionNcmpOutEventResponse(final String subscriptionId) {
+        cmNotificationSubscriptionEventsHandler.publishCmNotificationSubscriptionNcmpOutEvent(subscriptionId,
+                "subscriptionCreateResponse", null, true);
+    }
+
     private void rejectAndPublishCmNotificationSubscriptionCreateRequest(final String subscriptionId,
-                                                                         final List<String> subscriptionTargetFilters) {
+            final List<Predicate> predicates) {
+        final Set<String> subscriptionTargetFilters =
+                predicates.stream().flatMap(predicate -> predicate.getTargetFilter().stream())
+                        .collect(Collectors.toSet());
         final CmNotificationSubscriptionNcmpOutEvent cmNotificationSubscriptionNcmpOutEvent =
-                cmNotificationSubscriptionMappersHandler
-                        .toCmNotificationSubscriptionNcmpOutEventForRejectedRequest(subscriptionId,
-                                subscriptionTargetFilters);
+                cmNotificationSubscriptionMappersHandler.toCmNotificationSubscriptionNcmpOutEventForRejectedRequest(
+                        subscriptionId, new ArrayList<>(subscriptionTargetFilters));
         cmNotificationSubscriptionEventsHandler.publishCmNotificationSubscriptionNcmpOutEvent(subscriptionId,
                 "subscriptionCreateResponse", cmNotificationSubscriptionNcmpOutEvent, false);
     }
index 7d1a1d6..98b4ee2 100644 (file)
@@ -72,6 +72,9 @@ class CmNotificationSubscriptionHandlerServiceImplSpec extends Specification{
         and: 'the events handler method to publish DMI event is called correct number of times with the correct parameters'
             testSubscriptionDetailsMap.size() * mockCmNotificationSubscriptionEventsHandler.publishCmNotificationSubscriptionDmiInEvent(
                 "test-id", "dmi-1", "subscriptionCreateRequest", testDmiInEvent)
+        and: 'we schedule to send the response after configured time from the cache'
+            1 * mockCmNotificationSubscriptionEventsHandler.publishCmNotificationSubscriptionNcmpOutEvent(
+                "test-id", "subscriptionCreateResponse", null, true)
     }
 
     def 'Consume valid and but non-unique CmNotificationSubscription create message'() {