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.nbinotifications.utils.NotificationServiceDataUtils;
21 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
22 import org.opendaylight.transportpce.test.AbstractTest;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceInputBuilder;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceOutput;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceInputBuilder;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceOutput;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceInputBuilder;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutput;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListInputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListOutput;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
37 public class NbiNotificationsImplTest extends AbstractTest {
38 private NbiNotificationsImpl nbiNotificationsImpl;
39 public static NetworkTransactionService networkTransactionService;
40 private TopicManager topicManager;
43 public 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);
55 nbiNotificationsImpl = new NbiNotificationsImpl(converter, converterAlarm, converterTapi,
56 "localhost:8080", networkTransactionService, topicManager);
60 public void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException {
61 ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> result =
62 nbiNotificationsImpl.getNotificationsProcessService(
63 new GetNotificationsProcessServiceInputBuilder().build());
64 assertNull("Should be null", result.get().getResult().getNotificationsProcessService());
68 public 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("Should be null", result.get().getResult().getNotificationsProcessService());
79 public 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("Should be null", result.get().getResult().getNotificationsAlarmService());
90 public void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException {
91 CreateNotificationSubscriptionServiceInputBuilder builder
92 = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
93 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
94 nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
95 assertNotNull("Should receive UUID for subscription service",
96 result.get().getResult().getSubscriptionService().getUuid().toString());
100 public void getTapiNotificationsServiceTest() throws InterruptedException, ExecutionException {
101 CreateNotificationSubscriptionServiceInputBuilder builder
102 = NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder();
103 ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>> result =
104 nbiNotificationsImpl.createNotificationSubscriptionService(builder.build());
105 GetNotificationListInputBuilder builder1 = new GetNotificationListInputBuilder()
106 .setTimePeriod("Time Period")
107 .setSubscriptionIdOrName(result.get().getResult().getSubscriptionService().getUuid().getValue());
108 ListenableFuture<RpcResult<GetNotificationListOutput>> result1 =
109 nbiNotificationsImpl.getNotificationList(builder1.build());
110 assertNull("Should be null", result1.get().getResult().getNotification());