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.dataprovider.model.DataProvider;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14EthernetContainerNotificationListener;
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.devicemanager.service.NotificationService;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
31 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
34 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.AttributeValueChangedNotification;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ObjectCreationNotification;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ObjectDeletionNotification;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ProblemNotification;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPE;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPECRITICAL;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPEMAJOR;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPEMINOR;
42 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPENONALARMED;
43 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPEWARNING;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
46 public class TestOnf14EthernetContainerNotificationListener extends Mockito {
47 private NetconfBindingAccessor accessor;
48 private NodeId nodeId;
49 private DeviceManagerServiceProvider serviceProvider;
50 private FaultService faultService;
51 private DataProvider databaseService;
52 private NotificationService notificationService;
54 private ObjectDeletionNotification deletionNotif;
55 private ObjectCreationNotification creationNotif;
56 private ProblemNotification problemNotif;
57 private AttributeValueChangedNotification attrValChangedNotif;
58 private WebsocketManagerService websocketService;
62 accessor = mock(NetconfBindingAccessor.class);
63 nodeId = mock(NodeId.class);
64 serviceProvider = mock(DeviceManagerServiceProvider.class);
65 faultService = mock(FaultService.class);
66 databaseService = mock(DataProvider.class);
67 notificationService = mock(NotificationService.class);
68 websocketService = mock(WebsocketManagerService.class);
70 problemNotif = mock(ProblemNotification.class);
71 deletionNotif = mock(ObjectDeletionNotification.class);
72 creationNotif = mock(ObjectCreationNotification.class);
73 attrValChangedNotif = mock(AttributeValueChangedNotification.class);
75 when(accessor.getNodeId()).thenReturn(nodeId);
76 when(problemNotif.getCounter()).thenReturn(10L);
77 when(problemNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
78 when(problemNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
79 when(problemNotif.getProblem()).thenReturn("modulationIsDownShifted");
81 when(attrValChangedNotif.getAttributeName()).thenReturn("12345678-0123-2345-abcd-0123456789AB");
82 when(attrValChangedNotif.getCounter()).thenReturn(20L);
83 when(attrValChangedNotif.getNewValue()).thenReturn("new-value");
84 when(attrValChangedNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
85 when(attrValChangedNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
87 when(creationNotif.getObjectType()).thenReturn("air-interface-name");
88 when(creationNotif.getCounter()).thenReturn(20L);
89 when(creationNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
90 when(creationNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
92 when(deletionNotif.getCounter()).thenReturn(20L);
93 when(deletionNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
94 when(deletionNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
96 when(serviceProvider.getFaultService()).thenReturn(faultService);
97 when(serviceProvider.getDataProvider()).thenReturn(databaseService);
98 when(serviceProvider.getNotificationService()).thenReturn(notificationService);
99 when(serviceProvider.getWebsocketService()).thenReturn(websocketService);
103 public void testOtherNotif() {
104 Onf14EthernetContainerNotificationListener notifListener =
105 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
107 notifListener.onObjectDeletionNotification(deletionNotif);
108 notifListener.onObjectCreationNotification(creationNotif);
109 notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
113 public void testProblemNotifCritical() {
114 Onf14EthernetContainerNotificationListener notifListener =
115 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
117 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
119 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
120 return SEVERITYTYPECRITICAL.class;
124 notifListener.onProblemNotification(problemNotif);
128 public void testProblemNotifMajor() {
129 Onf14EthernetContainerNotificationListener notifListener =
130 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
132 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
134 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
135 return SEVERITYTYPEMAJOR.class;
139 notifListener.onProblemNotification(problemNotif);
143 public void testProblemNotifMinor() {
144 Onf14EthernetContainerNotificationListener notifListener =
145 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
147 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
149 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
150 return SEVERITYTYPEMINOR.class;
154 notifListener.onProblemNotification(problemNotif);
158 public void testProblemNotifWarning() {
159 Onf14EthernetContainerNotificationListener notifListener =
160 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
162 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
164 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
165 return SEVERITYTYPEWARNING.class;
169 notifListener.onProblemNotification(problemNotif);
173 public void testProblemNotifNonalarmed() {
174 Onf14EthernetContainerNotificationListener notifListener =
175 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
177 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
179 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
180 return SEVERITYTYPENONALARMED.class;
184 notifListener.onProblemNotification(problemNotif);
188 public void testProblemNotifNull() {
189 Onf14EthernetContainerNotificationListener notifListener =
190 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
192 when(problemNotif.getSeverity()).thenReturn(null);
194 notifListener.onProblemNotification(problemNotif);