052b5a7119316ec6309ed46b58b9f7b0099247e8
[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.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;
43
44 public class TestORanChangeNotificationListener {
45
46     private static final String NODEID = "node1";
47
48     @Test
49     public void test() {
50
51         NetconfBindingAccessor netconfAccessor = mock(NetconfBindingAccessor.class);
52         DataProvider databaseService = mock(DataProvider.class);
53         VESCollectorService vesCollectorService = mock(VESCollectorService.class);
54         VESCollectorCfgService vesCfgService = mock(VESCollectorCfgService.class);
55
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() {
62
63             @Override
64             public int compareTo(PathArgument arg0) {
65                 return 0;
66             }
67
68             @Override
69             public Class<? extends DataObject> getType() {
70                 return DataObject.class;
71             }
72         });
73         InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
74
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);
79
80     }
81
82     /**
83      * @param type
84      * @return
85      */
86     private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
87         NetconfConfigChange change = mock(NetconfConfigChange.class);
88
89         @SuppressWarnings("null")
90         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
91         when(change.nonnullEdit()).thenReturn(edits);
92         return change;
93     }
94 }