Migration to TAPI 2.4 Step3
[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.rev230728.GetNotificationsAlarmServiceInputBuilder;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmServiceOutput;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceInputBuilder;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessServiceOutput;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.CreateNotificationSubscriptionServiceInputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.CreateNotificationSubscriptionServiceOutput;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListInputBuilder;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36
37 public class NbiNotificationsImplTest extends AbstractTest {
38     private NbiNotificationsImpl nbiNotificationsImpl;
39     public static NetworkTransactionService networkTransactionService;
40     private TopicManager topicManager;
41
42     @BeforeEach
43     void setUp() throws ExecutionException, InterruptedException {
44         topicManager = TopicManager.getInstance();
45         networkTransactionService = new NetworkTransactionImpl(getDataBroker());
46         JsonStringConverter<NotificationProcessService> converter = new JsonStringConverter<>(
47                 getDataStoreContextUtil().getBindingDOMCodecServices());
48         JsonStringConverter<NotificationAlarmService> converterAlarm = new JsonStringConverter<>(
49                 getDataStoreContextUtil().getBindingDOMCodecServices());
50         JsonStringConverter<NotificationTapiService> converterTapi = new JsonStringConverter<>(
51             getDataStoreContextUtil().getBindingDOMCodecServices());
52         topicManager.setTapiConverter(converterTapi);
53         NotificationServiceDataUtils.createTapiContext(networkTransactionService);
54
55         nbiNotificationsImpl = new NbiNotificationsImpl(converter, converterAlarm, converterTapi,
56             "localhost:8080", networkTransactionService, topicManager);
57     }
58
59     @Test
60     void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException {
61         ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
62                 nbiNotificationsImpl.getNotificationsProcessService(
63                         new GetNotificationsProcessServiceInputBuilder().build());
64         assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
65     }
66
67     @Test
68     void getNotificationsServiceTest() throws InterruptedException, ExecutionException {
69         GetNotificationsProcessServiceInputBuilder builder = new GetNotificationsProcessServiceInputBuilder()
70                 .setGroupId("groupId")
71                 .setIdConsumer("consumerId")
72                 .setConnectionType(ConnectionType.Service);
73         ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
74                 nbiNotificationsImpl.getNotificationsProcessService(builder.build());
75         assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
76     }
77
78     @Test
79     void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException {
80         GetNotificationsAlarmServiceInputBuilder builder = new GetNotificationsAlarmServiceInputBuilder()
81                 .setGroupId("groupId")
82                 .setIdConsumer("consumerId")
83                 .setConnectionType(ConnectionType.Service);
84         ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> result =
85                 nbiNotificationsImpl.getNotificationsAlarmService(builder.build());
86         assertNull(result.get().getResult().getNotificationsAlarmService(), "Should be null");
87     }
88
89     @Test
90     void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException {
91         CreateNotificationSubscriptionServiceInputBuilder builder
92             = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
93         ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
94             nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
95         assertNotNull(result.get().getResult().getSubscriptionService().getUuid().toString(),
96             "Should receive UUID for subscription service");
97     }
98
99     @Test
100     void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException {
101         CreateNotificationSubscriptionServiceInputBuilder builder
102             = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
103         ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
104             nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
105         assertNull(nbiNotificationsImpl.getNotificationList(new GetNotificationListInputBuilder()
106             .setTimeRange(null)
107             .setSubscriptionId(result.get().getResult().getSubscriptionService().getUuid())
108             .build())
109             .get().getResult().getNotification(), "Should be null");
110     }
111 }