2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.test;
24 import static org.junit.Assert.assertEquals;
25 import java.util.Arrays;
26 import java.util.Optional;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.mockito.ArgumentCaptor;
30 import org.mockito.Mockito;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNotifications;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.NetconfNodeStateServiceImpl;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfAccessorImpl;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.NetconfCommunicatorManager;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.binding.NetconfBindingNotificationsImpl;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.test.example.TestNetconfHelper;
38 import org.opendaylight.mdsal.binding.api.DataBroker;
39 import org.opendaylight.mdsal.binding.api.MountPoint;
40 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.NotificationsService;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
49 public class TestNetconfAccessorImpl extends Mockito {
52 public void testConstruct() {
53 NetconfCommunicatorManager netconfCommunicatorManager = mock(NetconfCommunicatorManager.class);
54 DomContext domContext = mock(DomContext.class);
55 String nodeIdString = "Test";
56 String capabilityStringForNetworkElement = "network-element";
57 NodeId nodeId = new NodeId(nodeIdString);
58 NetconfNode testNode = TestNetconfHelper.getTestNode(nodeId, capabilityStringForNetworkElement)
59 .augmentation(NetconfNode.class);
61 NetconfNodeStateServiceImpl netconfNodeStateService = mock(NetconfNodeStateServiceImpl.class);
62 NetconfAccessorImpl netconfAccessor = new NetconfAccessorImpl(nodeId, testNode, netconfCommunicatorManager,
63 domContext, netconfNodeStateService);
65 Assert.assertNotNull(netconfAccessor);
67 NetconfAccessorImpl netconfAcessor2 = new NetconfAccessorImpl(netconfAccessor);
69 Assert.assertNotNull(netconfAcessor2);
73 public void testBindingNotifications() {
74 NetconfAccessorImpl netconfAccessor = TestNetconfHelper.getNetconfAcessorImpl();
76 DataBroker dataBroker = mock(DataBroker.class);
78 NotificationsService notificationService = mock(NotificationsService.class);
80 RpcConsumerRegistry rpcComerRegistry = mock(RpcConsumerRegistry.class);
81 when(rpcComerRegistry.getRpcService(NotificationsService.class)).thenReturn(notificationService);
83 MountPoint mountPoint = mock(MountPoint.class);
84 when(mountPoint.getService(RpcConsumerRegistry.class)).thenReturn(Optional.of(rpcComerRegistry));
87 NetconfBindingNotificationsImpl test =
88 new NetconfBindingNotificationsImpl(netconfAccessor, dataBroker, mountPoint);
90 String streamName = "NETCONF";
91 test.registerNotificationsStream(streamName);
93 //Capture parameters and assert them
94 ArgumentCaptor<CreateSubscriptionInput> captor = ArgumentCaptor.forClass(CreateSubscriptionInput.class);
95 verify(notificationService).createSubscription(captor.capture());
97 assertEquals("StreamName", streamName, captor.getValue().getStream().getValue());
101 public void testNotificationList() {
103 NetconfAccessorImpl netconfAccessor = TestNetconfHelper.getNetconfAcessorImpl();
105 DataBroker dataBroker = mock(DataBroker.class);
107 NotificationsService notificationService = mock(NotificationsService.class);
109 RpcConsumerRegistry rpcComerRegistry = mock(RpcConsumerRegistry.class);
110 when(rpcComerRegistry.getRpcService(NotificationsService.class)).thenReturn(notificationService);
112 MountPoint mountPoint = mock(MountPoint.class);
113 when(mountPoint.getService(RpcConsumerRegistry.class)).thenReturn(Optional.of(rpcComerRegistry));
117 NetconfBindingNotificationsImpl test =
118 new NetconfBindingNotificationsImpl(netconfAccessor, dataBroker, mountPoint);
120 String streamName = NetconfNotifications.DefaultNotificationsStream+"ChangeIt";
121 StreamNameType streamNameType = new StreamNameType(streamName);
122 Stream stream = new StreamBuilder().setName(streamNameType).build();
123 test.registerNotificationsStream(Arrays.asList(stream));
125 //Capture parameters and assert them
126 ArgumentCaptor<CreateSubscriptionInput> captor = ArgumentCaptor.forClass(CreateSubscriptionInput.class);
127 verify(notificationService).createSubscription(captor.capture());
129 assertEquals("StreamName", streamName, captor.getValue().getStream().getValue());