Merge "Debug tool for openconfig proprietary extensions"
[transportpce.git] / nbinotifications / src / test / java / org / opendaylight / transportpce / nbinotifications / producer / PublisherTest.java
index 507fb9e043f4b3dd9a7b5f7dc08f06d3b24f79ff..8030b9253f5ac51902697d0ccb0bb94b24ee9bfb 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.transportpce.nbinotifications.producer;
 
-import static org.junit.Assert.assertEquals;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.IOException;
 import java.nio.file.Files;
@@ -18,14 +19,17 @@ import java.util.Map;
 import java.util.concurrent.ExecutionException;
 import org.apache.kafka.clients.producer.MockProducer;
 import org.apache.kafka.common.serialization.StringSerializer;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
-import org.opendaylight.transportpce.common.network.RequestProcessor;
-import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsImpl;
+import org.opendaylight.transportpce.nbinotifications.impl.NbiNotificationsProvider;
+import org.opendaylight.transportpce.nbinotifications.impl.rpc.CreateNotificationSubscriptionServiceImpl;
 import org.opendaylight.transportpce.nbinotifications.serialization.ConfigConstants;
 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceSerializer;
 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceSerializer;
@@ -33,17 +37,25 @@ import org.opendaylight.transportpce.nbinotifications.serialization.TapiNotifica
 import org.opendaylight.transportpce.nbinotifications.utils.NotificationServiceDataUtils;
 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
 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.NotificationTapiService;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.input.SubscriptionFilter;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.input.SubscriptionFilterBuilder;
+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.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.CreateNotificationSubscriptionServiceInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.create.notification.subscription.service.input.SubscriptionFilter;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.create.notification.subscription.service.input.SubscriptionFilterBuilder;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
 
 public class PublisherTest extends AbstractTest {
+
+    private static NetworkTransactionService networkTransactionService;
+
+    @Mock
+    RpcProviderService rpcProviderRegistry;
+    @Mock
+    private NotificationService notificationService;
+
     private JsonStringConverter<NotificationProcessService> converterService;
     private JsonStringConverter<NotificationAlarmService> converterAlarm;
     private JsonStringConverter<NotificationTapiService> converterTapiService;
@@ -53,13 +65,12 @@ public class PublisherTest extends AbstractTest {
     private MockProducer<String, NotificationProcessService> mockProducer;
     private MockProducer<String, NotificationAlarmService> mockAlarmProducer;
     private MockProducer<String, NotificationTapiService> mockTapiProducer;
-    private NbiNotificationsImpl nbiNotificationsImpl;
+    private NbiNotificationsProvider nbiNotifications;
     private TopicManager topicManager;
 
-    public static NetworkTransactionService networkTransactionService;
 
-    @Before
-    public void setUp() throws ExecutionException, InterruptedException {
+    @BeforeEach
+    void setUp() throws ExecutionException, InterruptedException {
         topicManager = TopicManager.getInstance();
         converterService = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
         converterAlarm = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
@@ -80,52 +91,53 @@ public class PublisherTest extends AbstractTest {
         publisherAlarm = new Publisher<>("test", mockAlarmProducer);
         publisherTapiService = new Publisher<>("test", mockTapiProducer);
         MockitoAnnotations.openMocks(this);
-        networkTransactionService = new NetworkTransactionImpl(
-            new RequestProcessor(getDataStoreContextUtil().getDataBroker()));
+        networkTransactionService = new NetworkTransactionImpl(getDataBroker());
         topicManager.setTapiConverter(converterTapiService);
         NotificationServiceDataUtils.createTapiContext(networkTransactionService);
-        nbiNotificationsImpl = new NbiNotificationsImpl(converterService, converterAlarm, converterTapiService,
-            "localhost:8080", networkTransactionService, topicManager);
+        nbiNotifications = new NbiNotificationsProvider("localhost:8080", "localhost:8080",
+                rpcProviderRegistry, notificationService, getDataStoreContextUtil().getBindingDOMCodecServices(),
+                networkTransactionService);
     }
 
     @Test
-    public void sendEventServiceShouldBeSuccessful() throws IOException {
+    void sendEventServiceShouldBeSuccessful() throws IOException {
         String json = Files.readString(Paths.get("src/test/resources/event.json"));
         NotificationProcessService notificationProcessService = converterService
                 .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationProcessService.QNAME),
                         json, JSONCodecFactorySupplier.RFC7951);
         publisherService.sendEvent(notificationProcessService, notificationProcessService.getConnectionType().name());
-        assertEquals("We should have one message", 1, mockProducer.history().size());
-        assertEquals("Key should be test", "test", mockProducer.history().get(0).key());
+        assertEquals(1, mockProducer.history().size(), "We should have one message");
+        assertEquals("test", mockProducer.history().get(0).key(), "Key should be test");
     }
 
     @Test
-    public void sendEventAlarmShouldBeSuccessful() throws IOException {
+    void sendEventAlarmShouldBeSuccessful() throws IOException {
         String json = Files.readString(Paths.get("src/test/resources/event_alarm_service.json"));
         NotificationAlarmService notificationAlarmService = converterAlarm
                 .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationAlarmService.QNAME),
                         json, JSONCodecFactorySupplier.RFC7951);
         publisherAlarm.sendEvent(notificationAlarmService, "alarm"
                 + notificationAlarmService.getConnectionType().getName());
-        assertEquals("We should have one message", 1, mockAlarmProducer.history().size());
-        assertEquals("Key should be test", "test", mockAlarmProducer.history().get(0).key());
+        assertEquals(1, mockAlarmProducer.history().size(), "We should have one message");
+        assertEquals("test", mockAlarmProducer.history().get(0).key(), "Key should be test");
     }
 
     @Test
-    public void sendTapiEventShouldBeSuccessful() throws IOException {
+    void sendTapiEventShouldBeSuccessful() throws IOException {
         CreateNotificationSubscriptionServiceInputBuilder builder
             = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
         SubscriptionFilter subscriptionFilter = new SubscriptionFilterBuilder(builder.getSubscriptionFilter())
             .setRequestedObjectIdentifier(new HashSet<>(List.of(new Uuid("76d8f07b-ead5-4132-8eb8-cf3fdef7e079"))))
             .build();
         builder.setSubscriptionFilter(subscriptionFilter);
-        nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
+
+        new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager).invoke(builder.build());
         String json = Files.readString(Paths.get("src/test/resources/tapi_event.json"));
         NotificationTapiService notificationTapiService = converterTapiService
             .createDataObjectFromJsonString(YangInstanceIdentifier.of(NotificationTapiService.QNAME),
                 json, JSONCodecFactorySupplier.RFC7951);
         publisherTapiService.sendEvent(notificationTapiService, "");
-        assertEquals("We should have one message", 1, mockTapiProducer.history().size());
-        assertEquals("Key should be test", "test", mockTapiProducer.history().get(0).key());
+        assertEquals(1, mockTapiProducer.history().size(), "We should have one message");
+        assertEquals("test", mockTapiProducer.history().get(0).key(), "Key should be test");
     }
 }