305bd9ca382100ab3346634e68172bb4feebca09
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.test;
23
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.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl.OpenroadmChangeNotificationListener;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
41 import org.opendaylight.yangtools.yang.binding.DataObject;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
44
45 public class TestChangeNotificationListener {
46     // variables
47     private static final String NODEID = "node1";
48
49     //    end of variables
50     //    public methods
51     @Test
52     public void test() {
53
54         NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
55         DataProvider databaseService = mock(DataProvider.class);
56         OpenroadmChangeNotificationListener notifListener =
57                 new OpenroadmChangeNotificationListener(netconfAccessor, databaseService);
58         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
59         Iterable<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
60
61             @Override
62             public int compareTo(PathArgument arg0) {
63                 return 0;
64             }
65
66             @Override
67             public Class<? extends DataObject> getType() {
68                 return DataObject.class;
69             }
70         });
71         InstanceIdentifier<?> target = InstanceIdentifier.create(pathArguments);
72
73         notifListener.onNetconfConfigChange(createNotification(EditOperationType.Create, target));
74         EventlogEntity event = new EventlogBuilder().setNodeId(NODEID)
75                 .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build();
76         verify(databaseService).writeEventLog(event);
77
78     }
79
80     //  end of public methods
81     // private methods
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     // end of private methods
95 }