2 * Copyright © 2020 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.nbinotifications.impl;
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertNull;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.concurrent.ExecutionException;
16 import org.junit.jupiter.api.BeforeEach;
17 import org.junit.jupiter.api.Test;
18 import org.junit.jupiter.api.extension.ExtendWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.jupiter.MockitoExtension;
21 import org.opendaylight.mdsal.binding.api.NotificationService;
22 import org.opendaylight.mdsal.binding.api.RpcProviderService;
23 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
24 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
25 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
26 import org.opendaylight.transportpce.nbinotifications.impl.rpc.CreateNotificationSubscriptionServiceImpl;
27 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationListImpl;
28 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsAlarmServiceImpl;
29 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsProcessServiceImpl;
30 import org.opendaylight.transportpce.nbinotifications.utils.NotificationServiceDataUtils;
31 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
32 import org.opendaylight.transportpce.test.AbstractTest;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceInputBuilder;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceOutput;
36 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceInputBuilder;
37 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutput;
38 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
39 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
40 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.CreateNotificationSubscriptionServiceOutput;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListInputBuilder;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListOutput;
44 import org.opendaylight.yangtools.yang.common.RpcResult;
46 @ExtendWith(MockitoExtension.class)
47 public class NbiNotificationsImplTest extends AbstractTest {
50 RpcProviderService rpcProviderRegistry;
52 private NotificationService notificationService;
54 private NbiNotificationsProvider nbiNotifications;
55 public static NetworkTransactionService networkTransactionService;
56 private TopicManager topicManager;
57 private JsonStringConverter<NotificationProcessService> converterProcess;
58 private JsonStringConverter<NotificationAlarmService> converterAlarm;
59 private JsonStringConverter<NotificationTapiService> converterTapi;
62 void setUp() throws ExecutionException, InterruptedException {
63 topicManager = TopicManager.getInstance();
64 networkTransactionService = new NetworkTransactionImpl(getDataBroker());
65 converterProcess = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
66 converterAlarm = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
67 converterTapi = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
68 topicManager.setTapiConverter(converterTapi);
69 NotificationServiceDataUtils.createTapiContext(networkTransactionService);
71 nbiNotifications = new NbiNotificationsProvider("localhost:8080", "localhost:8080",
72 rpcProviderRegistry, notificationService, getDataStoreContextUtil().getBindingDOMCodecServices(),
73 networkTransactionService);
77 void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException {
78 ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
79 new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080").invoke(
80 new GetNotificationsProcessServiceInputBuilder().build());
81 assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
85 void getNotificationsServiceTest() throws InterruptedException, ExecutionException {
86 ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
87 new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080")
88 .invoke(new GetNotificationsProcessServiceInputBuilder()
89 .setGroupId("groupId")
90 .setIdConsumer("consumerId")
91 .setConnectionType(ConnectionType.Service)
93 assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
97 void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException {
98 ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> result =
99 new GetNotificationsAlarmServiceImpl(converterAlarm, "localhost:8080")
100 .invoke(new GetNotificationsAlarmServiceInputBuilder()
101 .setGroupId("groupId")
102 .setIdConsumer("consumerId")
103 .setConnectionType(ConnectionType.Service)
105 assertNull(result.get().getResult().getNotificationsAlarmService(), "Should be null");
109 void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException {
110 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
111 new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager)
112 .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build());
113 assertNotNull(result.get().getResult().getSubscriptionService().getUuid().toString(),
114 "Should receive UUID for subscription service");
118 void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException {
119 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
120 new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager)
121 .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build());
122 ListenableFuture<RpcResult<GetNotificationListOutput>> result2 =
123 new GetNotificationListImpl(converterTapi, "localhost:8080", networkTransactionService, topicManager)
124 .invoke(new GetNotificationListInputBuilder()
126 .setSubscriptionId(result.get().getResult().getSubscriptionService().getUuid())
128 assertNull(result2.get().getResult().getNotification(), "Should be null");