7709298e0960ea2d71b50184057a53e17f843972
[ccsdk/features.git] /
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.test;
20
21 import static org.mockito.Mockito.*;
22
23 import java.util.Arrays;
24 import java.util.List;
25
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.netconfnodestateservice.NetconfAccessor;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogEntity;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
41
42 public class TestORanChangeNotificationListener {
43
44     private static final String NODEID = "node1";
45
46     @Test
47     public void test() {
48
49         NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
50         DataProvider databaseService = mock(DataProvider.class);
51         ORanChangeNotificationListener notifListener =
52                 new ORanChangeNotificationListener(netconfAccessor, databaseService);
53         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
54         Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
55
56             @Override
57             public int compareTo(PathArgument arg0) {
58                 return 0;
59             }
60
61             @Override
62             public Class<? extends DataObject> getType() {
63                 return DataObject.class;
64             }
65         });
66         InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
67
68         notifListener.onNetconfConfigChange(createNotification(EditOperationType.Create, target));
69         EventlogEntity event = new EventlogBuilder().setNodeId(NODEID)
70                 .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build();
71         verify(databaseService).writeEventLog(event);
72
73     }
74
75     /**
76      * @param type
77      * @return
78      */
79     private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
80         NetconfConfigChange change = mock(NetconfConfigChange.class);
81
82         @SuppressWarnings("null")
83         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
84         when(change.nonnullEdit()).thenReturn(edits);
85         return change;
86     }
87 }