Update features for Argon release
[ccsdk/features.git] / sdnr / wt / mountpoint-state-provider / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / mountpointstateprovider / test / TestMountpointNodeStateListenerImpl.java
1 /*
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 package org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.test;
20
21
22 import static org.junit.Assert.assertNotEquals;
23 import static org.junit.Assert.assertNotNull;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
30 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointNodeStateListenerImpl;
31 import org.onap.ccsdk.features.sdnr.wt.mountpointstateprovider.impl.MountpointStatePublisher;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev221225.ConnectionOper.ConnectionStatus;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
40 import org.opendaylight.yangtools.yang.common.Uint16;
41
42 public class TestMountpointNodeStateListenerImpl extends Mockito {
43
44     NetconfNodeStateService netconfNodeStateServiceMock = mock(NetconfNodeStateService.class);
45     MountpointNodeStateListenerImpl nodeStateListener =
46             new MountpointNodeStateListenerImpl(netconfNodeStateServiceMock);
47     MountpointStatePublisher mountpointStatePublisher;
48     NetconfNode netconfNode;
49     NodeId nNodeId = new NodeId("nSky");
50     VESCollectorService vesCollectorService;
51
52     @Before
53     public void initialize() {
54         DeviceManagerServiceProvider serviceProvider = mock(DeviceManagerServiceProvider.class);
55         vesCollectorService = mock(VESCollectorService.class);
56         NetconfNetworkElementService netconfNetworkElementService = mock(NetconfNetworkElementService.class);
57         when(netconfNetworkElementService.getServiceProvider()).thenReturn(serviceProvider);
58         when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService);
59         mountpointStatePublisher = new MountpointStatePublisher(vesCollectorService);
60         nodeStateListener.start(mountpointStatePublisher);
61         netconfNode = mock(NetconfNode.class);
62         when(netconfNode.getHost()).thenReturn(new Host(new IpAddress(new Ipv4Address("1.2.3.4"))));
63         when(netconfNode.getPort()).thenReturn(new PortNumber(Uint16.valueOf(2230)));
64         when(netconfNode.getConnectionStatus()).thenReturn(ConnectionStatus.Connected);
65     }
66
67     @Test
68     public void testOnCreated() {
69         assertNotNull(nNodeId);
70         assertNotNull(netconfNode);
71         nodeStateListener.onCreated(nNodeId, netconfNode);
72         assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
73     }
74
75     @Test
76     public void testOnStateChange() {
77         nodeStateListener.onStateChange(nNodeId, netconfNode);
78         assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
79     }
80
81     @Test
82     public void testOnRemoved() {
83         nodeStateListener.onRemoved(nNodeId);
84         assertNotEquals(mountpointStatePublisher.getStateObjects().size(), 0);
85     }
86
87 }