X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=nbinotifications%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnbinotifications%2Fconsumer%2FSubscriberTest.java;h=7e5fcf615a00f5bbb55194a2df6fe253b3fe44f5;hb=274148a8d813140f86e1f9770ba992b072c1a5cd;hp=de58a498af4234e7635911e37d7af075a9d7ef3d;hpb=28f2a7aea63e35dd31dd883aa796d11838959324;p=transportpce.git diff --git a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/consumer/SubscriberTest.java b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/consumer/SubscriberTest.java index de58a498a..7e5fcf615 100644 --- a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/consumer/SubscriberTest.java +++ b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/consumer/SubscriberTest.java @@ -22,24 +22,31 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.transportpce.nbinotifications.utils.NotificationServiceDataUtils; import org.opendaylight.transportpce.test.AbstractTest; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.get.notifications.service.output.NotificationService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.alarm.service.output.NotificationsAlarmService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.process.service.output.NotificationsProcessService; public class SubscriberTest extends AbstractTest { private static final String TOPIC = "topic"; private static final int PARTITION = 0; - private MockConsumer mockConsumer; - private Subscriber subscriber; + private MockConsumer mockConsumer; + private MockConsumer mockConsumerAlarm; + private Subscriber subscriberService; + private Subscriber subscriberAlarmService; @Before public void setUp() { mockConsumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST); - subscriber = new Subscriber(mockConsumer); + mockConsumerAlarm = new MockConsumer<>(OffsetResetStrategy.EARLIEST); + subscriberService = new Subscriber<>(mockConsumer); + subscriberAlarmService = new Subscriber<>(mockConsumerAlarm); } @Test public void subscribeServiceShouldBeSuccessful() { // from https://www.baeldung.com/kafka-mockconsumer - ConsumerRecord record = new ConsumerRecord( + ConsumerRecord record = new ConsumerRecord<>( TOPIC, PARTITION, 0L, "key", NotificationServiceDataUtils.buildReceivedEvent()); mockConsumer.schedulePollTask(() -> { mockConsumer.rebalance(Collections.singletonList(new TopicPartition(TOPIC, PARTITION))); @@ -50,8 +57,29 @@ public class SubscriberTest extends AbstractTest { TopicPartition tp = new TopicPartition(TOPIC, PARTITION); startOffsets.put(tp, 0L); mockConsumer.updateBeginningOffsets(startOffsets); - List result = subscriber.subscribeService(TOPIC); + List result = subscriberService.subscribe(TOPIC, + NotificationsProcessService.QNAME); assertEquals("There should be 1 record", 1, result.size()); assertTrue("Consumer should be closed", mockConsumer.closed()); } + + @Test + public void subscribeAlarmShouldBeSuccessful() { + // from https://www.baeldung.com/kafka-mockconsumer + ConsumerRecord record = new ConsumerRecord<>( + TOPIC, PARTITION, 0L, "key", NotificationServiceDataUtils.buildReceivedAlarmEvent()); + mockConsumerAlarm.schedulePollTask(() -> { + mockConsumerAlarm.rebalance(Collections.singletonList(new TopicPartition(TOPIC, PARTITION))); + mockConsumerAlarm.addRecord(record); + }); + + Map startOffsets = new HashMap<>(); + TopicPartition tp = new TopicPartition(TOPIC, PARTITION); + startOffsets.put(tp, 0L); + mockConsumerAlarm.updateBeginningOffsets(startOffsets); + List result = subscriberAlarmService.subscribe(TOPIC, + NotificationsAlarmService.QNAME); + assertEquals("There should be 1 record", 1, result.size()); + assertTrue("Consumer should be closed", mockConsumerAlarm.closed()); + } }