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.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.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListOutput;
36 import org.opendaylight.yangtools.yang.common.RpcResult;
38 public class NbiNotificationsImplTest extends AbstractTest {
39 private NbiNotificationsImpl nbiNotificationsImpl;
40 public static NetworkTransactionService networkTransactionService;
41 private TopicManager topicManager;
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);
56 nbiNotificationsImpl = new NbiNotificationsImpl(converter, converterAlarm, converterTapi,
57 "localhost:8080", networkTransactionService, topicManager);
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");
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");
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");
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");
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()
108 .setSubscriptionId(result.get().getResult().getSubscriptionService().getUuid());
109 ListenableFuture<RpcResult<GetNotificationListOutput>> result1 =
110 nbiNotificationsImpl.getNotificationList(builder1.build());
111 assertNull(result1.get().getResult().getNotification(), "Should be null");