0cfd5ae0168f496b7fc3eaf963a27b796cc6ecb7
[ccsdk/features.git] /
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.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mockito;
23 import org.mockito.invocation.InvocationOnMock;
24 import org.mockito.stubbing.Answer;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.Onf14AirInterfaceNotificationListener;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.test.mock.NetconfAccessorMock;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
31 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.AttributeValueChangedNotification;
32 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectCreationNotification;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ObjectDeletionNotification;
34 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.ProblemNotification;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPE;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPECRITICAL;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEMAJOR;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEMINOR;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPENONALARMED;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.air._interface._2._0.rev200121.SEVERITYTYPEWARNING;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
43
44 public class TestOnf14AirInterfaceNotificationListener extends Mockito {
45     private NetconfAccessor accessor;
46     private NodeId nodeId;
47     private DeviceManagerServiceProvider serviceProvider;
48     private FaultService faultService;
49
50     private ObjectDeletionNotification deletionNotif;
51     private ObjectCreationNotification creationNotif;
52     private ProblemNotification problemNotif;
53     private AttributeValueChangedNotification attrValChangedNotif;
54
55     @Before
56     public void init() {
57         accessor = mock(NetconfAccessorMock.class);
58         nodeId = mock(NodeId.class);
59         serviceProvider = mock(DeviceManagerServiceProvider.class);
60         faultService = mock(FaultService.class);
61
62         problemNotif = mock(ProblemNotification.class);
63         deletionNotif = mock(ObjectDeletionNotification.class);
64         creationNotif = mock(ObjectCreationNotification.class);
65         attrValChangedNotif = mock(AttributeValueChangedNotification.class);
66
67         when(accessor.getNodeId()).thenReturn(nodeId);
68         when(problemNotif.getCounter()).thenReturn(10);
69         when(problemNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
70         when(problemNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
71         when(problemNotif.getProblem()).thenReturn("modulationIsDownShifted");
72
73         when(serviceProvider.getFaultService()).thenReturn(faultService);
74     }
75
76     @Test
77     public void testOtherNotif() {
78         Onf14AirInterfaceNotificationListener notifListener =
79                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
80
81         notifListener.onObjectDeletionNotification(deletionNotif);
82         notifListener.onObjectCreationNotification(creationNotif);
83         notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
84     }
85
86     @Test
87     public void testProblemNotifCritical() {
88         Onf14AirInterfaceNotificationListener notifListener =
89                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
90
91         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
92             @Override
93             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
94                 return SEVERITYTYPECRITICAL.class;
95             }
96         });
97
98         notifListener.onProblemNotification(problemNotif);
99     }
100
101     @Test
102     public void testProblemNotifMajor() {
103         Onf14AirInterfaceNotificationListener notifListener =
104                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
105
106         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
107             @Override
108             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
109                 return SEVERITYTYPEMAJOR.class;
110             }
111         });
112
113         notifListener.onProblemNotification(problemNotif);
114     }
115
116     @Test
117     public void testProblemNotifMinor() {
118         Onf14AirInterfaceNotificationListener notifListener =
119                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
120
121         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
122             @Override
123             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
124                 return SEVERITYTYPEMINOR.class;
125             }
126         });
127
128         notifListener.onProblemNotification(problemNotif);
129     }
130
131     @Test
132     public void testProblemNotifWarning() {
133         Onf14AirInterfaceNotificationListener notifListener =
134                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
135
136         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
137             @Override
138             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
139                 return SEVERITYTYPEWARNING.class;
140             }
141         });
142
143         notifListener.onProblemNotification(problemNotif);
144     }
145
146     @Test
147     public void testProblemNotifNonalarmed() {
148         Onf14AirInterfaceNotificationListener notifListener =
149                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
150
151         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
152             @Override
153             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
154                 return SEVERITYTYPENONALARMED.class;
155             }
156         });
157
158         notifListener.onProblemNotification(problemNotif);
159     }
160
161     @Test
162     public void testProblemNotifNull() {
163         Onf14AirInterfaceNotificationListener notifListener =
164                 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
165
166         when(problemNotif.getSeverity()).thenReturn(null);
167
168         notifListener.onProblemNotification(problemNotif);
169     }
170
171 }