Migration to TAPI 2.4 Step2
[transportpce.git] / nbinotifications / src / test / java / org / opendaylight / transportpce / nbinotifications / consumer / SubscriberTest.java
index c32142f23b57e047cca5707190ddbb77b0927351..af6fdca091e3e627ee3f8825d4a037e839f587cd 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.transportpce.nbinotifications.consumer;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -18,33 +19,39 @@ import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.apache.kafka.clients.consumer.MockConsumer;
 import org.apache.kafka.clients.consumer.OffsetResetStrategy;
 import org.apache.kafka.common.TopicPartition;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.transportpce.nbinotifications.utils.NotificationServiceDataUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.get.notifications.alarm.service.output.NotificationsAlarmService;
-import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.get.notifications.process.service.output.NotificationsProcessService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.alarm.service.output.NotificationsAlarmService;
+import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.process.service.output.NotificationsProcessService;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.list.output.Notification;
 
 public class SubscriberTest extends AbstractTest {
     private static final String TOPIC = "topic";
     private static final int PARTITION = 0;
     private MockConsumer<String, NotificationsProcessService> mockConsumer;
     private MockConsumer<String, NotificationsAlarmService> mockConsumerAlarm;
+    private MockConsumer<String, Notification> mockConsumerTapi;
     private Subscriber<NotificationProcessService, NotificationsProcessService> subscriberService;
     private Subscriber<NotificationAlarmService, NotificationsAlarmService> subscriberAlarmService;
+    private Subscriber<NotificationTapiService, Notification> subscriberTapiService;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
         mockConsumerAlarm = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
+        mockConsumerTapi = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
         subscriberService = new Subscriber<>(mockConsumer);
         subscriberAlarmService = new Subscriber<>(mockConsumerAlarm);
+        subscriberTapiService = new Subscriber<>(mockConsumerTapi);
     }
 
     @Test
-    public void subscribeServiceShouldBeSuccessful() {
+    void subscribeServiceShouldBeSuccessful() {
         // from https://www.baeldung.com/kafka-mockconsumer
         ConsumerRecord<String, NotificationsProcessService> record = new ConsumerRecord<>(
                 TOPIC, PARTITION, 0L, "key", NotificationServiceDataUtils.buildReceivedEvent());
@@ -59,12 +66,12 @@ public class SubscriberTest extends AbstractTest {
         mockConsumer.updateBeginningOffsets(startOffsets);
         List<NotificationsProcessService> result = subscriberService.subscribe(TOPIC,
                 NotificationsProcessService.QNAME);
-        assertEquals("There should be 1 record", 1, result.size());
-        assertTrue("Consumer should be closed", mockConsumer.closed());
+        assertEquals(1, result.size(), "There should be 1 record");
+        assertTrue(mockConsumer.closed(), "Consumer should be closed");
     }
 
     @Test
-    public void subscribeAlarmShouldBeSuccessful() {
+    void subscribeAlarmShouldBeSuccessful() {
         // from https://www.baeldung.com/kafka-mockconsumer
         ConsumerRecord<String, NotificationsAlarmService> record = new ConsumerRecord<>(
                 TOPIC, PARTITION, 0L, "key", NotificationServiceDataUtils.buildReceivedAlarmEvent());
@@ -79,7 +86,27 @@ public class SubscriberTest extends AbstractTest {
         mockConsumerAlarm.updateBeginningOffsets(startOffsets);
         List<NotificationsAlarmService> result = subscriberAlarmService.subscribe(TOPIC,
                 NotificationsAlarmService.QNAME);
-        assertEquals("There should be 1 record", 1, result.size());
-        assertTrue("Consumer should be closed", mockConsumerAlarm.closed());
+        assertEquals(1, result.size(), "There should be 1 record");
+        assertTrue(mockConsumerAlarm.closed(), "Consumer should be closed");
+    }
+
+    @Test
+    void subscribeTapiAlarmShouldBeSuccessful() {
+        // from https://www.baeldung.com/kafka-mockconsumer
+        ConsumerRecord<String, Notification> record = new ConsumerRecord<>(
+            TOPIC, PARTITION, 0L, "key", NotificationServiceDataUtils.buildReceivedTapiAlarmEvent());
+        mockConsumerTapi.schedulePollTask(() -> {
+            mockConsumerTapi.rebalance(Collections.singletonList(new TopicPartition(TOPIC, PARTITION)));
+            mockConsumerTapi.addRecord(record);
+        });
+
+        Map<TopicPartition, Long> startOffsets = new HashMap<>();
+        TopicPartition tp = new TopicPartition(TOPIC, PARTITION);
+        startOffsets.put(tp, 0L);
+        mockConsumerTapi.updateBeginningOffsets(startOffsets);
+        List<Notification> result = subscriberTapiService.subscribe(TOPIC,
+            NotificationTapiService.QNAME);
+        assertEquals(1, result.size(), "There should be 1 record");
+        assertTrue(mockConsumerTapi.closed(), "Consumer should be closed");
     }
 }