Merge "Optimize cm-handle registration with CPS-DMI Plugin to upload yang model"
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / onf14 / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / TestOnf14AirInterfaceNotificationListener.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
19
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.Mockito;
24 import org.mockito.invocation.InvocationOnMock;
25 import org.mockito.stubbing.Answer;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14AirInterfaceNotificationListener;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
32 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
34 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.AttributeValueChangedNotification;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectCreationNotification;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectDeletionNotification;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ProblemNotification;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPE;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPECRITICAL;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEMAJOR;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEMINOR;
42 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPENONALARMED;
43 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEWARNING;
44 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
46
47 public class TestOnf14AirInterfaceNotificationListener extends Mockito {
48     private NetconfBindingAccessor accessor;
49     private NodeId nodeId;
50     private DeviceManagerServiceProvider serviceProvider;
51     private FaultService faultService;
52     private DataProvider databaseService;
53     private NotificationService notificationService;
54
55     private ObjectDeletionNotification deletionNotif;
56     private ObjectCreationNotification creationNotif;
57     private ProblemNotification problemNotif;
58     private AttributeValueChangedNotification attrValChangedNotif;
59     private @NonNull WebsocketManagerService websocketService;
60
61     @Before
62     public void init() {
63         accessor = mock(NetconfBindingAccessor.class);
64         nodeId = mock(NodeId.class);
65         serviceProvider = mock(DeviceManagerServiceProvider.class);
66         faultService = mock(FaultService.class);
67         databaseService = mock(DataProvider.class);
68         notificationService = mock(NotificationService.class);
69         websocketService = mock(WebsocketManagerService.class);
70
71         problemNotif = mock(ProblemNotification.class);
72         deletionNotif = mock(ObjectDeletionNotification.class);
73         creationNotif = mock(ObjectCreationNotification.class);
74         attrValChangedNotif = mock(AttributeValueChangedNotification.class);
75
76         when(accessor.getNodeId()).thenReturn(nodeId);
77         when(problemNotif.getCounter()).thenReturn(10);
78         when(problemNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
79         when(problemNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
80         when(problemNotif.getProblem()).thenReturn("modulationIsDownShifted");
81
82         when(attrValChangedNotif.getAttributeName()).thenReturn("12345678-0123-2345-abcd-0123456789AB");
83         when(attrValChangedNotif.getCounter()).thenReturn(20);
84         when(attrValChangedNotif.getNewValue()).thenReturn("new-value");
85         when(attrValChangedNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
86         when(attrValChangedNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
87
88         when(creationNotif.getObjectType()).thenReturn("air-interface-name");
89         when(creationNotif.getCounter()).thenReturn(20);
90         when(creationNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
91         when(creationNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
92
93         when(deletionNotif.getCounter()).thenReturn(20);
94         when(deletionNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
95         when(deletionNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
96
97         when(serviceProvider.getFaultService()).thenReturn(faultService);
98         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
99         when(serviceProvider.getNotificationService()).thenReturn(notificationService);
100         when(serviceProvider.getWebsocketService()).thenReturn(websocketService);
101     }
102
103     @Test
104     public void testOtherNotif() {
105         Onf14AirInterfaceNotificationListener notifListener =
106                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
107
108         notifListener.onObjectDeletionNotification(deletionNotif);
109         notifListener.onObjectCreationNotification(creationNotif);
110         notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
111     }
112
113     @Test
114     public void testProblemNotifCritical() {
115         Onf14AirInterfaceNotificationListener notifListener =
116                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
117
118         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
119             @Override
120             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
121                 return SEVERITYTYPECRITICAL.class;
122             }
123         });
124
125         notifListener.onProblemNotification(problemNotif);
126     }
127
128     @Test
129     public void testProblemNotifMajor() {
130         Onf14AirInterfaceNotificationListener notifListener =
131                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
132
133         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
134             @Override
135             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
136                 return SEVERITYTYPEMAJOR.class;
137             }
138         });
139
140         notifListener.onProblemNotification(problemNotif);
141     }
142
143     @Test
144     public void testProblemNotifMinor() {
145         Onf14AirInterfaceNotificationListener notifListener =
146                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
147
148         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
149             @Override
150             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
151                 return SEVERITYTYPEMINOR.class;
152             }
153         });
154
155         notifListener.onProblemNotification(problemNotif);
156     }
157
158     @Test
159     public void testProblemNotifWarning() {
160         Onf14AirInterfaceNotificationListener notifListener =
161                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
162
163         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
164             @Override
165             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
166                 return SEVERITYTYPEWARNING.class;
167             }
168         });
169
170         notifListener.onProblemNotification(problemNotif);
171     }
172
173     @Test
174     public void testProblemNotifNonalarmed() {
175         Onf14AirInterfaceNotificationListener notifListener =
176                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
177
178         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
179             @Override
180             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
181                 return SEVERITYTYPENONALARMED.class;
182             }
183         });
184
185         notifListener.onProblemNotification(problemNotif);
186     }
187
188     @Test
189     public void testProblemNotifNull() {
190         Onf14AirInterfaceNotificationListener notifListener =
191                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
192
193         when(problemNotif.getSeverity()).thenReturn(null);
194
195         notifListener.onProblemNotification(problemNotif);
196     }
197
198 }