deb7c0b2f57a737064bc8e27971c7968b6c28c6f
[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.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;
40
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;
48
49     @BeforeEach
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);
58
59         nbiNotificationsImpl = new NbiNotificationsImpl(converterProcess, converterAlarm, converterTapi,
60             "localhost:8080", networkTransactionService, topicManager);
61     }
62
63     @Test
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");
69     }
70
71     @Test
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)
79                     .build());
80         assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null");
81     }
82
83     @Test
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)
91                     .build());
92         assertNull(result.get().getResult().getNotificationsAlarmService(), "Should be null");
93     }
94
95     @Test
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");
102     }
103
104     @Test
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()
112                     .setTimeRange(null)
113                     .setSubscriptionId(result.get().getResult().getSubscriptionService().getUuid())
114                     .build());
115         assertNull(result2.get().getResult().getNotification(), "Should be null");
116     }
117 }