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.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.Onf14WireInterfaceNotificationListener;
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.core.model._1._4.rev191127.UniversalId;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.AttributeValueChangedNotification;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ObjectCreationNotification;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ObjectDeletionNotification;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ProblemNotification;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPE;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPECRITICAL;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPEMAJOR;
42 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPEMINOR;
43 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPENONALARMED;
44 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPEWARNING;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
47 public class TestOnf14WireInterfaceNotificationListener 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;
55 private ObjectDeletionNotification deletionNotif;
56 private ObjectCreationNotification creationNotif;
57 private ProblemNotification problemNotif;
58 private AttributeValueChangedNotification attrValChangedNotif;
59 private @NonNull WebsocketManagerService websocketService;
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);
71 problemNotif = mock(ProblemNotification.class);
72 deletionNotif = mock(ObjectDeletionNotification.class);
73 creationNotif = mock(ObjectCreationNotification.class);
74 attrValChangedNotif = mock(AttributeValueChangedNotification.class);
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");
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"));
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"));
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"));
97 when(serviceProvider.getFaultService()).thenReturn(faultService);
98 when(serviceProvider.getDataProvider()).thenReturn(databaseService);
99 when(serviceProvider.getNotificationService()).thenReturn(notificationService);
100 when(serviceProvider.getWebsocketService()).thenReturn(websocketService);
104 public void testOtherNotif() {
105 Onf14WireInterfaceNotificationListener notifListener =
106 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
108 notifListener.onObjectDeletionNotification(deletionNotif);
109 notifListener.onObjectCreationNotification(creationNotif);
110 notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
114 public void testProblemNotifCritical() {
115 Onf14WireInterfaceNotificationListener notifListener =
116 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
118 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
120 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
121 return SEVERITYTYPECRITICAL.class;
125 notifListener.onProblemNotification(problemNotif);
129 public void testProblemNotifMajor() {
130 Onf14WireInterfaceNotificationListener notifListener =
131 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
133 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
135 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
136 return SEVERITYTYPEMAJOR.class;
140 notifListener.onProblemNotification(problemNotif);
144 public void testProblemNotifMinor() {
145 Onf14WireInterfaceNotificationListener notifListener =
146 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
148 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
150 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
151 return SEVERITYTYPEMINOR.class;
155 notifListener.onProblemNotification(problemNotif);
159 public void testProblemNotifWarning() {
160 Onf14WireInterfaceNotificationListener notifListener =
161 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
163 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
165 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
166 return SEVERITYTYPEWARNING.class;
170 notifListener.onProblemNotification(problemNotif);
174 public void testProblemNotifNonalarmed() {
175 Onf14WireInterfaceNotificationListener notifListener =
176 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
178 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
180 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
181 return SEVERITYTYPENONALARMED.class;
185 notifListener.onProblemNotification(problemNotif);
189 public void testProblemNotifNull() {
190 Onf14WireInterfaceNotificationListener notifListener =
191 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
193 when(problemNotif.getSeverity()).thenReturn(null);
195 notifListener.onProblemNotification(problemNotif);