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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
32 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
33 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.AttributeValueChangedNotification;
34 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ObjectCreationNotification;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ObjectDeletionNotification;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.ProblemNotification;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPE;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPECRITICAL;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPEMAJOR;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPEMINOR;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPENONALARMED;
42 import org.opendaylight.yang.gen.v1.urn.onf.yang.ethernet.container._2._0.rev200121.SEVERITYTYPEWARNING;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
45 public class TestOnf14EthernetContainerNotificationListener extends Mockito {
46 private NetconfBindingAccessor accessor;
47 private NodeId nodeId;
48 private DeviceManagerServiceProvider serviceProvider;
49 private FaultService faultService;
50 private DataProvider databaseService;
51 private NotificationService notificationService;
53 private ObjectDeletionNotification deletionNotif;
54 private ObjectCreationNotification creationNotif;
55 private ProblemNotification problemNotif;
56 private AttributeValueChangedNotification attrValChangedNotif;
60 accessor = mock(NetconfBindingAccessor.class);
61 nodeId = mock(NodeId.class);
62 serviceProvider = mock(DeviceManagerServiceProvider.class);
63 faultService = mock(FaultService.class);
64 databaseService = mock(DataProvider.class);
65 notificationService = mock(NotificationService.class);
67 problemNotif = mock(ProblemNotification.class);
68 deletionNotif = mock(ObjectDeletionNotification.class);
69 creationNotif = mock(ObjectCreationNotification.class);
70 attrValChangedNotif = mock(AttributeValueChangedNotification.class);
72 when(accessor.getNodeId()).thenReturn(nodeId);
73 when(problemNotif.getCounter()).thenReturn(10L);
74 when(problemNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
75 when(problemNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
76 when(problemNotif.getProblem()).thenReturn("modulationIsDownShifted");
78 when(attrValChangedNotif.getAttributeName()).thenReturn("12345678-0123-2345-abcd-0123456789AB");
79 when(attrValChangedNotif.getCounter()).thenReturn(20L);
80 when(attrValChangedNotif.getNewValue()).thenReturn("new-value");
81 when(attrValChangedNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
82 when(attrValChangedNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
84 when(creationNotif.getObjectType()).thenReturn("air-interface-name");
85 when(creationNotif.getCounter()).thenReturn(20L);
86 when(creationNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
87 when(creationNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
89 when(deletionNotif.getCounter()).thenReturn(20L);
90 when(deletionNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
91 when(deletionNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
93 when(serviceProvider.getFaultService()).thenReturn(faultService);
94 when(serviceProvider.getDataProvider()).thenReturn(databaseService);
95 when(serviceProvider.getNotificationService()).thenReturn(notificationService);
99 public void testOtherNotif() {
100 Onf14EthernetContainerNotificationListener notifListener =
101 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
103 notifListener.onObjectDeletionNotification(deletionNotif);
104 notifListener.onObjectCreationNotification(creationNotif);
105 notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
109 public void testProblemNotifCritical() {
110 Onf14EthernetContainerNotificationListener notifListener =
111 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
113 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
115 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
116 return SEVERITYTYPECRITICAL.class;
120 notifListener.onProblemNotification(problemNotif);
124 public void testProblemNotifMajor() {
125 Onf14EthernetContainerNotificationListener notifListener =
126 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
128 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
130 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
131 return SEVERITYTYPEMAJOR.class;
135 notifListener.onProblemNotification(problemNotif);
139 public void testProblemNotifMinor() {
140 Onf14EthernetContainerNotificationListener notifListener =
141 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
143 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
145 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
146 return SEVERITYTYPEMINOR.class;
150 notifListener.onProblemNotification(problemNotif);
154 public void testProblemNotifWarning() {
155 Onf14EthernetContainerNotificationListener notifListener =
156 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
158 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
160 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
161 return SEVERITYTYPEWARNING.class;
165 notifListener.onProblemNotification(problemNotif);
169 public void testProblemNotifNonalarmed() {
170 Onf14EthernetContainerNotificationListener notifListener =
171 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
173 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
175 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
176 return SEVERITYTYPENONALARMED.class;
180 notifListener.onProblemNotification(problemNotif);
184 public void testProblemNotifNull() {
185 Onf14EthernetContainerNotificationListener notifListener =
186 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
188 when(problemNotif.getSeverity()).thenReturn(null);
190 notifListener.onProblemNotification(problemNotif);