ff0ddb43c812fb0462c9822c78fd8ca6ed9dc427
[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.openroadm.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.NetconfAccessor;
35 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.AlarmNotification;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCause;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.ProbableCauseBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.alarm.Resource;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.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.rev191129.ProbableCauseEnum;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.Device;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.rev191129.resource.DeviceBuilder;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
47
48 public class TestOpenRoadmAlarmNotification {
49     private static final String myCircuitId = "Test_Id";
50     private static final String myId = "Alarm_Id";
51     DateAndTime myRaiseTime = new DateAndTime("2020-02-25T10:08:06.7Z");
52     ProbableCause myProbableCause =
53             new ProbableCauseBuilder().setCause(ProbableCauseEnum.AutomaticLaserShutdown).build();
54     Device device = new DeviceBuilder().setNodeId(NodeIdType.getDefaultInstance("zNhe2i5")).build();
55     Resource myResource = new ResourceBuilder().setDevice(device).build();
56     static DeviceManagerServiceProvider serviceProvider;
57     static @NonNull FaultService faultService;
58     static AlarmNotification notification;
59     Severity severity;
60     static NetconfAccessor accessor;
61     static WebsocketManagerService notificationService;
62
63     @BeforeClass
64     public static void init() throws InterruptedException, IOException {
65
66         accessor = mock(NetconfAccessor.class);
67         serviceProvider = mock(DeviceManagerServiceProvider.class);
68         faultService = mock(FaultService.class);
69         notificationService = mock(WebsocketManagerService.class);
70     }
71
72
73
74     @Test
75     public void testNotification() {
76         severity = Severity.Critical;
77         when(serviceProvider.getFaultService()).thenReturn(faultService);
78         when(serviceProvider.getWebsocketService()).thenReturn(notificationService);
79         OpenroadmFaultNotificationListener alarmListener =
80                 new OpenroadmFaultNotificationListener(serviceProvider);
81         notification = mock(AlarmNotification.class);
82
83         when(notification.getId()).thenReturn(myId);
84         when(notification.getCircuitId()).thenReturn(myCircuitId);
85         when(notification.getRaiseTime()).thenReturn(myRaiseTime);
86         when(notification.getProbableCause()).thenReturn(myProbableCause);
87         when(notification.getResource()).thenReturn(myResource);
88         when(notification.getSeverity()).thenReturn(severity);
89         alarmListener.onAlarmNotification(notification);
90         System.out.println(notification.getId());
91         assertEquals(myId, notification.getId());
92         assertEquals(myCircuitId, notification.getCircuitId());
93         assertEquals(myRaiseTime, notification.getRaiseTime());
94         assertEquals(myProbableCause, notification.getProbableCause());
95         assertEquals(myResource, notification.getResource());
96         assertEquals(severity, notification.getSeverity());
97
98
99     }
100
101 }