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