a6d042aef0dd1dfc5c02bdfda72789db9e66e6a3
[transportpce.git] / nbinotifications / src / test / java / org / opendaylight / transportpce / nbinotifications / impl / NbiNotificationsImplTest.java
1 /*
2  * Copyright © 2020 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.nbinotifications.impl;
9
10
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12 import static org.junit.jupiter.api.Assertions.assertNull;
13
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.utils.NotificationServiceDataUtils;
22 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
23 import org.opendaylight.transportpce.test.AbstractTest;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsAlarmServiceInputBuilder;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsAlarmServiceOutput;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsProcessServiceInputBuilder;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsProcessServiceOutput;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationAlarmService;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationProcessService;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationTapiService;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceInputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutput;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListInputBuilder;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListOutput;
36 import org.opendaylight.yangtools.yang.common.RpcResult;
37
38 public class NbiNotificationsImplTest extends AbstractTest {
39     private NbiNotificationsImpl nbiNotificationsImpl;
40     public static NetworkTransactionService networkTransactionService;
41     private TopicManager topicManager;
42
43     @BeforeEach
44     void setUp() throws ExecutionException, InterruptedException {
45         topicManager = TopicManager.getInstance();
46         networkTransactionService = new NetworkTransactionImpl(getDataBroker());
47         JsonStringConverter<NotificationProcessService> converter = new JsonStringConverter<>(
48                 getDataStoreContextUtil().getBindingDOMCodecServices());
49         JsonStringConverter<NotificationAlarmService> converterAlarm = new JsonStringConverter<>(
50                 getDataStoreContextUtil().getBindingDOMCodecServices());
51         JsonStringConverter<NotificationTapiService> converterTapi = new JsonStringConverter<>(
52             getDataStoreContextUtil().getBindingDOMCodecServices());
53         topicManager.setTapiConverter(converterTapi);
54         NotificationServiceDataUtils.createTapiContext(networkTransactionService);
55
56         nbiNotificationsImpl = new NbiNotificationsImpl(converter, converterAlarm, converterTapi,
57             "localhost:8080", networkTransactionService, topicManager);
58     }
59
60     @Test
61     void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException {
62         ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
63                 nbiNotificationsImpl.getNotificationsProcessService(
64                         new GetNotificationsProcessServiceInputBuilder().build());
65         assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
66     }
67
68     @Test
69     void getNotificationsServiceTest() throws InterruptedException, ExecutionException {
70         GetNotificationsProcessServiceInputBuilder builder = new GetNotificationsProcessServiceInputBuilder()
71                 .setGroupId("groupId")
72                 .setIdConsumer("consumerId")
73                 .setConnectionType(ConnectionType.Service);
74         ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
75                 nbiNotificationsImpl.getNotificationsProcessService(builder.build());
76         assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
77     }
78
79     @Test
80     void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException {
81         GetNotificationsAlarmServiceInputBuilder builder = new GetNotificationsAlarmServiceInputBuilder()
82                 .setGroupId("groupId")
83                 .setIdConsumer("consumerId")
84                 .setConnectionType(ConnectionType.Service);
85         ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> result =
86                 nbiNotificationsImpl.getNotificationsAlarmService(builder.build());
87         assertNull(result.get().getResult().getNotificationsAlarmService(), "Should be null");
88     }
89
90     @Test
91     void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException {
92         CreateNotificationSubscriptionServiceInputBuilder builder
93             = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
94         ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
95             nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
96         assertNotNull(result.get().getResult().getSubscriptionService().getUuid().toString(),
97             "Should receive UUID for subscription service");
98     }
99
100     @Test
101     void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException {
102         CreateNotificationSubscriptionServiceInputBuilder builder
103             = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
104         ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
105             nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
106         GetNotificationListInputBuilder builder1 = new GetNotificationListInputBuilder()
107             .setTimePeriod("Time Period")
108             .setSubscriptionIdOrName(result.get().getResult().getSubscriptionService().getUuid().getValue());
109         ListenableFuture<RpcResult<GetNotificationListOutput>> result1 =
110             nbiNotificationsImpl.getNotificationList(builder1.build());
111         assertNull(result1.get().getResult().getNotification(), "Should be null");
112     }
113 }