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.Onf14WireInterfaceNotificationListener;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.test.mock.NetconfAccessorMock;
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.NetconfAccessor;
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.wire._interface._2._0.rev200123.AttributeValueChangedNotification;
35 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ObjectCreationNotification;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ObjectDeletionNotification;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.ProblemNotification;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPE;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPECRITICAL;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPEMAJOR;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPEMINOR;
42 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPENONALARMED;
43 import org.opendaylight.yang.gen.v1.urn.onf.yang.wire._interface._2._0.rev200123.SEVERITYTYPEWARNING;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
46 public class TestOnf14WireInterfaceNotificationListener extends Mockito {
47 private NetconfAccessor 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;
61 accessor = mock(NetconfAccessorMock.class);
62 nodeId = mock(NodeId.class);
63 serviceProvider = mock(DeviceManagerServiceProvider.class);
64 faultService = mock(FaultService.class);
65 databaseService = mock(DataProvider.class);
66 notificationService = mock(NotificationService.class);
68 problemNotif = mock(ProblemNotification.class);
69 deletionNotif = mock(ObjectDeletionNotification.class);
70 creationNotif = mock(ObjectCreationNotification.class);
71 attrValChangedNotif = mock(AttributeValueChangedNotification.class);
73 when(accessor.getNodeId()).thenReturn(nodeId);
74 when(problemNotif.getCounter()).thenReturn(10);
75 when(problemNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
76 when(problemNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-0abc-abcd-0123456789AB"));
77 when(problemNotif.getProblem()).thenReturn("modulationIsDownShifted");
79 when(attrValChangedNotif.getAttributeName()).thenReturn("12345678-0123-2345-abcd-0123456789AB");
80 when(attrValChangedNotif.getCounter()).thenReturn(20);
81 when(attrValChangedNotif.getNewValue()).thenReturn("new-value");
82 when(attrValChangedNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
83 when(attrValChangedNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
85 when(creationNotif.getObjectType()).thenReturn("air-interface-name");
86 when(creationNotif.getCounter()).thenReturn(20);
87 when(creationNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
88 when(creationNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
90 when(deletionNotif.getCounter()).thenReturn(20);
91 when(deletionNotif.getObjectIdRef()).thenReturn(new UniversalId("12345678-0123-1234-abcd-0123456789AB"));
92 when(deletionNotif.getTimestamp()).thenReturn(new DateAndTime("2020-02-05T12:30:45.283Z"));
94 when(serviceProvider.getFaultService()).thenReturn(faultService);
95 when(serviceProvider.getDataProvider()).thenReturn(databaseService);
96 when(serviceProvider.getNotificationService()).thenReturn(notificationService);
100 public void testOtherNotif() {
101 Onf14WireInterfaceNotificationListener notifListener =
102 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
104 notifListener.onObjectDeletionNotification(deletionNotif);
105 notifListener.onObjectCreationNotification(creationNotif);
106 notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
110 public void testProblemNotifCritical() {
111 Onf14WireInterfaceNotificationListener notifListener =
112 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
114 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
116 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
117 return SEVERITYTYPECRITICAL.class;
121 notifListener.onProblemNotification(problemNotif);
125 public void testProblemNotifMajor() {
126 Onf14WireInterfaceNotificationListener notifListener =
127 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
129 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
131 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
132 return SEVERITYTYPEMAJOR.class;
136 notifListener.onProblemNotification(problemNotif);
140 public void testProblemNotifMinor() {
141 Onf14WireInterfaceNotificationListener notifListener =
142 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
144 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
146 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
147 return SEVERITYTYPEMINOR.class;
151 notifListener.onProblemNotification(problemNotif);
155 public void testProblemNotifWarning() {
156 Onf14WireInterfaceNotificationListener notifListener =
157 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
159 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
161 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
162 return SEVERITYTYPEWARNING.class;
166 notifListener.onProblemNotification(problemNotif);
170 public void testProblemNotifNonalarmed() {
171 Onf14WireInterfaceNotificationListener notifListener =
172 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
174 when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
176 public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
177 return SEVERITYTYPENONALARMED.class;
181 notifListener.onProblemNotification(problemNotif);
185 public void testProblemNotifNull() {
186 Onf14WireInterfaceNotificationListener notifListener =
187 new Onf14WireInterfaceNotificationListener(accessor, serviceProvider);
189 when(problemNotif.getSeverity()).thenReturn(null);
191 notifListener.onProblemNotification(problemNotif);