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.*;
23 import java.util.Arrays;
24 import java.util.List;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.junit.Test;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.ORanChangeNotificationListener;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
40 import org.opendaylight.yangtools.yang.binding.DataObject;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
44 public class TestORanChangeNotificationListener {
46 private static final String NODEID = "node1";
51 NetconfBindingAccessor netconfAccessor = mock(NetconfBindingAccessor.class);
52 DataProvider databaseService = mock(DataProvider.class);
53 VESCollectorService vesCollectorService = mock(VESCollectorService.class);
54 VESCollectorCfgService vesCfgService = mock(VESCollectorCfgService.class);
56 when(vesCollectorService.getConfig()).thenReturn(vesCfgService);
57 when(vesCfgService.getReportingEntityName()).thenReturn("SDN-R");
58 ORanChangeNotificationListener notifListener =
59 new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService);
60 when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
61 Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
64 public int compareTo(PathArgument arg0) {
69 public Class<? extends DataObject> getType() {
70 return DataObject.class;
73 InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
75 notifListener.onNetconfConfigChange(createNotification(EditOperationType.Create, target));
76 EventlogEntity event = new EventlogBuilder().setNodeId(NODEID)
77 .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build();
78 verify(databaseService).writeEventLog(event);
86 private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
87 NetconfConfigChange change = mock(NetconfConfigChange.class);
89 @SuppressWarnings("null")
90 final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
91 when(change.nonnullEdit()).thenReturn(edits);