4d64cca19194d5e33bd372ea847423fa6ee54c68
[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.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev191129.circuit.pack.features.CircuitPackComponents;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
43 import org.opendaylight.yangtools.yang.binding.DataObject;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
46
47 public class TestChangeNotificationListener {
48
49     private static final String NODEID = "node1";
50
51     @Test
52     public void test() {
53
54         NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
55         DataProvider databaseService = mock(DataProvider.class);
56         WebsocketManagerService notificationService = mock(WebsocketManagerService.class);
57         OpenroadmChangeNotificationListener notifListener =
58                 new OpenroadmChangeNotificationListener(netconfAccessor, databaseService, notificationService);
59         when(netconfAccessor.getNodeId()).thenReturn(new NodeId(NODEID));
60         List<? extends PathArgument> pathArguments = Arrays.asList(new PathArgument() {
61
62             @Override
63             public int compareTo(PathArgument arg0) {
64                 return 0;
65             }
66
67             @Override
68             public Class<? extends DataObject> getType() {
69                 return CircuitPackComponents.class;
70             }
71         });
72         InstanceIdentifier<?> target = InstanceIdentifier.unsafeOf(pathArguments);
73
74         notifListener.onNetconfConfigChange(createNotification(EditOperationType.Create, target));
75         EventlogEntity event = new EventlogBuilder().setNodeId(NODEID)
76                 .setNewValue(String.valueOf(EditOperationType.Create)).setObjectId(target.toString()).build();
77         verify(databaseService).writeEventLog(event);
78
79     }
80
81     /**
82      * @param type
83      * @return
84      */
85     private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
86         NetconfConfigChange change = mock(NetconfConfigChange.class);
87
88         @SuppressWarnings("null")
89         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
90         when(change.nonnullEdit()).thenReturn(edits);
91         return change;
92     }
93 }