X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=nbinotifications%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnbinotifications%2Fimpl%2FNbiNotificationsImplTest.java;h=91b109b73cd4a66426cbf8c77fc4e14650abcaa0;hb=d9ef75efa4ff5164c84d1d1e62ac1d4a7e21ab6a;hp=bc025c5d0f6959976a5280a5749d52eecb828742;hpb=bc7e77930f84d25f4f000918278b0dbf9e5b52f9;p=transportpce.git diff --git a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java index bc025c5d0..91b109b73 100644 --- a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java +++ b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java @@ -7,108 +7,124 @@ */ package org.opendaylight.transportpce.nbinotifications.impl; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import com.google.common.util.concurrent.ListenableFuture; import java.util.concurrent.ExecutionException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +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.rpc.CreateNotificationSubscriptionServiceImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationListImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsAlarmServiceImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsProcessServiceImpl; 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.http.org.openroadm.common.service.types.rev211210.ConnectionType; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceInputBuilder; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceOutput; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceInputBuilder; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceOutput; -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.notification.rev181210.CreateNotificationSubscriptionServiceInputBuilder; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutput; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListInputBuilder; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListOutput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceInputBuilder; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceOutput; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceInputBuilder; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutput; +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.notification.rev221121.CreateNotificationSubscriptionServiceOutput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListOutput; import org.opendaylight.yangtools.yang.common.RpcResult; +@ExtendWith(MockitoExtension.class) public class NbiNotificationsImplTest extends AbstractTest { - private NbiNotificationsImpl nbiNotificationsImpl; + + @Mock + RpcProviderService rpcProviderRegistry; + @Mock + private NotificationService notificationService; + + private NbiNotificationsProvider nbiNotifications; public static NetworkTransactionService networkTransactionService; private TopicManager topicManager; + private JsonStringConverter converterProcess; + private JsonStringConverter converterAlarm; + private JsonStringConverter converterTapi; - @Before - public void setUp() throws ExecutionException, InterruptedException { + @BeforeEach + void setUp() throws ExecutionException, InterruptedException { topicManager = TopicManager.getInstance(); - networkTransactionService = new NetworkTransactionImpl( - new RequestProcessor(getDataStoreContextUtil().getDataBroker())); - JsonStringConverter converter = new JsonStringConverter<>( - getDataStoreContextUtil().getBindingDOMCodecServices()); - JsonStringConverter converterAlarm = new JsonStringConverter<>( - getDataStoreContextUtil().getBindingDOMCodecServices()); - JsonStringConverter converterTapi = new JsonStringConverter<>( - getDataStoreContextUtil().getBindingDOMCodecServices()); + networkTransactionService = new NetworkTransactionImpl(getDataBroker()); + converterProcess = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); + converterAlarm = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); + converterTapi = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices()); topicManager.setTapiConverter(converterTapi); NotificationServiceDataUtils.createTapiContext(networkTransactionService); - nbiNotificationsImpl = new NbiNotificationsImpl(converter, converterAlarm, converterTapi, - "localhost:8080", networkTransactionService, topicManager); + nbiNotifications = new NbiNotificationsProvider("localhost:8080", "localhost:8080", + rpcProviderRegistry, notificationService, getDataStoreContextUtil().getBindingDOMCodecServices(), + networkTransactionService); } @Test - public void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException { + void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - nbiNotificationsImpl.getNotificationsProcessService( + new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080").invoke( new GetNotificationsProcessServiceInputBuilder().build()); - assertNull("Should be null", result.get().getResult().getNotificationsProcessService()); + assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null"); } @Test - public void getNotificationsServiceTest() throws InterruptedException, ExecutionException { - GetNotificationsProcessServiceInputBuilder builder = new GetNotificationsProcessServiceInputBuilder() - .setGroupId("groupId") - .setIdConsumer("consumerId") - .setConnectionType(ConnectionType.Service); + void getNotificationsServiceTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - nbiNotificationsImpl.getNotificationsProcessService(builder.build()); - assertNull("Should be null", result.get().getResult().getNotificationsProcessService()); + new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080") + .invoke(new GetNotificationsProcessServiceInputBuilder() + .setGroupId("groupId") + .setIdConsumer("consumerId") + .setConnectionType(ConnectionType.Service) + .build()); + assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null"); } @Test - public void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException { - GetNotificationsAlarmServiceInputBuilder builder = new GetNotificationsAlarmServiceInputBuilder() - .setGroupId("groupId") - .setIdConsumer("consumerId") - .setConnectionType(ConnectionType.Service); + void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - nbiNotificationsImpl.getNotificationsAlarmService(builder.build()); - assertNull("Should be null", result.get().getResult().getNotificationsAlarmService()); + new GetNotificationsAlarmServiceImpl(converterAlarm, "localhost:8080") + .invoke(new GetNotificationsAlarmServiceInputBuilder() + .setGroupId("groupId") + .setIdConsumer("consumerId") + .setConnectionType(ConnectionType.Service) + .build()); + assertNull(result.get().getResult().getNotificationsAlarmService(), "Should be null"); } @Test - public void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException { - CreateNotificationSubscriptionServiceInputBuilder builder - = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder(); + void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - nbiNotificationsImpl.createNotificationSubscriptionService(builder.build()); - assertNotNull("Should receive UUID for subscription service", - result.get().getResult().getSubscriptionService().getUuid().toString()); + new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager) + .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build()); + assertNotNull(result.get().getResult().getSubscriptionService().getUuid().toString(), + "Should receive UUID for subscription service"); } @Test - public void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException { - CreateNotificationSubscriptionServiceInputBuilder builder - = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder(); + void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - nbiNotificationsImpl.createNotificationSubscriptionService(builder.build()); - GetNotificationListInputBuilder builder1 = new GetNotificationListInputBuilder() - .setTimePeriod("Time Period") - .setSubscriptionIdOrName(result.get().getResult().getSubscriptionService().getUuid().getValue()); - ListenableFuture> result1 = - nbiNotificationsImpl.getNotificationList(builder1.build()); - assertNull("Should be null", result1.get().getResult().getNotification()); + new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager) + .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build()); + ListenableFuture> result2 = + new GetNotificationListImpl(converterTapi, "localhost:8080", networkTransactionService, topicManager) + .invoke(new GetNotificationListInputBuilder() + .setTimeRange(null) + .setSubscriptionId(result.get().getResult().getSubscriptionService().getUuid()) + .build()); + assertNull(result2.get().getResult().getNotification(), "Should be null"); } }