2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 import java.util.Arrays;
28 import java.util.List;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmChangeNotificationListener;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
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 TestChangeNotificationListener {
46 private static final String NODEID = "node1";
51 NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
52 DataProvider databaseService = mock(DataProvider.class);
53 OpenroadmChangeNotificationListener notifListener =
54 new OpenroadmChangeNotificationListener(netconfAccessor, databaseService);
55 when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
56 Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
59 public int compareTo(PathArgument arg0) {
64 public Class<? extends DataObject> getType() {
65 return DataObject.class;
68 InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
70 notifListener.onNetconfConfigChange(createNotification(EditOperationType.Create, target));
71 EventlogEntity event = new EventlogBuilder().setNodeId(NODEID)
72 .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build();
73 verify(databaseService).writeEventLog(event);
81 private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
82 NetconfConfigChange change = mock(NetconfConfigChange.class);
84 @SuppressWarnings("null")
85 final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
86 when(change.nonnullEdit()).thenReturn(edits);