f6f7d90453f0ec5ed7e43bf29d3a6f110457c4f6
[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.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;
44
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;
52
53     private ObjectDeletionNotification deletionNotif;
54     private ObjectCreationNotification creationNotif;
55     private ProblemNotification problemNotif;
56     private AttributeValueChangedNotification attrValChangedNotif;
57
58     @Before
59     public void init() {
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);
66
67         problemNotif = mock(ProblemNotification.class);
68         deletionNotif = mock(ObjectDeletionNotification.class);
69         creationNotif = mock(ObjectCreationNotification.class);
70         attrValChangedNotif = mock(AttributeValueChangedNotification.class);
71
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");
77
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"));
83
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"));
88
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"));
92
93         when(serviceProvider.getFaultService()).thenReturn(faultService);
94         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
95         when(serviceProvider.getNotificationService()).thenReturn(notificationService);
96     }
97
98     @Test
99     public void testOtherNotif() {
100         Onf14EthernetContainerNotificationListener notifListener =
101                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
102
103         notifListener.onObjectDeletionNotification(deletionNotif);
104         notifListener.onObjectCreationNotification(creationNotif);
105         notifListener.onAttributeValueChangedNotification(attrValChangedNotif);
106     }
107
108     @Test
109     public void testProblemNotifCritical() {
110         Onf14EthernetContainerNotificationListener notifListener =
111                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
112
113         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
114             @Override
115             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
116                 return SEVERITYTYPECRITICAL.class;
117             }
118         });
119
120         notifListener.onProblemNotification(problemNotif);
121     }
122
123     @Test
124     public void testProblemNotifMajor() {
125         Onf14EthernetContainerNotificationListener notifListener =
126                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
127
128         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
129             @Override
130             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
131                 return SEVERITYTYPEMAJOR.class;
132             }
133         });
134
135         notifListener.onProblemNotification(problemNotif);
136     }
137
138     @Test
139     public void testProblemNotifMinor() {
140         Onf14EthernetContainerNotificationListener notifListener =
141                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
142
143         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
144             @Override
145             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
146                 return SEVERITYTYPEMINOR.class;
147             }
148         });
149
150         notifListener.onProblemNotification(problemNotif);
151     }
152
153     @Test
154     public void testProblemNotifWarning() {
155         Onf14EthernetContainerNotificationListener notifListener =
156                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
157
158         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
159             @Override
160             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
161                 return SEVERITYTYPEWARNING.class;
162             }
163         });
164
165         notifListener.onProblemNotification(problemNotif);
166     }
167
168     @Test
169     public void testProblemNotifNonalarmed() {
170         Onf14EthernetContainerNotificationListener notifListener =
171                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
172
173         when(problemNotif.getSeverity()).thenAnswer(new Answer<Class<? extends SEVERITYTYPE>>() {
174             @Override
175             public Class<? extends SEVERITYTYPE> answer(InvocationOnMock invocation) throws Throwable {
176                 return SEVERITYTYPENONALARMED.class;
177             }
178         });
179
180         notifListener.onProblemNotification(problemNotif);
181     }
182
183     @Test
184     public void testProblemNotifNull() {
185         Onf14EthernetContainerNotificationListener notifListener =
186                 new Onf14EthernetContainerNotificationListener(accessor, serviceProvider);
187
188         when(problemNotif.getSeverity()).thenReturn(null);
189
190         notifListener.onProblemNotification(problemNotif);
191     }
192
193 }