2 * Copyright © 2017-2018 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
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
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
25 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl
26 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl
27 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator
28 import java.util.concurrent.atomic.AtomicReference
29 import kotlin.script.experimental.api.asSuccess
31 class NetconfSessionImplTest {
33 private var device: NetconfDeviceSimulator? = null
34 private var deviceInfo: DeviceInfo? = null
38 deviceInfo = DeviceInfo().apply {
41 ipAddress = "localhost"
46 device = NetconfDeviceSimulator(deviceInfo!!.port)
55 @Throws(Exception::class)
56 fun testNetconfSession() {
57 val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo()))
59 Assert.assertNotNull(netconfSession.getSessionId())
60 Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString())
62 netconfSession.checkAndReestablish()
64 Assert.assertNotNull(netconfSession.getSessionId())
65 Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString())
67 Assert.assertTrue(!netconfSession.getDeviceCapabilitiesSet().isEmpty())
71 fun testNetconfSessionconnect() {
72 val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
73 netconfSession.connect()
74 Assert.assertTrue(netconfSession.sessionstatus("Open"))
78 fun testNetconfSessionreconnect() {
79 val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
80 netconfSession.connect()
81 netconfSession.reconnect()
82 Assert.assertTrue(netconfSession.sessionstatus("Open"))
86 fun testNetconfSessiondisconnect() {
87 val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
88 netconfSession.connect()
89 netconfSession.disconnect()
90 Assert.assertTrue(netconfSession.sessionstatus("Close"))
94 fun testNetconfSessioncheckAndReestablish() {
95 val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
96 netconfSession.connect()
97 netconfSession.checkAndReestablish()
98 Assert.assertTrue(netconfSession.sessionstatus("Open"))
103 fun testNetconfSessionconnecgetDeviceInfo() {
104 val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!))
105 netconfSession.connect()
106 Assert.assertNotNull(netconfSession.getDeviceInfo())
107 Assert.assertFalse(!netconfSession.getDeviceCapabilitiesSet().isEmpty())