Add bounds to sphinx requirement
[ccsdk/features.git] / sdnr / wt / devicemanager-o-ran-sc / o-ran / ru-fh / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / oran / impl / binding / TestORanChangeNotificationListener.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
19 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding;
20
21 import static org.mockito.ArgumentMatchers.any;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24 import java.time.Instant;
25 import java.util.Arrays;
26 import java.util.List;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.binding.ORanChangeNotificationListener;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
38 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
45 import org.opendaylight.yangtools.yang.binding.DataObject;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
47 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
48
49 @RunWith(MockitoJUnitRunner.class)
50 public class TestORanChangeNotificationListener {
51
52     private static final String NODEID = "node1";
53
54     @Mock
55     DeviceManagerServiceProvider serviceProvider;
56     @Mock
57     NetconfBindingAccessor netconfAccessor;
58     @Mock
59     DataProvider databaseService;
60     @Mock
61     VESCollectorService vesCollectorService;
62     @Mock
63     VESCollectorCfgService vesCfgService;
64     @Mock
65     NotificationProxyParser notifProxyParser;
66     @Mock
67     static NetconfConfigChange change;
68
69     @Test
70     public void test() {
71
72         when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
73         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
74         when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
75         when(serviceProvider.getDataProvider()).thenReturn(databaseService);
76         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
77         when(vesCollectorService.getNotificationProxyParser()).thenReturn(notifProxyParser);
78
79         ORanChangeNotificationListener notifListener =
80                 new ORanChangeNotificationListener(netconfAccessor, serviceProvider);
81
82         Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
83
84             @Override
85             public int compareTo(PathArgument arg0) {
86                 return 0;
87             }
88
89             @Override
90             public Class<? extends DataObject> getType() {
91                 return DataObject.class;
92             }
93         });
94         InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
95         NetconfConfigChange confChangeNotification = createNotification(EditOperationType.Create, target);
96         when(notifProxyParser.getTime(confChangeNotification)).thenReturn(Instant.now());
97         notifListener.onNetconfConfigChange(confChangeNotification);
98         verify(databaseService).writeEventLog(any(EventlogEntity.class));
99     }
100
101     /**
102      * @param type
103      * @return
104      */
105     private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
106         @SuppressWarnings("null")
107         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
108         when(change.nonnullEdit()).thenReturn(edits);
109         return change;
110     }
111 }