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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
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.service.DeviceManagerServiceProvider;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
44 import org.opendaylight.yangtools.yang.binding.DataObject;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
48 @RunWith(MockitoJUnitRunner.class)
49 public class TestORanChangeNotificationListener {
51 private static final String NODEID = "node1";
54 DeviceManagerServiceProvider serviceProvider;
56 NetconfBindingAccessor netconfAccessor;
58 DataProvider databaseService;
60 VESCollectorService vesCollectorService;
62 VESCollectorCfgService vesCfgService;
64 NotificationProxyParser notifProxyParser;
66 static NetconfConfigChange change;
71 when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
72 when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
73 when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
74 when(serviceProvider.getDataProvider()).thenReturn(databaseService);
75 when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
76 when(vesCollectorService.getNotificationProxyParser()).thenReturn(notifProxyParser);
78 ORanChangeNotificationListener notifListener =
79 new ORanChangeNotificationListener(netconfAccessor, serviceProvider);
81 Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
84 public int compareTo(PathArgument arg0) {
89 public Class<? extends DataObject> getType() {
90 return DataObject.class;
93 InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
94 NetconfConfigChange confChangeNotification = createNotification(EditOperationType.Create, target);
95 when(notifProxyParser.getTime(confChangeNotification)).thenReturn(Instant.now());
96 notifListener.onNetconfConfigChange(confChangeNotification);
97 verify(databaseService).writeEventLog(any(EventlogEntity.class));
104 private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
105 @SuppressWarnings("null")
106 final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
107 when(change.nonnullEdit()).thenReturn(edits);