09e44f47dce34ca5a40be16b89d5727017945473
[ccsdk/features.git] /
1 /*
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14;
19
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;
45
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;
53
54     private ObjectDeletionNotification deletionNotif;
55     private ObjectCreationNotification creationNotif;
56     private ProblemNotification problemNotif;
57     private AttributeValueChangedNotification attrValChangedNotif;
58     private WebsocketManagerService websocketService;
59
60     @Before
61     public void init() {
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);
69
70         problemNotif = mock(ProblemNotification.class);
71         deletionNotif = mock(ObjectDeletionNotification.class);
72         creationNotif = mock(ObjectCreationNotification.class);
73         attrValChangedNotif = mock(AttributeValueChangedNotification.class);
74
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");
80
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"));
86
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"));
91
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"));
95
96         when(serviceProvider.getFaultService()).thenReturn(faultService);
97         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
98         when(serviceProvider.getNotificationService()).thenReturn(notificationService);
99         when(serviceProvider.getWebsocketService()).thenReturn(websocketService);
100     }
101
102     @Test
103     public void testOtherNotif() {
104         Onf14EthernetContainerNotificationListener notifListener =
105                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
106
107         notifListener.onObjectDeletionNotification(deletionNotif);
108         notifListener.onObjectCreationNotification(creationNotif);
109         notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
110     }
111
112     @Test
113     public void testProblemNotifCritical() {
114         Onf14EthernetContainerNotificationListener notifListener =
115                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
116
117         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
118             @Override
119             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
120                 return SEVERITYTYPECRITICAL.class;
121             }
122         });
123
124         notifListener.onProblemNotification(problemNotif);
125     }
126
127     @Test
128     public void testProblemNotifMajor() {
129         Onf14EthernetContainerNotificationListener notifListener =
130                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
131
132         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
133             @Override
134             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
135                 return SEVERITYTYPEMAJOR.class;
136             }
137         });
138
139         notifListener.onProblemNotification(problemNotif);
140     }
141
142     @Test
143     public void testProblemNotifMinor() {
144         Onf14EthernetContainerNotificationListener notifListener =
145                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
146
147         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
148             @Override
149             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
150                 return SEVERITYTYPEMINOR.class;
151             }
152         });
153
154         notifListener.onProblemNotification(problemNotif);
155     }
156
157     @Test
158     public void testProblemNotifWarning() {
159         Onf14EthernetContainerNotificationListener notifListener =
160                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
161
162         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
163             @Override
164             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
165                 return SEVERITYTYPEWARNING.class;
166             }
167         });
168
169         notifListener.onProblemNotification(problemNotif);
170     }
171
172     @Test
173     public void testProblemNotifNonalarmed() {
174         Onf14EthernetContainerNotificationListener notifListener =
175                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
176
177         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
178             @Override
179             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
180                 return SEVERITYTYPENONALARMED.class;
181             }
182         });
183
184         notifListener.onProblemNotification(problemNotif);
185     }
186
187     @Test
188     public void testProblemNotifNull() {
189         Onf14EthernetContainerNotificationListener notifListener =
190                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
191
192         when(problemNotif.getSeverity()).thenReturn(null);
193
194         notifListener.onProblemNotification(problemNotif);
195     }
196
197 }