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.opendaylight.transportpce.common.converter.JsonStringConverter;
19 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
20 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
21 import org.opendaylight.transportpce.nbinotifications.impl.rpc.CreateNotificationSubscriptionServiceImpl;
22 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationListImpl;
23 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsAlarmServiceImpl;
24 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsProcessServiceImpl;
25 import org.opendaylight.transportpce.nbinotifications.utils.NotificationServiceDataUtils;
26 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceInputBuilder;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceOutput;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceInputBuilder;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutput;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.CreateNotificationSubscriptionServiceOutput;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListInputBuilder;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListOutput;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
41 public class NbiNotificationsImplTest extends AbstractTest {
42 private NbiNotificationsImpl nbiNotificationsImpl;
43 public static NetworkTransactionService networkTransactionService;
44 private TopicManager topicManager;
45 private JsonStringConverter<NotificationProcessService> converterProcess;
46 private JsonStringConverter<NotificationAlarmService> converterAlarm;
47 private JsonStringConverter<NotificationTapiService> converterTapi;
50 void setUp() throws ExecutionException, InterruptedException {
51 topicManager = TopicManager.getInstance();
52 networkTransactionService = new NetworkTransactionImpl(getDataBroker());
53 converterProcess = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
54 converterAlarm = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
55 converterTapi = new JsonStringConverter<>(getDataStoreContextUtil().getBindingDOMCodecServices());
56 topicManager.setTapiConverter(converterTapi);
57 NotificationServiceDataUtils.createTapiContext(networkTransactionService);
59 nbiNotificationsImpl = new NbiNotificationsImpl(converterProcess, converterAlarm, converterTapi,
60 "localhost:8080", networkTransactionService, topicManager);
64 void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException {
65 ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
66 new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080").invoke(
67 new GetNotificationsProcessServiceInputBuilder().build());
68 assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
72 void getNotificationsServiceTest() throws InterruptedException, ExecutionException {
73 ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
74 new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080")
75 .invoke(new GetNotificationsProcessServiceInputBuilder()
76 .setGroupId("groupId")
77 .setIdConsumer("consumerId")
78 .setConnectionType(ConnectionType.Service)
80 assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
84 void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException {
85 ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> result =
86 new GetNotificationsAlarmServiceImpl(converterAlarm, "localhost:8080")
87 .invoke(new GetNotificationsAlarmServiceInputBuilder()
88 .setGroupId("groupId")
89 .setIdConsumer("consumerId")
90 .setConnectionType(ConnectionType.Service)
92 assertNull(result.get().getResult().getNotificationsAlarmService(), "Should be null");
96 void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException {
97 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
98 new CreateNotificationSubscriptionServiceImpl(nbiNotificationsImpl, topicManager)
99 .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build());
100 assertNotNull(result.get().getResult().getSubscriptionService().getUuid().toString(),
101 "Should receive UUID for subscription service");
105 void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException {
106 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
107 new CreateNotificationSubscriptionServiceImpl(nbiNotificationsImpl, topicManager)
108 .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build());
109 ListenableFuture<RpcResult<GetNotificationListOutput>> result2 =
110 new GetNotificationListImpl(converterTapi, "localhost:8080", networkTransactionService, topicManager)
111 .invoke(new GetNotificationListInputBuilder()
113 .setSubscriptionId(result.get().getResult().getSubscriptionService().getUuid())
115 assertNull(result2.get().getResult().getNotification(), "Should be null");