dd61db0d197da8bae17434a3d6520a687827f926
[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.netconfnodestateservice.test;
23
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;
48
49 public class TestNetconfAccessorImpl extends Mockito {
50
51     @Test
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);
60
61         NetconfNodeStateServiceImpl netconfNodeStateService = mock(NetconfNodeStateServiceImpl.class);
62         NetconfAccessorImpl netconfAccessor = new NetconfAccessorImpl(nodeId, testNode, netconfCommunicatorManager,
63                 domContext, netconfNodeStateService);
64
65         Assert.assertNotNull(netconfAccessor);
66
67         NetconfAccessorImpl netconfAcessor2 = new NetconfAccessorImpl(netconfAccessor);
68
69         Assert.assertNotNull(netconfAcessor2);
70     }
71
72     @Test
73     public void testBindingNotifications() {
74         NetconfAccessorImpl netconfAccessor = TestNetconfHelper.getNetconfAcessorImpl();
75
76         DataBroker dataBroker = mock(DataBroker.class);
77
78         NotificationsService notificationService = mock(NotificationsService.class);
79
80         RpcConsumerRegistry rpcComerRegistry = mock(RpcConsumerRegistry.class);
81         when(rpcComerRegistry.getRpcService(NotificationsService.class)).thenReturn(notificationService);
82
83         MountPoint mountPoint = mock(MountPoint.class);
84         when(mountPoint.getService(RpcConsumerRegistry.class)).thenReturn(Optional.of(rpcComerRegistry));
85
86         //Start here
87         NetconfBindingNotificationsImpl test =
88                 new NetconfBindingNotificationsImpl(netconfAccessor, dataBroker, mountPoint);
89
90         String streamName = "NETCONF";
91         test.registerNotificationsStream(streamName);
92
93         //Capture parameters and assert them
94         ArgumentCaptor<CreateSubscriptionInput> captor = ArgumentCaptor.forClass(CreateSubscriptionInput.class);
95         verify(notificationService).createSubscription(captor.capture());
96
97         assertEquals("StreamName", streamName, captor.getValue().getStream().getValue());
98     }
99
100     @Test
101     public void testNotificationList() {
102
103         NetconfAccessorImpl netconfAccessor = TestNetconfHelper.getNetconfAcessorImpl();
104
105         DataBroker dataBroker = mock(DataBroker.class);
106
107         NotificationsService notificationService = mock(NotificationsService.class);
108
109         RpcConsumerRegistry rpcComerRegistry = mock(RpcConsumerRegistry.class);
110         when(rpcComerRegistry.getRpcService(NotificationsService.class)).thenReturn(notificationService);
111
112         MountPoint mountPoint = mock(MountPoint.class);
113         when(mountPoint.getService(RpcConsumerRegistry.class)).thenReturn(Optional.of(rpcComerRegistry));
114
115
116         //Start here
117         NetconfBindingNotificationsImpl test =
118                 new NetconfBindingNotificationsImpl(netconfAccessor, dataBroker, mountPoint);
119
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));
124
125         //Capture parameters and assert them
126         ArgumentCaptor<CreateSubscriptionInput> captor = ArgumentCaptor.forClass(CreateSubscriptionInput.class);
127         verify(notificationService).createSubscription(captor.capture());
128
129         assertEquals("StreamName", streamName, captor.getValue().getStream().getValue());
130
131     }
132
133 }