From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- .../executor/ComponentNetconfExecutorTest.kt | 79 ------ .../netconf/executor/NetconfSessionImplTest.kt | 111 -------- .../executor/core/NetconfRpcServiceImplTest.kt | 124 --------- .../executor/mocks/NetconfDeviceSimulator.kt | 62 ----- .../executor/mocks/NetconfSubsystemFactory.kt | 125 --------- .../netconf/executor/utils/RpcMessageUtilsTest.kt | 306 --------------------- .../executor/ComponentNetconfExecutorTest.kt | 79 ++++++ .../netconf/executor/NetconfSessionImplTest.kt | 111 ++++++++ .../executor/core/NetconfRpcServiceImplTest.kt | 124 +++++++++ .../executor/mocks/NetconfDeviceSimulator.kt | 62 +++++ .../executor/mocks/NetconfSubsystemFactory.kt | 125 +++++++++ .../netconf/executor/utils/RpcMessageUtilsTest.kt | 306 +++++++++++++++++++++ .../src/test/resources/logback-test.xml | 2 +- 13 files changed, 808 insertions(+), 808 deletions(-) delete mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt delete mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt delete mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt delete mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt delete mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt delete mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/test') diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt deleted file mode 100644 index e2b901998..000000000 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Modifications Copyright © 2019 IBM, Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor - -import com.fasterxml.jackson.databind.JsonNode -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@EnableAutoConfiguration -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"]) -@DirtiesContext -@TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"], - locations = ["classpath:application-test.properties"]) -class ComponentNetconfExecutorTest { - - @Autowired - lateinit var componentNetconfExecutor: ComponentNetconfExecutor - - - @Test - fun testComponentNetconfExecutor() { - - val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json", - ExecutionServiceInput::class.java)!! - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", - "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - - val executionContext = bluePrintRuntimeService.getExecutionContext() - - - componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService - - //TODO("Set Attribute properties") - val stepMetaData: MutableMap = hashMapOf() - stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf") - stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor") - stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") - // Set Step Inputs in Blueprint Runtime Service - bluePrintRuntimeService.put("activate-netconf-step-inputs", stepMetaData.asJsonNode()) - - componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService - componentNetconfExecutor.stepName = "activate-netconf" - componentNetconfExecutor.apply(executionServiceInput) - - } -} - diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt deleted file mode 100644 index e7a514347..000000000 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor - -import org.apache.sshd.client.channel.ChannelSubsystem -import org.apache.sshd.client.session.ClientSessionImpl -import org.junit.After -import org.junit.Assert -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator -import java.util.concurrent.atomic.AtomicReference -import kotlin.script.experimental.api.asSuccess - -class NetconfSessionImplTest { - - private var device: NetconfDeviceSimulator? = null - private var deviceInfo: DeviceInfo? = null - - @Before - fun before() { - deviceInfo = DeviceInfo().apply { - username = "username" - password = "password" - ipAddress = "localhost" - port = 2224 - connectTimeout = 10 - } - - device = NetconfDeviceSimulator(deviceInfo!!.port) - device!!.start() - } - - @After - fun after() { - device!!.stop() - } - - @Throws(Exception::class) - fun testNetconfSession() { - val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo())) - - Assert.assertNotNull(netconfSession.getSessionId()) - Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString()) - - netconfSession.checkAndReestablish() - - Assert.assertNotNull(netconfSession.getSessionId()) - Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString()) - - Assert.assertTrue(!netconfSession.getDeviceCapabilitiesSet().isEmpty()) - } - - @Test - fun testNetconfSessionconnect() { - val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) - netconfSession.connect() - Assert.assertTrue(netconfSession.sessionstatus("Open")) - } - - @Test - fun testNetconfSessionreconnect() { - val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) - netconfSession.connect() - netconfSession.reconnect() - Assert.assertTrue(netconfSession.sessionstatus("Open")) - - } - @Test - fun testNetconfSessiondisconnect() { - val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) - netconfSession.connect() - netconfSession.disconnect() - Assert.assertTrue(netconfSession.sessionstatus("Close")) - - } - @Test - fun testNetconfSessioncheckAndReestablish() { - val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) - netconfSession.connect() - netconfSession.checkAndReestablish() - Assert.assertTrue(netconfSession.sessionstatus("Open")) - - - } - @Test - fun testNetconfSessionconnecgetDeviceInfo() { - val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) - netconfSession.connect() - Assert.assertNotNull(netconfSession.getDeviceInfo()) - Assert.assertFalse(!netconfSession.getDeviceCapabilitiesSet().isEmpty()) - } - - -} diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt deleted file mode 100644 index 8f1f71501..000000000 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt +++ /dev/null @@ -1,124 +0,0 @@ -package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.core - -import org.junit.After -import org.junit.Assert -import org.junit.Before -import org.junit.Test - -import org.junit.Assert.* -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator - -class NetconfRpcServiceImplTest { - - private var device: NetconfDeviceSimulator? = null - private var deviceInfo: DeviceInfo? = null - - @Before - fun before() { - deviceInfo = DeviceInfo().apply { - username = "username" - password = "password" - ipAddress = "localhost" - port = 2224 - connectTimeout = 10 - } - - device = NetconfDeviceSimulator(deviceInfo!!.port) - device!!.start() - } - - @After - fun after() { - device!!.stop() - } - - @Test - fun setNetconfSession() { - - } - - @Test - fun getConfig() { - - val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) - val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - Assert.assertTrue(netconfRpcServiceImpl.getConfig("filter","target").status.equals("failure")) - } - - - @Test - fun deleteConfig() { - - val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) - val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - Assert.assertTrue(netconfRpcServiceImpl.deleteConfig("target").status.equals("failure")) - } - - @Test - fun lock() { - val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) - val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - Assert.assertTrue(netconfRpcServiceImpl.lock("target").status.equals("failure")) - } - - @Test - fun unLock() { - val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) - val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - Assert.assertTrue(netconfRpcServiceImpl.unLock("target").status.equals("failure")) - } - - @Test - fun commit() { - val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) - val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - Assert.assertTrue(netconfRpcServiceImpl.commit(true,60,"persist","1").status.equals("failure")) - - } - - @Test - fun cancelCommit() { - val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo())) - val netconfRpcServiceImpl = NetconfRpcServiceImpl(DeviceInfo()) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - - Assert.assertNotNull(netconfRpcServiceImpl.cancelCommit("1")) - } - - @Test - fun discardConfig() { - val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) - val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - Assert.assertTrue(netconfRpcServiceImpl.discardConfig().status.equals("failure")) - - } - - @Test - fun editConfig() { - } - - @Test - fun validate() { - val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) - val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) - netconfRpcServiceImpl.setNetconfSession(netconfSession) - netconfSession.connect() - Assert.assertTrue(netconfRpcServiceImpl.validate("target").status.equals("failure")) - - } - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt deleted file mode 100644 index a2a3946db..000000000 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.mocks - - -import org.apache.sshd.common.NamedFactory -import org.apache.sshd.server.Command -import org.apache.sshd.server.SshServer -import org.apache.sshd.server.auth.UserAuth -import org.apache.sshd.server.auth.UserAuthNoneFactory -import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils.NetconfSubsystemFactory -import java.util.* - - -class NetconfDeviceSimulator(private val port: Int) { - - private var sshd: SshServer? = null - - fun start() { - sshd = SshServer.setUpDefaultServer() - sshd!!.port = port - sshd!!.keyPairProvider = SimpleGeneratorHostKeyProvider() - - val userAuthFactories = ArrayList>() - userAuthFactories.add(UserAuthNoneFactory()) - sshd!!.userAuthFactories = userAuthFactories - - val namedFactoryList = ArrayList>() - namedFactoryList.add(NetconfSubsystemFactory()) - sshd!!.subsystemFactories = namedFactoryList - - try { - sshd!!.start() - } catch (e: Exception) { - e.printStackTrace() - } - - } - - fun stop() { - try { - sshd!!.stop(true) - } catch (e: Exception) { - e.printStackTrace() - } - - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt deleted file mode 100644 index 7eaef030b..000000000 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils - - -import java.io.IOException -import java.io.InputStream -import java.io.OutputStream -import org.apache.sshd.common.NamedFactory; -import org.apache.sshd.server.Command; -import org.apache.sshd.server.Environment; -import org.apache.sshd.server.ExitCallback; - - -class NetconfSubsystemFactory : NamedFactory { - - private val END_CHAR_SEQUENCE = "]]>]]>" - - override fun create(): Command { - return NetconfSubsystem() - } - - override fun getName(): String { - return "netconf" - } - - /** - * Simple implementation of netconf reading 1 request, sending a 'hello' response and quitting - */ - inner class NetconfSubsystem : Command { - private var input: InputStream? = null - private var out: OutputStream? = null - private var clientThread: Thread? = null - private var r: Int = 0 - - @Throws(IOException::class) - override fun start(env: Environment) { - clientThread = Thread(object : Runnable { - - override fun run() { - try { - val message = StringBuilder() - while (true) { - process(createHelloString()) - r = input!!.read() - if (r == -1) { - break - } else { - val c = r.toChar() - message.append(c) - val messageString = message.toString() - if (messageString.endsWith(END_CHAR_SEQUENCE)) { - println("Detected end message:\n$messageString") - process(createHelloString()) - message.setLength(0) - break - } - } - } - } catch (e: IOException) { - e.printStackTrace() - } - - } - - @Throws(IOException::class) - private fun process(xmlMessage: String) { - println("Sending message:\n$xmlMessage") - out!!.write(xmlMessage.toByteArray(charset("UTF-8"))) - out!!.write((END_CHAR_SEQUENCE + "\n").toByteArray(charset("UTF-8"))) - out!!.flush() - } - - private fun createHelloString(): String { - val sessionId = "" + (Math.random() * Integer.MAX_VALUE).toInt() - return ("\n" - + "\nurn:ietf:params:netconf:base:1.0\n" - + "urn:ietf:params:netconf:base:1.1\n\n" - + "" + sessionId + "\n") - } - }) - - clientThread!!.start() - } - - @Throws(Exception::class) - override fun destroy() { - try { - clientThread!!.join(2000) - } catch (e: InterruptedException) { - // log.warn("Error joining Client thread" + e.getMessage()); - } - - clientThread!!.interrupt() - } - - override fun setInputStream(input: InputStream) { - this.input = input - } - - override fun setOutputStream(out: OutputStream) { - this.out = out - } - - override fun setErrorStream(err: OutputStream) {} - - override fun setExitCallback(callback: ExitCallback) {} - - - - } -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt deleted file mode 100644 index 8a60d8097..000000000 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.utils - -import org.junit.Assert -import org.junit.Assert.assertTrue -import org.junit.Test -import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.NetconfException -import kotlin.test.fail - -class RpcMessageUtilsTest { - - @Test - fun getConfig() { - val checkString = ("" - + "" - + "Test-Filter-Content" - + "") - - val messageId = "Test-Message-ID" - val configType = NetconfDatastore.CANDIDATE.datastore - val filterContent = "Test-Filter-Content" - - val result = - NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - } - - - @Test - fun editConfig() { - val checkString = ("" - + "" - + "Test-Default-Operation" - + "Test-Filter-Content") - - val messageId = "Test-Message-ID" - val configType = NetconfDatastore.CANDIDATE.datastore - val filterContent = "Test-Filter-Content" - val defaultOperation = "Test-Default-Operation" - - val result = - NetconfMessageUtils.editConfig(messageId, configType, defaultOperation, filterContent).replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - } - - @Test - fun validate() { - val checkString = ("" - + "" - + "") - - val messageId = "Test-Message-ID" - val configType = NetconfDatastore.CANDIDATE.datastore - - val result = NetconfMessageUtils.validate(messageId, configType).replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - } - - @Test - fun cancelCommit() { - val checkString = - ("" + - "" + - "" + - "1234" + - "") - - val messageId = "Test-Message-ID" - - val cancelCommitPersistId = - NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitPersistId)) - Assert.assertEquals(checkString, cancelCommitPersistId) - } - - @Test - fun cancelCommitNoPersistId() { - val checkString = - ("" + - "" + - "" + - "") - - val messageId = "Test-Message-ID" - - val cancelCommitNoPersistId = NetconfMessageUtils.cancelCommit(messageId, "").replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitNoPersistId)) - Assert.assertEquals(checkString, cancelCommitNoPersistId) - } - - @Test - fun commit() { - val checkString = ("" - + "" - + "") - - val messageId = "Test-Message-ID" - - val commit = NetconfMessageUtils.commit(messageId, false, 0, "", "").replace("[\n\r\t]".toRegex(), "") - - val commitWithPersistButNotConfirmed = - NetconfMessageUtils.commit(messageId, false, 0, "1234", "").replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(commit)) - Assert.assertEquals(checkString, commit) - Assert.assertEquals(checkString, commitWithPersistButNotConfirmed) - - } - - @Test - fun commitPersistId() { - val checkString = - ("" + - "" + - "" + - "1234" + - "") - - val messageId = "Test-Message-ID" - - val result = NetconfMessageUtils.commit(messageId, false, 30, "", "1234").replace("[\n\r\t]".toRegex(), "") - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - - try { - NetconfMessageUtils.commit(messageId, true, 30, "", "1234").replace("[\n\r\t]".toRegex(), "") - } catch (e: NetconfException) { - Assert.assertEquals("Can't proceed with both confirmed flag and persistId(1234) specified. Only one should be specified.", - e.message) - return - } - - fail() - } - - @Test - fun commitPersist() { - val checkString = - ("" + - "" + - "" + - "" + - "30" + - "1234" + - "") - - val messageId = "Test-Message-ID" - - val result = NetconfMessageUtils.commit(messageId, true, 30, "1234", "").replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - - try { - NetconfMessageUtils.commit(messageId, false, 30, "1234", "1234").replace("[\n\r\t]".toRegex(), "") - } catch (e: NetconfException) { - Assert.assertEquals("Can't proceed with both persist(1234) and persistId(1234) specified. Only one should be specified.", - e.message) - return - } - fail() - } - - @Test - fun unlock() { - val checkString = ("" - + "" - + "") - - val messageId = "Test-Message-ID" - val configType = NetconfDatastore.CANDIDATE.datastore - - val result = NetconfMessageUtils.unlock(messageId, configType).replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - } - - @Test - fun deleteConfig() { - val checkString = ("" - + "" - + "") - - val messageId = "Test-Message-ID" - val netconfTargetConfig = NetconfDatastore.CANDIDATE.datastore - - val result = NetconfMessageUtils.deleteConfig(messageId, netconfTargetConfig).replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - } - - @Test - fun discardChanges() { - val checkString = ("" - + "" - + "") - - val messageId = "Test-Message-ID" - - val result = NetconfMessageUtils.discardChanges(messageId).replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - } - - @Test - fun lock() { - val checkString = ("" - + "" - + "") - - val messageId = "Test-Message-ID" - val configType = NetconfDatastore.CANDIDATE.datastore - val result = NetconfMessageUtils.lock(messageId, configType).replace("[\n\r\t]".toRegex(), "") - - assertTrue(NetconfMessageUtils.validateRPCXML(result)) - Assert.assertEquals(checkString, result) - } - - @Test - fun getMsgId() { - val checkString = ("testmessage") - - var messageId = "message-id=\"testmessage\"" - var result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "") - Assert.assertEquals(checkString, result) - - messageId = "message-id=\"hello\"" - result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "") - Assert.assertEquals("hello", result) - - messageId = "message-id" - result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "") - Assert.assertEquals("", result) - } - - @Test - fun createHelloString() { - val checkString = (" " - +" hi hello ]]>]]>") - - val capability = listOf("hi", "hello") - - val result = NetconfMessageUtils.createHelloString(capability).replace("[\n\r\t]".toRegex(), "") - Assert.assertEquals(checkString, result) - } - - @Test - fun validateChunkedFraming() { - val reply = ("hello") - val result = NetconfMessageUtils.validateChunkedFraming(reply) - Assert.assertFalse(result) - } - - @Test - fun checkReply(){ - assertTrue(NetconfMessageUtils.checkReply("ok")) - } - - @Test - fun formatRPCRequest(){ - val checkString = ("#199" + - " hi hello " + - "##") - - val request = (" " - +" hi hello ]]>]]>") - - val messageId = "Test-Message-ID" - - val capabilities = setOf("hi", "hello","urn:ietf:params:netconf:base:1.1") - - val result = NetconfMessageUtils.formatRPCRequest(request,messageId,capabilities).replace("[\n\r\t]".toRegex(), "") - Assert.assertEquals(checkString, result) - - - } - - - - -} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt new file mode 100644 index 000000000..b84c2d1ae --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt @@ -0,0 +1,79 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Modifications Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor + +import com.fasterxml.jackson.databind.JsonNode +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.annotation.DirtiesContext +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@EnableAutoConfiguration +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) +@DirtiesContext +@TestPropertySource(properties = +["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"], + locations = ["classpath:application-test.properties"]) +class ComponentNetconfExecutorTest { + + @Autowired + lateinit var componentNetconfExecutor: ComponentNetconfExecutor + + + @Test + fun testComponentNetconfExecutor() { + + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json", + ExecutionServiceInput::class.java)!! + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val executionContext = bluePrintRuntimeService.getExecutionContext() + + + componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService + + //TODO("Set Attribute properties") + val stepMetaData: MutableMap = hashMapOf() + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf") + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor") + stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") + // Set Step Inputs in Blueprint Runtime Service + bluePrintRuntimeService.put("activate-netconf-step-inputs", stepMetaData.asJsonNode()) + + componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService + componentNetconfExecutor.stepName = "activate-netconf" + componentNetconfExecutor.apply(executionServiceInput) + + } +} + diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt new file mode 100644 index 000000000..b462ad0e8 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfSessionImplTest.kt @@ -0,0 +1,111 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor + +import org.apache.sshd.client.channel.ChannelSubsystem +import org.apache.sshd.client.session.ClientSessionImpl +import org.junit.After +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core.NetconfRpcServiceImpl +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator +import java.util.concurrent.atomic.AtomicReference +import kotlin.script.experimental.api.asSuccess + +class NetconfSessionImplTest { + + private var device: NetconfDeviceSimulator? = null + private var deviceInfo: DeviceInfo? = null + + @Before + fun before() { + deviceInfo = DeviceInfo().apply { + username = "username" + password = "password" + ipAddress = "localhost" + port = 2224 + connectTimeout = 10 + } + + device = NetconfDeviceSimulator(deviceInfo!!.port) + device!!.start() + } + + @After + fun after() { + device!!.stop() + } + + @Throws(Exception::class) + fun testNetconfSession() { + val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo())) + + Assert.assertNotNull(netconfSession.getSessionId()) + Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString()) + + netconfSession.checkAndReestablish() + + Assert.assertNotNull(netconfSession.getSessionId()) + Assert.assertEquals("localhost:2224", netconfSession.getDeviceInfo().toString()) + + Assert.assertTrue(!netconfSession.getDeviceCapabilitiesSet().isEmpty()) + } + + @Test + fun testNetconfSessionconnect() { + val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) + netconfSession.connect() + Assert.assertTrue(netconfSession.sessionstatus("Open")) + } + + @Test + fun testNetconfSessionreconnect() { + val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) + netconfSession.connect() + netconfSession.reconnect() + Assert.assertTrue(netconfSession.sessionstatus("Open")) + + } + @Test + fun testNetconfSessiondisconnect() { + val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) + netconfSession.connect() + netconfSession.disconnect() + Assert.assertTrue(netconfSession.sessionstatus("Close")) + + } + @Test + fun testNetconfSessioncheckAndReestablish() { + val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) + netconfSession.connect() + netconfSession.checkAndReestablish() + Assert.assertTrue(netconfSession.sessionstatus("Open")) + + + } + @Test + fun testNetconfSessionconnecgetDeviceInfo() { + val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(deviceInfo!!)) + netconfSession.connect() + Assert.assertNotNull(netconfSession.getDeviceInfo()) + Assert.assertFalse(!netconfSession.getDeviceCapabilitiesSet().isEmpty()) + } + + +} diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt new file mode 100644 index 000000000..68d3e246f --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt @@ -0,0 +1,124 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core + +import org.junit.After +import org.junit.Assert +import org.junit.Before +import org.junit.Test + +import org.junit.Assert.* +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.mocks.NetconfDeviceSimulator + +class NetconfRpcServiceImplTest { + + private var device: NetconfDeviceSimulator? = null + private var deviceInfo: DeviceInfo? = null + + @Before + fun before() { + deviceInfo = DeviceInfo().apply { + username = "username" + password = "password" + ipAddress = "localhost" + port = 2224 + connectTimeout = 10 + } + + device = NetconfDeviceSimulator(deviceInfo!!.port) + device!!.start() + } + + @After + fun after() { + device!!.stop() + } + + @Test + fun setNetconfSession() { + + } + + @Test + fun getConfig() { + + val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) + val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + Assert.assertTrue(netconfRpcServiceImpl.getConfig("filter","target").status.equals("failure")) + } + + + @Test + fun deleteConfig() { + + val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) + val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + Assert.assertTrue(netconfRpcServiceImpl.deleteConfig("target").status.equals("failure")) + } + + @Test + fun lock() { + val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) + val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + Assert.assertTrue(netconfRpcServiceImpl.lock("target").status.equals("failure")) + } + + @Test + fun unLock() { + val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) + val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + Assert.assertTrue(netconfRpcServiceImpl.unLock("target").status.equals("failure")) + } + + @Test + fun commit() { + val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) + val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + Assert.assertTrue(netconfRpcServiceImpl.commit(true,60,"persist","1").status.equals("failure")) + + } + + @Test + fun cancelCommit() { + val netconfSession = NetconfSessionImpl(deviceInfo!!, NetconfRpcServiceImpl(DeviceInfo())) + val netconfRpcServiceImpl = NetconfRpcServiceImpl(DeviceInfo()) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + + Assert.assertNotNull(netconfRpcServiceImpl.cancelCommit("1")) + } + + @Test + fun discardConfig() { + val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) + val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + Assert.assertTrue(netconfRpcServiceImpl.discardConfig().status.equals("failure")) + + } + + @Test + fun editConfig() { + } + + @Test + fun validate() { + val netconfRpcServiceImpl = NetconfRpcServiceImpl(deviceInfo!!) + val netconfSession = NetconfSessionImpl(deviceInfo!!, netconfRpcServiceImpl) + netconfRpcServiceImpl.setNetconfSession(netconfSession) + netconfSession.connect() + Assert.assertTrue(netconfRpcServiceImpl.validate("target").status.equals("failure")) + + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt new file mode 100644 index 000000000..c6d6308ab --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfDeviceSimulator.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.mocks + + +import org.apache.sshd.common.NamedFactory +import org.apache.sshd.server.Command +import org.apache.sshd.server.SshServer +import org.apache.sshd.server.auth.UserAuth +import org.apache.sshd.server.auth.UserAuthNoneFactory +import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfSubsystemFactory +import java.util.* + + +class NetconfDeviceSimulator(private val port: Int) { + + private var sshd: SshServer? = null + + fun start() { + sshd = SshServer.setUpDefaultServer() + sshd!!.port = port + sshd!!.keyPairProvider = SimpleGeneratorHostKeyProvider() + + val userAuthFactories = ArrayList>() + userAuthFactories.add(UserAuthNoneFactory()) + sshd!!.userAuthFactories = userAuthFactories + + val namedFactoryList = ArrayList>() + namedFactoryList.add(NetconfSubsystemFactory()) + sshd!!.subsystemFactories = namedFactoryList + + try { + sshd!!.start() + } catch (e: Exception) { + e.printStackTrace() + } + + } + + fun stop() { + try { + sshd!!.stop(true) + } catch (e: Exception) { + e.printStackTrace() + } + + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt new file mode 100644 index 000000000..de0a5d016 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/mocks/NetconfSubsystemFactory.kt @@ -0,0 +1,125 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils + + +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream +import org.apache.sshd.common.NamedFactory; +import org.apache.sshd.server.Command; +import org.apache.sshd.server.Environment; +import org.apache.sshd.server.ExitCallback; + + +class NetconfSubsystemFactory : NamedFactory { + + private val END_CHAR_SEQUENCE = "]]>]]>" + + override fun create(): Command { + return NetconfSubsystem() + } + + override fun getName(): String { + return "netconf" + } + + /** + * Simple implementation of netconf reading 1 request, sending a 'hello' response and quitting + */ + inner class NetconfSubsystem : Command { + private var input: InputStream? = null + private var out: OutputStream? = null + private var clientThread: Thread? = null + private var r: Int = 0 + + @Throws(IOException::class) + override fun start(env: Environment) { + clientThread = Thread(object : Runnable { + + override fun run() { + try { + val message = StringBuilder() + while (true) { + process(createHelloString()) + r = input!!.read() + if (r == -1) { + break + } else { + val c = r.toChar() + message.append(c) + val messageString = message.toString() + if (messageString.endsWith(END_CHAR_SEQUENCE)) { + println("Detected end message:\n$messageString") + process(createHelloString()) + message.setLength(0) + break + } + } + } + } catch (e: IOException) { + e.printStackTrace() + } + + } + + @Throws(IOException::class) + private fun process(xmlMessage: String) { + println("Sending message:\n$xmlMessage") + out!!.write(xmlMessage.toByteArray(charset("UTF-8"))) + out!!.write((END_CHAR_SEQUENCE + "\n").toByteArray(charset("UTF-8"))) + out!!.flush() + } + + private fun createHelloString(): String { + val sessionId = "" + (Math.random() * Integer.MAX_VALUE).toInt() + return ("\n" + + "\nurn:ietf:params:netconf:base:1.0\n" + + "urn:ietf:params:netconf:base:1.1\n\n" + + "" + sessionId + "\n") + } + }) + + clientThread!!.start() + } + + @Throws(Exception::class) + override fun destroy() { + try { + clientThread!!.join(2000) + } catch (e: InterruptedException) { + // log.warn("Error joining Client thread" + e.getMessage()); + } + + clientThread!!.interrupt() + } + + override fun setInputStream(input: InputStream) { + this.input = input + } + + override fun setOutputStream(out: OutputStream) { + this.out = out + } + + override fun setErrorStream(err: OutputStream) {} + + override fun setExitCallback(callback: ExitCallback) {} + + + + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt new file mode 100644 index 000000000..a4ef4410a --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt @@ -0,0 +1,306 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils + +import org.junit.Assert +import org.junit.Assert.assertTrue +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException +import kotlin.test.fail + +class RpcMessageUtilsTest { + + @Test + fun getConfig() { + val checkString = ("" + + "" + + "Test-Filter-Content" + + "") + + val messageId = "Test-Message-ID" + val configType = NetconfDatastore.CANDIDATE.datastore + val filterContent = "Test-Filter-Content" + + val result = + NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + } + + + @Test + fun editConfig() { + val checkString = ("" + + "" + + "Test-Default-Operation" + + "Test-Filter-Content") + + val messageId = "Test-Message-ID" + val configType = NetconfDatastore.CANDIDATE.datastore + val filterContent = "Test-Filter-Content" + val defaultOperation = "Test-Default-Operation" + + val result = + NetconfMessageUtils.editConfig(messageId, configType, defaultOperation, filterContent).replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + } + + @Test + fun validate() { + val checkString = ("" + + "" + + "") + + val messageId = "Test-Message-ID" + val configType = NetconfDatastore.CANDIDATE.datastore + + val result = NetconfMessageUtils.validate(messageId, configType).replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + } + + @Test + fun cancelCommit() { + val checkString = + ("" + + "" + + "" + + "1234" + + "") + + val messageId = "Test-Message-ID" + + val cancelCommitPersistId = + NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitPersistId)) + Assert.assertEquals(checkString, cancelCommitPersistId) + } + + @Test + fun cancelCommitNoPersistId() { + val checkString = + ("" + + "" + + "" + + "") + + val messageId = "Test-Message-ID" + + val cancelCommitNoPersistId = NetconfMessageUtils.cancelCommit(messageId, "").replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitNoPersistId)) + Assert.assertEquals(checkString, cancelCommitNoPersistId) + } + + @Test + fun commit() { + val checkString = ("" + + "" + + "") + + val messageId = "Test-Message-ID" + + val commit = NetconfMessageUtils.commit(messageId, false, 0, "", "").replace("[\n\r\t]".toRegex(), "") + + val commitWithPersistButNotConfirmed = + NetconfMessageUtils.commit(messageId, false, 0, "1234", "").replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(commit)) + Assert.assertEquals(checkString, commit) + Assert.assertEquals(checkString, commitWithPersistButNotConfirmed) + + } + + @Test + fun commitPersistId() { + val checkString = + ("" + + "" + + "" + + "1234" + + "") + + val messageId = "Test-Message-ID" + + val result = NetconfMessageUtils.commit(messageId, false, 30, "", "1234").replace("[\n\r\t]".toRegex(), "") + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + + try { + NetconfMessageUtils.commit(messageId, true, 30, "", "1234").replace("[\n\r\t]".toRegex(), "") + } catch (e: NetconfException) { + Assert.assertEquals("Can't proceed with both confirmed flag and persistId(1234) specified. Only one should be specified.", + e.message) + return + } + + fail() + } + + @Test + fun commitPersist() { + val checkString = + ("" + + "" + + "" + + "" + + "30" + + "1234" + + "") + + val messageId = "Test-Message-ID" + + val result = NetconfMessageUtils.commit(messageId, true, 30, "1234", "").replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + + try { + NetconfMessageUtils.commit(messageId, false, 30, "1234", "1234").replace("[\n\r\t]".toRegex(), "") + } catch (e: NetconfException) { + Assert.assertEquals("Can't proceed with both persist(1234) and persistId(1234) specified. Only one should be specified.", + e.message) + return + } + fail() + } + + @Test + fun unlock() { + val checkString = ("" + + "" + + "") + + val messageId = "Test-Message-ID" + val configType = NetconfDatastore.CANDIDATE.datastore + + val result = NetconfMessageUtils.unlock(messageId, configType).replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + } + + @Test + fun deleteConfig() { + val checkString = ("" + + "" + + "") + + val messageId = "Test-Message-ID" + val netconfTargetConfig = NetconfDatastore.CANDIDATE.datastore + + val result = NetconfMessageUtils.deleteConfig(messageId, netconfTargetConfig).replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + } + + @Test + fun discardChanges() { + val checkString = ("" + + "" + + "") + + val messageId = "Test-Message-ID" + + val result = NetconfMessageUtils.discardChanges(messageId).replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + } + + @Test + fun lock() { + val checkString = ("" + + "" + + "") + + val messageId = "Test-Message-ID" + val configType = NetconfDatastore.CANDIDATE.datastore + val result = NetconfMessageUtils.lock(messageId, configType).replace("[\n\r\t]".toRegex(), "") + + assertTrue(NetconfMessageUtils.validateRPCXML(result)) + Assert.assertEquals(checkString, result) + } + + @Test + fun getMsgId() { + val checkString = ("testmessage") + + var messageId = "message-id=\"testmessage\"" + var result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "") + Assert.assertEquals(checkString, result) + + messageId = "message-id=\"hello\"" + result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "") + Assert.assertEquals("hello", result) + + messageId = "message-id" + result = NetconfMessageUtils.getMsgId(messageId).replace("[\n\r\t]".toRegex(), "") + Assert.assertEquals("", result) + } + + @Test + fun createHelloString() { + val checkString = (" " + +" hi hello ]]>]]>") + + val capability = listOf("hi", "hello") + + val result = NetconfMessageUtils.createHelloString(capability).replace("[\n\r\t]".toRegex(), "") + Assert.assertEquals(checkString, result) + } + + @Test + fun validateChunkedFraming() { + val reply = ("hello") + val result = NetconfMessageUtils.validateChunkedFraming(reply) + Assert.assertFalse(result) + } + + @Test + fun checkReply(){ + assertTrue(NetconfMessageUtils.checkReply("ok")) + } + + @Test + fun formatRPCRequest(){ + val checkString = ("#199" + + " hi hello " + + "##") + + val request = (" " + +" hi hello ]]>]]>") + + val messageId = "Test-Message-ID" + + val capabilities = setOf("hi", "hello","urn:ietf:params:netconf:base:1.1") + + val result = NetconfMessageUtils.formatRPCRequest(request,messageId,capabilities).replace("[\n\r\t]".toRegex(), "") + Assert.assertEquals(checkString, result) + + + } + + + + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml index f9ec9fe57..355cd3ace 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/logback-test.xml @@ -26,7 +26,7 @@ - + -- cgit 1.2.3-korg