Support for PM (Performance Management)
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / onf14 / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf14 / dom / TestOnf14DomAirInterfaceNotificationListener.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.dom;
19
20 import java.time.Instant;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.Mockito;
25 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DevicemanagerQNames;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.notifications.Onf14DomAirInterfaceNotificationListener;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.util.NetconfDeviceNotification;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
33 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
35 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
36 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
37 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
38 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
39
40 public class TestOnf14DomAirInterfaceNotificationListener extends Mockito {
41     private NetconfDomAccessor accessor;
42     private NodeId nodeId;
43     private DeviceManagerServiceProvider serviceProvider;
44     private FaultService faultService;
45     private DataProvider databaseService;
46     private NotificationService notificationService;
47
48     private @NonNull WebsocketManagerService websocketService;
49
50     @Before
51     public void init() {
52         accessor = mock(NetconfDomAccessor.class);
53         nodeId = mock(NodeId.class);
54         serviceProvider = mock(DeviceManagerServiceProvider.class);
55         faultService = mock(FaultService.class);
56         databaseService = mock(DataProvider.class);
57         notificationService = mock(NotificationService.class);
58         websocketService = mock(WebsocketManagerService.class);
59
60         when(accessor.getNodeId()).thenReturn(nodeId);
61         when(serviceProvider.getFaultService()).thenReturn(faultService);
62         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
63         when(serviceProvider.getNotificationService()).thenReturn(notificationService);
64         when(serviceProvider.getWebsocketService()).thenReturn(websocketService);
65     }
66
67     @Test
68     public void testOtherNotif() {
69         Onf14DomAirInterfaceNotificationListener notifListener =
70                 new Onf14DomAirInterfaceNotificationListener(accessor, serviceProvider);
71
72         NetconfDeviceNotification ndn =
73                 new NetconfDeviceNotification(createAirInterfaceCreationNotification(), Instant.now());
74         notifListener.onNotification(ndn);
75         ndn = new NetconfDeviceNotification(createAirInterfaceAVCNotification(), Instant.now());
76         notifListener.onNotification(ndn);
77         ndn = new NetconfDeviceNotification(createAirInterfaceDeletionNotification(), Instant.now());
78         notifListener.onNotification(ndn);
79         ndn = new NetconfDeviceNotification(createAirInterfaceProblemNotification(), Instant.now());
80         notifListener.onNotification(ndn);
81     }
82
83     private ContainerNode createAirInterfaceProblemNotification() {
84         return Builders.containerBuilder()
85                 .withNodeIdentifier(
86                         NodeIdentifier.create(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION))
87                 .withChild(ImmutableNodes
88                         .leafNode(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_COUNTER, "47"))
89                 .withChild(ImmutableNodes.leafNode(
90                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_PROBLEM,
91                         "12345678-0123-2345-abcd-0123456789AB"))
92                 .withChild(ImmutableNodes.leafNode(
93                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_OBJECT_ID_REF,
94                         "12345678-0123-1234-abcd-0123456789AB"))
95                 .withChild(ImmutableNodes.leafNode(
96                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_TIMESTAMP,
97                         "2022-02-05T12:30:45.283Z"))
98                 .withChild(ImmutableNodes.leafNode(
99                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_PROBLEM_NOTIFICATION_SEVERITY,
100                         "SEVERITY_TYPE_CRITICAL"))
101                 .build();
102     }
103
104     private ContainerNode createAirInterfaceAVCNotification() {
105         return Builders.containerBuilder()
106                 .withNodeIdentifier(
107                         NodeIdentifier.create(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION))
108                 .withChild(ImmutableNodes
109                         .leafNode(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_COUNTER, "47"))
110                 .withChild(ImmutableNodes.leafNode(
111                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_ATTRIBUTE_NAME,
112                         "12345678-0123-2345-abcd-0123456789AB"))
113                 .withChild(ImmutableNodes.leafNode(
114                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_NEW_VALUE, "new-value"))
115                 .withChild(ImmutableNodes.leafNode(
116                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_OBJECT_ID_REF,
117                         "12345678-0123-1234-abcd-0123456789AB"))
118                 .withChild(ImmutableNodes.leafNode(
119                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_AVC_NOTIFICATION_TIMESTAMP,
120                         "2022-02-05T12:30:45.283Z"))
121                 .build();
122     }
123
124     private ContainerNode createAirInterfaceDeletionNotification() {
125         return Builders.containerBuilder()
126                 .withNodeIdentifier(
127                         NodeIdentifier.create(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION))
128                 .withChild(ImmutableNodes
129                         .leafNode(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION_COUNTER, "47"))
130                 .withChild(ImmutableNodes.leafNode(
131                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION_TIMESTAMP,
132                         "2022-02-05T12:30:45.283Z"))
133                 .withChild(ImmutableNodes.leafNode(
134                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_DELETE_NOTIFICATION_OBJECT_ID_REF,
135                         "12345678-0123-1234-abcd-0123456789AB"))
136                 .build();
137     }
138
139     private ContainerNode createAirInterfaceCreationNotification() {
140         return Builders.containerBuilder()
141                 .withNodeIdentifier(
142                         NodeIdentifier.create(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION))
143                 .withChild(ImmutableNodes
144                         .leafNode(Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_COUNTER, "47"))
145                 .withChild(ImmutableNodes.leafNode(
146                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_OBJECT_TYPE,
147                         "air-interface-name"))
148                 .withChild(ImmutableNodes.leafNode(
149                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_TIMESTAMP,
150                         "2022-02-05T12:30:45.283Z"))
151                 .withChild(ImmutableNodes.leafNode(
152                         Onf14DevicemanagerQNames.AIR_INTERFACE_OBJECT_CREATE_NOTIFICATION_OBJECT_ID_REF,
153                         "12345678-0123-1234-abcd-0123456789AB"))
154                 .build();
155     }
156
157 }