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.test;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23 import java.time.Instant;
24 import java.util.Arrays;
25 import java.util.List;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Mock;
30 import org.mockito.junit.MockitoJUnitRunner;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanChangeNotificationListener;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
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 NetconfBindingAccessor netconfAccessor;
56 DataProvider databaseService;
58 VESCollectorService vesCollectorService;
60 VESCollectorCfgService vesCfgService;
62 NotificationProxyParser notifProxyParser;
64 static NetconfConfigChange change;
69 when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
70 when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
71 when(vesCfgService.isVESCollectorEnabled()).thenReturn(true);
73 ORanChangeNotificationListener notifListener =
74 new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService, notifProxyParser);
76 Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
79 public int compareTo(PathArgument arg0) {
84 public Class<? extends DataObject> getType() {
85 return DataObject.class;
88 InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
89 NetconfConfigChange confChangeNotification = createNotification(EditOperationType.Create, target);
90 when(notifProxyParser.getTime(confChangeNotification)).thenReturn(Instant.now());
91 notifListener.onNetconfConfigChange(confChangeNotification);
92 EventlogEntity event = new EventlogBuilder().setNodeId(NODEID)
93 .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build();
94 verify(databaseService).writeEventLog(event);
102 private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
103 @SuppressWarnings("null")
104 final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
105 when(change.nonnullEdit()).thenReturn(edits);