674c9d0dee59b706c8441614c16b131ec5a5b908
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27 import java.io.IOException;
28 import org.eclipse.jdt.annotation.NonNull;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm71.impl.OpenroadmFaultNotificationListener;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
35 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.AlarmNotification;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.Severity;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ProbableCause;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ProbableCauseBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.Resource;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev200529.alarm.ResourceBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev191129.NodeIdType;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.probablecause.rev200529.ProbableCauseEnum;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.Device;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.DeviceBuilder;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
48
49 public class TestOpenRoadmAlarmNotification {
50     private static final String myCircuitId = "Test_Id";
51     private static final String myId = "Alarm_Id";
52     DateAndTime myRaiseTime = new DateAndTime("2020-02-25T10:08:06.7Z");
53     ProbableCause myProbableCause =
54             new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build();
55     Device device = new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build();
56     org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.CircuitPack resVal =
57             new org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.resource.resource.CircuitPackBuilder()
58             .setCircuitPackName("Slot-0-Port-A").build();
59     org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.Resource affectedResource =
60             new org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev200529.resource.ResourceBuilder().setResource(resVal).build();
61     Resource myResource = new ResourceBuilder().setResource(affectedResource).setDevice(device).build();
62
63
64     static DeviceManagerServiceProvider serviceProvider;
65     static @NonNull FaultService faultService;
66     static AlarmNotification notification;
67     Severity severity;
68     static NetconfBindingAccessor accessor;
69     static WebsocketManagerService notificationService;
70     static NodeId nNodeId = new NodeId("nSky");
71     @BeforeClass
72     public static void init() throws InterruptedException, IOException {
73
74         accessor = mock(NetconfBindingAccessor.class);
75         serviceProvider = mock(DeviceManagerServiceProvider.class);
76         faultService = mock(FaultService.class);
77         notificationService = mock(WebsocketManagerService.class);
78     }
79
80
81
82     @Test
83     public void testNotification() {
84         severity = Severity.Critical;
85         when(accessor.getNodeId()).thenReturn(nNodeId);
86         when(serviceProvider.getFaultService()).thenReturn(faultService);
87         when(serviceProvider.getWebsocketService()).thenReturn(notificationService);
88         OpenroadmFaultNotificationListener alarmListener =
89                 new OpenroadmFaultNotificationListener(accessor, serviceProvider);
90         notification = mock(AlarmNotification.class);
91
92         when(notification.getId()).thenReturn(myId);
93         when(notification.getCircuitId()).thenReturn(myCircuitId);
94         when(notification.getRaiseTime()).thenReturn(myRaiseTime);
95         when(notification.getProbableCause()).thenReturn(myProbableCause);
96         when(notification.getResource()).thenReturn(myResource);
97         when(notification.getSeverity()).thenReturn(severity);
98         alarmListener.onAlarmNotification(notification);
99         System.out.println(notification.getId());
100         assertEquals(myId, notification.getId());
101         assertEquals(myCircuitId, notification.getCircuitId());
102         assertEquals(myRaiseTime, notification.getRaiseTime());
103         assertEquals(myProbableCause, notification.getProbableCause());
104         assertEquals(myResource, notification.getResource());
105         assertEquals(severity, notification.getSeverity());
106
107
108     }
109
110 }