2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotEquals;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25 import java.io.IOException;
26 import java.util.Optional;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
32 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointNodeConnectListenerImpl;
33 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisher;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
43 import org.opendaylight.yangtools.yang.common.Uint16;
45 public class TestMountpointNodeConnectListenerImpl {
47 DeviceManagerServiceProvider serviceProvider;
48 MountpointStatePublisher mountpointStatePublisher;
49 NetconfNodeStateService netconfNodeStateServiceMock;
50 MountpointNodeConnectListenerImpl nodeConnectListener;
51 //NetconfNodeMock netconfNodeMock;
52 NetconfNode netconfNode;
54 NetconfAccessor accessor;
55 VESCollectorService vesCollectorService;
58 public void initialize() throws IOException {
59 serviceProvider = mock(DeviceManagerServiceProvider.class);
60 netconfNodeStateServiceMock = mock(NetconfNodeStateService.class);
62 netconfNode = mock(NetconfNode.class);
63 when(netconfNode.getHost()).thenReturn(new Host(new IpAddress(new Ipv4Address("1.2.3.4"))));
64 when(netconfNode.getPort()).thenReturn(new PortNumber(Uint16.valueOf(2230)));
65 when(netconfNode.getConnectionStatus()).thenReturn(ConnectionStatus.Connected);
67 vesCollectorService = mock(VESCollectorService.class);
68 NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class);
69 nNodeId = new NodeId("nSky");
70 accessor = mock(NetconfAccessor.class);
71 when(accessor.getNodeId()).thenReturn(nNodeId);
72 when(accessor.getNetconfNode()).thenReturn(netconfNode);
74 mountpointStatePublisher = new MountpointStatePublisher(vesCollectorService);
75 when(netconfNetworkElementService.getServiceProvider()).thenReturn(serviceProvider);
76 when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
78 nodeConnectListener = new MountpointNodeConnectListenerImpl(netconfNodeStateServiceMock);
79 nodeConnectListener.start(mountpointStatePublisher);
83 public void testOnEnterConnected() {
84 nodeConnectListener.onEnterConnected(accessor);
85 assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
89 public void testOnLeaveConnected() {
90 nodeConnectListener.onLeaveConnected(nNodeId, Optional.of(netconfNode));
91 assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
95 public void testClose() throws Exception {
96 assertEquals(mountpointStatePublisher.getStateObjects().size(), 0);
97 nodeConnectListener.close();