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;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.concurrent.ExecutionException;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
18 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
19 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
20 import org.opendaylight.transportpce.common.network.RequestProcessor;
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.rev211210.ConnectionType;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceInputBuilder;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceOutput;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceInputBuilder;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceOutput;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.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;
38 public class NbiNotificationsImplTest extends AbstractTest {
39 private NbiNotificationsImpl nbiNotificationsImpl;
40 public static NetworkTransactionService networkTransactionService;
41 private TopicManager topicManager;
44 public void setUp() throws ExecutionException, InterruptedException {
45 topicManager = TopicManager.getInstance();
46 networkTransactionService = new NetworkTransactionImpl(
47 new RequestProcessor(getDataStoreContextUtil().getDataBroker()));
48 JsonStringConverter<NotificationProcessService> converter = new JsonStringConverter<>(
49 getDataStoreContextUtil().getBindingDOMCodecServices());
50 JsonStringConverter<NotificationAlarmService> converterAlarm = new JsonStringConverter<>(
51 getDataStoreContextUtil().getBindingDOMCodecServices());
52 JsonStringConverter<NotificationTapiService> converterTapi = new JsonStringConverter<>(
53 getDataStoreContextUtil().getBindingDOMCodecServices());
54 topicManager.setTapiConverter(converterTapi);
55 NotificationServiceDataUtils.createTapiContext(networkTransactionService);
57 nbiNotificationsImpl = new NbiNotificationsImpl(converter, converterAlarm, converterTapi,
58 "localhost:8080", networkTransactionService, topicManager);
62 public void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException {
63 ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
64 nbiNotificationsImpl.getNotificationsProcessService(
65 new GetNotificationsProcessServiceInputBuilder().build());
66 assertNull("Should be null", result.get().getResult().getNotificationsProcessService());
70 public void getNotificationsServiceTest() throws InterruptedException, ExecutionException {
71 GetNotificationsProcessServiceInputBuilder builder = new GetNotificationsProcessServiceInputBuilder()
72 .setGroupId("groupId")
73 .setIdConsumer("consumerId")
74 .setConnectionType(ConnectionType.Service);
75 ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
76 nbiNotificationsImpl.getNotificationsProcessService(builder.build());
77 assertNull("Should be null", result.get().getResult().getNotificationsProcessService());
81 public void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException {
82 GetNotificationsAlarmServiceInputBuilder builder = new GetNotificationsAlarmServiceInputBuilder()
83 .setGroupId("groupId")
84 .setIdConsumer("consumerId")
85 .setConnectionType(ConnectionType.Service);
86 ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> result =
87 nbiNotificationsImpl.getNotificationsAlarmService(builder.build());
88 assertNull("Should be null", result.get().getResult().getNotificationsAlarmService());
92 public void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException {
93 CreateNotificationSubscriptionServiceInputBuilder builder
94 = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
95 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
96 nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
97 assertNotNull("Should receive UUID for subscription service",
98 result.get().getResult().getSubscriptionService().getUuid().toString());
102 public void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException {
103 CreateNotificationSubscriptionServiceInputBuilder builder
104 = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
105 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
106 nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
107 GetNotificationListInputBuilder builder1 = new GetNotificationListInputBuilder()
108 .setTimePeriod("Time Period")
109 .setSubscriptionIdOrName(result.get().getResult().getSubscriptionService().getUuid().getValue());
110 ListenableFuture<RpcResult<GetNotificationListOutput>> result1 =
111 nbiNotificationsImpl.getNotificationList(builder1.build());
112 assertNull("Should be null", result1.get().getResult().getNotification());