From 277dcbf4e63d8ba063498485f6976de1321120d5 Mon Sep 17 00:00:00 2001
From: Alok Joshi <AJoshi19@slb.com>
Date: Wed, 29 Mar 2023 12:15:04 -0500
Subject: [PATCH] unit tests

---
 .../messageBus/SubscriptionManagerImplTest.java       | 11 +++++++++++
 .../messageBus/models/TopicSubscriptionsTest.java     | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java
index 86296de13..efa74f523 100644
--- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java
+++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/messageBus/SubscriptionManagerImplTest.java
@@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit;
 
 import static java.lang.Thread.sleep;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.atLeast;
 import static org.mockito.Mockito.doNothing;
@@ -182,6 +183,16 @@ public class SubscriptionManagerImplTest {
         verify(subscriptionClient, times(1)).registerMessageHandler(any(), any(), any());
     }
 
+    @Test
+    public void shouldCloseSubscriptionClientWhenSubscriptionIsDeleted() throws ServiceBusException, InterruptedException {
+        when(topicSubscriptions.checkIfNewTopicSubscription(anyString(), anyString(), anyString())).thenReturn(false);
+        when(subscriptionClientFactory.getSubscriptionClient(dataPartition, sbTopic, sbSubscription)).thenReturn(subscriptionClient);
+        doNothing().when(topicSubscriptions).updateCurrentTopicSubscriptions(anyString(), anyString(), anyString());
+        when(topicSubscriptions.getDeletedTopicSubscriptions(anyString(), anyString(), anyList())).thenReturn(Collections.singletonList(getHmac_subscription().getNotificationId()));
+        subscriptionManager.subscribeNotificationsEvent();
+        verify(subscriptionClient, times(1)).close();
+    }
+
     private static Subscription getHmac_subscription() {
         Subscription hmac_subscription = new Subscription();
         hmac_subscription.setName("hamc_test_subscription");
diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java
index 3f657ed0b..d80372c78 100644
--- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java
+++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/messageBus/models/TopicSubscriptionsTest.java
@@ -9,6 +9,7 @@ import org.mockito.junit.MockitoJUnitRunner;
 import org.springframework.test.util.ReflectionTestUtils;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -76,4 +77,14 @@ public class TopicSubscriptionsTest {
         assertEquals(existingTopicSubscriptions.size(), 1);
         assertEquals(currentTopicSubscriptions.size(), 0);
     }
+
+    @Test
+    public void deletedSubscriptionFoundTest() {
+        final String DELETED_SUBSCRIPTION = "test678asdeleted";
+        existingTopicSubscriptions.get(PARTITION).get(SBTOPICNAME).add(DELETED_SUBSCRIPTION);
+
+        List<String> deletedSubscriptions = topicSubscriptions.getDeletedTopicSubscriptions(PARTITION, SBTOPICNAME, Arrays.asList(EXISTINGSUBSCRIPTION));
+        assertEquals(1, deletedSubscriptions.size());
+        assertEquals(DELETED_SUBSCRIPTION, deletedSubscriptions.get(0));
+    }
 }
-- 
GitLab