Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / netconf-executor / src / test / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / functions / netconf / executor / NetconfSessionImplTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
17
18 import org.apache.sshd.client.channel.ChannelSubsystem
19 import org.apache.sshd.client.session.ClientSessionImpl
20 import org.junit.After
21 import org.junit.Assert
22 import org.junit.Before
23 import org.junit.Test
24 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
25 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl
26 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl
27 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator
28 import java.util.concurrent.atomic.AtomicReference
29 import kotlin.script.experimental.api.asSuccess
30
31 class NetconfSessionImplTest {
32
33     private var device: NetconfDeviceSimulator? = null
34     private var deviceInfo: DeviceInfo? = null
35
36     @Before
37     fun before() {
38         deviceInfo = DeviceInfo().apply {
39             username = "username"
40             password = "password"
41             ipAddress = "localhost"
42             port = 2224
43             connectTimeout = 10
44         }
45
46         device = NetconfDeviceSimulator(deviceInfo!!.port)
47         device!!.start()
48     }
49
50     @After
51     fun after() {
52         device!!.stop()
53     }
54
55     @Throws(Exception::class)
56     fun testNetconfSession() {
57         val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo()))
58
59         Assert.assertNotNull(netconfSession.getSessionId())
60         Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString())
61
62         netconfSession.checkAndReestablish()
63
64         Assert.assertNotNull(netconfSession.getSessionId())
65         Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString())
66
67         Assert.assertTrue(!netconfSession.getDeviceCapabilitiesSet().isEmpty())
68     }
69
70     @Test
71     fun testNetconfSessionconnect() {
72         val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
73         netconfSession.connect()
74         Assert.assertTrue(netconfSession.sessionstatus("Open"))
75     }
76
77     @Test
78     fun testNetconfSessionreconnect() {
79         val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
80         netconfSession.connect()
81         netconfSession.reconnect()
82         Assert.assertTrue(netconfSession.sessionstatus("Open"))
83
84     }
85     @Test
86     fun testNetconfSessiondisconnect() {
87         val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
88         netconfSession.connect()
89         netconfSession.disconnect()
90         Assert.assertTrue(netconfSession.sessionstatus("Close"))
91
92     }
93     @Test
94     fun testNetconfSessioncheckAndReestablish() {
95         val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
96         netconfSession.connect()
97         netconfSession.checkAndReestablish()
98         Assert.assertTrue(netconfSession.sessionstatus("Open"))
99
100
101     }
102     @Test
103     fun testNetconfSessionconnecgetDeviceInfo() {
104         val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
105         netconfSession.connect()
106         Assert.assertNotNull(netconfSession.getDeviceInfo())
107         Assert.assertFalse(!netconfSession.getDeviceCapabilitiesSet().isEmpty())
108     }
109
110
111 }