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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
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;
44 public class TestOnf14AirInterfaceNotificationListener extends Mockito {
45 private NetconfAccessor accessor;
46 private NodeId nodeId;
47 private DeviceManagerServiceProvider serviceProvider;
48 private FaultService faultService;
50 private ObjectDeletionNotification deletionNotif;
51 private ObjectCreationNotification creationNotif;
52 private ProblemNotification problemNotif;
53 private AttributeValueChangedNotification attrValChangedNotif;
57 accessor = mock(NetconfAccessorMock.class);
58 nodeId = mock(NodeId.class);
59 serviceProvider = mock(DeviceManagerServiceProvider.class);
60 faultService = mock(FaultService.class);
62 problemNotif = mock(ProblemNotification.class);
63 deletionNotif = mock(ObjectDeletionNotification.class);
64 creationNotif = mock(ObjectCreationNotification.class);
65 attrValChangedNotif = mock(AttributeValueChangedNotification.class);
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");
73 when(serviceProvider.getFaultService()).thenReturn(faultService);
77 public void testOtherNotif() {
78 Onf14AirInterfaceNotificationListener notifListener =
79 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
81 notifListener.onObjectDeletionNotification(deletionNotif);
82 notifListener.onObjectCreationNotification(creationNotif);
83 notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
87 public void testProblemNotifCritical() {
88 Onf14AirInterfaceNotificationListener notifListener =
89 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
91 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
93 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
94 return SEVERITYTYPECRITICAL.class;
98 notifListener.onProblemNotification(problemNotif);
102 public void testProblemNotifMajor() {
103 Onf14AirInterfaceNotificationListener notifListener =
104 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
106 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
108 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
109 return SEVERITYTYPEMAJOR.class;
113 notifListener.onProblemNotification(problemNotif);
117 public void testProblemNotifMinor() {
118 Onf14AirInterfaceNotificationListener notifListener =
119 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
121 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
123 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
124 return SEVERITYTYPEMINOR.class;
128 notifListener.onProblemNotification(problemNotif);
132 public void testProblemNotifWarning() {
133 Onf14AirInterfaceNotificationListener notifListener =
134 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
136 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
138 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
139 return SEVERITYTYPEWARNING.class;
143 notifListener.onProblemNotification(problemNotif);
147 public void testProblemNotifNonalarmed() {
148 Onf14AirInterfaceNotificationListener notifListener =
149 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
151 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
153 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
154 return SEVERITYTYPENONALARMED.class;
158 notifListener.onProblemNotification(problemNotif);
162 public void testProblemNotifNull() {
163 Onf14AirInterfaceNotificationListener notifListener =
164 new Onf14AirInterfaceNotificationListener(accessor, serviceProvider);
166 when(problemNotif.getSeverity()).thenReturn(null);
168 notifListener.onProblemNotification(problemNotif);