1fb39864a2af7e7119b21bfaf2d6e3db340e993e
[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.openroadm71.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.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditOperationType;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.EditBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
42 import org.opendaylight.yangtools.yang.binding.DataObject;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
45
46 public class TestChangeNotificationListener {
47
48     private static final String NODEID = "node1";
49
50     @Test
51     public void test() {
52
53         NetconfAccessor netconfAccessor = mock(NetconfAccessor.class);
54         DataProvider databaseService = mock(DataProvider.class);
55         WebsocketManagerService notificationService = mock(WebsocketManagerService.class);
56         OpenroadmChangeNotificationListener notifListener =
57                 new OpenroadmChangeNotificationListener(netconfAccessor, databaseService, notificationService);
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     /**
81      * @param type
82      * @return
83      */
84     private static NetconfConfigChange createNotification(EditOperationType type, InstanceIdentifier<?> target) {
85         NetconfConfigChange change = mock(NetconfConfigChange.class);
86
87         @SuppressWarnings("null")
88         final @NonNull List<Edit> edits = Arrays.asList(new EditBuilder().setOperation(type).setTarget(target).build());
89         when(change.nonnullEdit()).thenReturn(edits);
90         return change;
91     }
92 }