From 1072867dfac0df993cbd3e44bcc11a5cac7465fd Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Tue, 22 Sep 2020 12:16:46 -0400 Subject: Enabling Code Formatter Code Formatter was turned off due to java 11 migation Issue-ID: CCSDK-2852 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I3d02ed3cc7a93d7551fe25356512cfe8db1517d8 --- .../netconf/executor/ComponentNetconfExecutor.kt | 7 +- .../functions/netconf/executor/NetconfDevice.kt | 1 + .../netconf/executor/NetconfExecutorExtensions.kt | 3 +- .../functions/netconf/executor/api/DeviceInfo.kt | 8 ++ .../netconf/executor/api/NetconfSessionListener.kt | 1 + .../executor/core/NetconfDeviceCommunicator.kt | 11 +++ .../netconf/executor/core/NetconfSessionImpl.kt | 7 +- .../netconf/executor/utils/NetconfConstant.kt | 2 + .../netconf/executor/utils/NetconfMessageUtils.kt | 18 +++-- .../netconf/executor/api/DeviceInfoTest.kt | 1 + .../netconf/executor/api/NetconfMessageTest.kt | 1 + .../executor/core/NetconfDeviceCommunicatorTest.kt | 6 +- .../executor/core/NetconfRpcServiceImplTest.kt | 3 + .../executor/core/NetconfSessionImplTest.kt | 21 ++--- .../core/NetconfSessionListenerImplTest.kt | 1 + .../netconf/executor/utils/RpcMessageUtilsTest.kt | 90 ++++++++++++++-------- 16 files changed, 127 insertions(+), 54 deletions(-) (limited to 'ms/blueprintsprocessor/functions/netconf-executor') diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt index 307e73e6b..b64790065 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt @@ -35,6 +35,7 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic AbstractComponentFunction() { companion object { + const val SCRIPT_TYPE = "script-type" const val SCRIPT_CLASS_REFERENCE = "script-class-reference" const val INSTANCE_DEPENDENCIES = "instance-dependencies" @@ -66,8 +67,10 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic // Handles both script processing and error handling scriptComponent.executeScript(executionServiceInput) - componentFunctionScriptingService.cleanupInstance(bluePrintRuntimeService.bluePrintContext(), - scriptType) + componentFunctionScriptingService.cleanupInstance( + bluePrintRuntimeService.bluePrintContext(), + scriptType + ) } override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt index a69e4d9d6..d1855cb62 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt @@ -21,6 +21,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core.Ne import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core.NetconfSessionImpl data class NetconfDevice(val deviceInfo: DeviceInfo) { + val netconfRpcService = NetconfRpcServiceImpl(deviceInfo) val netconfSession: NetconfSession diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt index f52cb0a62..b964388cb 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt @@ -44,7 +44,8 @@ fun AbstractComponentFunction.netconfDeviceInfo(requirementName: String): Device val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties( requirement - .node!!, requirement.capability!! + .node!!, + requirement.capability!! ) return netconfDeviceInfo(capabilityProperties) diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt index 4456cb0de..25cfb3392 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt @@ -20,20 +20,28 @@ import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty class DeviceInfo { + @get:JsonProperty("login-account") var username: String? = null + @get:JsonProperty("login-key") var password: String? = null + @get:JsonProperty("target-ip-address") var ipAddress: String? = null + @get:JsonProperty("port-number") var port: Int = 0 + @get:JsonProperty("connection-time-out") var connectTimeout: Long = 30 + @get:JsonIgnore var source: String? = null + @get:JsonProperty("reply-time-out") var replyTimeout: Int = 30 + @get:JsonIgnore var idleTimeout: Int = 99999 diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt index 23982dcb5..1cb4b3732 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSessionListener.kt @@ -16,5 +16,6 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api interface NetconfSessionListener { + fun accept(event: NetconfReceivedEvent) } diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt index 8f8fc1463..b2d4d98fe 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt @@ -120,6 +120,7 @@ class NetconfDeviceCommunicator( internal enum class NetconfMessageState { NO_MATCHING_PATTERN { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { ']' -> FIRST_BRACKET @@ -129,6 +130,7 @@ class NetconfDeviceCommunicator( } }, FIRST_BRACKET { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { ']' -> SECOND_BRACKET @@ -137,6 +139,7 @@ class NetconfDeviceCommunicator( } }, SECOND_BRACKET { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { '>' -> FIRST_BIGGER @@ -145,6 +148,7 @@ class NetconfDeviceCommunicator( } }, FIRST_BIGGER { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { ']' -> THIRD_BRACKET @@ -153,6 +157,7 @@ class NetconfDeviceCommunicator( } }, THIRD_BRACKET { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { ']' -> ENDING_BIGGER @@ -161,6 +166,7 @@ class NetconfDeviceCommunicator( } }, ENDING_BIGGER { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { '>' -> END_PATTERN @@ -169,6 +175,7 @@ class NetconfDeviceCommunicator( } }, FIRST_LF { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { '#' -> FIRST_HASH @@ -179,6 +186,7 @@ class NetconfDeviceCommunicator( } }, FIRST_HASH { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { '#' -> SECOND_HASH @@ -187,6 +195,7 @@ class NetconfDeviceCommunicator( } }, SECOND_HASH { + override fun evaluateChar(c: Char): NetconfMessageState { return when (c) { '\n' -> END_CHUNKED_PATTERN @@ -195,11 +204,13 @@ class NetconfDeviceCommunicator( } }, END_CHUNKED_PATTERN { + override fun evaluateChar(c: Char): NetconfMessageState { return NO_MATCHING_PATTERN } }, END_PATTERN { + override fun evaluateChar(c: Char): NetconfMessageState { return NO_MATCHING_PATTERN } diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt index 3d3eee8f0..7aefbb0d6 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt @@ -65,7 +65,7 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ try { log.info( "$deviceInfo: Connecting to Netconf Device with timeouts C:${deviceInfo.connectTimeout}, " + - "R:${deviceInfo.replyTimeout}, I:${deviceInfo.idleTimeout}" + "R:${deviceInfo.replyTimeout}, I:${deviceInfo.idleTimeout}" ) startConnection() log.info("$deviceInfo: Connected to Netconf Device") @@ -78,7 +78,7 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ override fun disconnect() { var retryNum = 3 while (rpcService.closeSession(false).status - .equals(RpcStatus.FAILURE, true) && retryNum > 0 + .equals(RpcStatus.FAILURE, true) && retryNum > 0 ) { log.error("disconnect: graceful disconnect failed, retrying $retryNum times...") retryNum-- @@ -228,7 +228,8 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ ImmutableSet.of( ClientSession.ClientSessionEvent.WAIT_AUTH, ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED - ), 0 + ), + 0 ) if (!event.contains(ClientSession.ClientSessionEvent.AUTHED)) { throw NetconfException("$deviceInfo: Failed to authenticate session.") diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt index 03177e8ec..54877d5eb 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfConstant.kt @@ -27,11 +27,13 @@ enum class ModifyAction(val action: String) { } object RpcStatus { + const val SUCCESS = "success" const val FAILURE = "failure" } object RpcMessageUtils { + const val OPEN = "<" const val CLOSE = ">" const val EQUAL = "=" diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt index 232dca621..32d7dcadc 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt @@ -31,6 +31,7 @@ import kotlin.text.Charsets.UTF_8 class NetconfMessageUtils { companion object { + val log = LoggerFactory.getLogger(NetconfMessageUtils::class.java) const val NEW_LINE = "\n" @@ -141,13 +142,13 @@ class NetconfMessageUtils { if (!persist.isEmpty() && !persistId.isEmpty()) { throw NetconfException( "Can't proceed with both persist($persist) and " + - "persistId($persistId) specified. Only one should be specified." + "persistId($persistId) specified. Only one should be specified." ) } if (confirmed && !persistId.isEmpty()) { throw NetconfException( "Can't proceed with both confirmed flag and " + - "persistId($persistId) specified. Only one should be specified." + "persistId($persistId) specified. Only one should be specified." ) } @@ -366,8 +367,10 @@ class NetconfMessageUtils { if (!message.startsWith(RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH)) { // chunk encode message message = - (RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + message.toByteArray(UTF_8).size + RpcMessageUtils.NEW_LINE + message + RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + - RpcMessageUtils.NEW_LINE) + ( + RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + message.toByteArray(UTF_8).size + RpcMessageUtils.NEW_LINE + message + RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + + RpcMessageUtils.NEW_LINE + ) } return message } @@ -383,9 +386,10 @@ class NetconfMessageUtils { if (!request.contains(RpcMessageUtils.XML_HEADER)) { if (request.startsWith(RpcMessageUtils.NEW_LINE + RpcMessageUtils.HASH)) { request = - request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0] + RpcMessageUtils.XML_HEADER + request.substring( - request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].length - ) + request.split("<".toRegex()).dropLastWhile { it.isEmpty() } + .toTypedArray()[0] + RpcMessageUtils.XML_HEADER + request.substring( + request.split("<".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].length + ) } else { request = RpcMessageUtils.XML_HEADER + "\n" + request } diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfoTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfoTest.kt index ab051597b..930fb1276 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfoTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfoTest.kt @@ -20,6 +20,7 @@ import org.junit.Test import kotlin.test.assertEquals class DeviceInfoTest { + @Test fun testToString() { diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessageTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessageTest.kt index e5bacc547..f4e352165 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessageTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessageTest.kt @@ -22,6 +22,7 @@ import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus class NetconfMessageTest { + @Test fun testSuccessfulDeviceResponse() { val dr: DeviceResponse = genSuccessfulEmptyDeviceResponse() diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicatorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicatorTest.kt index 1991fc4f6..c70a43e49 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicatorTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicatorTest.kt @@ -42,6 +42,7 @@ import kotlin.test.assertFalse import kotlin.test.assertTrue class NetconfDeviceCommunicatorTest { + private lateinit var netconfSession: NetconfSession private lateinit var netconfSessionListener: NetconfSessionListener private lateinit var mockInputStream: InputStream @@ -51,7 +52,9 @@ class NetconfDeviceCommunicatorTest { private val endPatternCharArray: List = stringToCharArray(RpcMessageUtils.END_PATTERN) companion object { + private val chunkedEnding = "\n##\n" + // using example from section 4.2 of RFC6242 (https://tools.ietf.org/html/rfc6242#section-4.2) private val validChunkedEncodedMsg = """ | @@ -197,7 +200,8 @@ class NetconfDeviceCommunicatorTest { xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> - """.trimIndent(), eventSlot.captured.messagePayload + """.trimIndent(), + eventSlot.captured.messagePayload ) } 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 index 9a3652aa1..b119d26f0 100644 --- 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 @@ -33,9 +33,11 @@ import kotlin.test.assertFailsWith import kotlin.test.assertTrue class NetconfRpcServiceImplTest { + private lateinit var mockNetconfSession: NetconfSessionImpl companion object { + private const val someString = "someString" private const val replyStr = "this is a reply" private val failedDeviceResponse = DeviceResponse( @@ -46,6 +48,7 @@ class NetconfRpcServiceImplTest { status = RpcStatus.SUCCESS, requestMessage = "request message", responseMessage = replyStr ) // responseMessage will be null in this POJO + // but will be set later from mockSession private const val msgId = "100" private const val timeout = 5 diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImplTest.kt index b94c092e3..41e4f8290 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImplTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImplTest.kt @@ -53,6 +53,7 @@ import kotlin.test.assertTrue class NetconfSessionImplTest { companion object { + val SUCCESSFUL_DEVICE_RESPONSE = DeviceResponse().apply { status = RpcStatus.SUCCESS errorMessage = "" @@ -150,7 +151,7 @@ class NetconfSessionImplTest { // rpcService.closeSession succeeds with status not RpcStatus.FAILURE val netconfSessionSpy = spyk(netconfSession, recordPrivateCalls = true) every { rpcService.closeSession(any()) } returns - FAILED_DEVICE_RESPONSE andThen SUCCESSFUL_DEVICE_RESPONSE + FAILED_DEVICE_RESPONSE andThen SUCCESSFUL_DEVICE_RESPONSE every { mockClientSession.close() } just Runs every { mockSshClient.close() } just Runs every { mockClientChannel.close() } just Runs @@ -247,7 +248,7 @@ class NetconfSessionImplTest { // make sure the replies didn't change assertTrue { netconfSessionSpy.getReplies().size == 1 && - netconfSessionSpy.getReplies().containsKey("somekey") + netconfSessionSpy.getReplies().containsKey("somekey") } verify(exactly = 0) { netconfSessionSpy.clearReplies() } } @@ -312,7 +313,7 @@ class NetconfSessionImplTest { val futureRet: CompletableFuture = CompletableFuture.completedFuture(futureMsg) every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet every { netconfCommunicator.getFutureFromSendMessage(any(), any(), any()) } throws - ExecutionException("exec exception", Exception("nested exception")) + ExecutionException("exec exception", Exception("nested exception")) every { netconfSessionSpy["close"]() as Unit } just Runs every { netconfSessionSpy.checkAndReestablish() } just Runs netconfSessionSpy.setSession(mockClientSession) @@ -329,7 +330,7 @@ class NetconfSessionImplTest { val futureRet: CompletableFuture = CompletableFuture.completedFuture(futureMsg) every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet every { netconfCommunicator.getFutureFromSendMessage(any(), any(), any()) } throws - ExecutionException("exec exception", Exception("nested exception")) + ExecutionException("exec exception", Exception("nested exception")) every { netconfSessionSpy["close"]() as Unit } throws IOException("got an IO exception") every { netconfSessionSpy.checkAndReestablish() } just Runs // call the method @@ -429,7 +430,7 @@ class NetconfSessionImplTest { succeededSessionFuture.value = mockClientSession every { mockSshClient.connect(deviceInfo.username, deviceInfo.ipAddress, deviceInfo.port) } returns succeededSessionFuture every { mockClientSession.waitFor(any(), any()) } returns - setOf(ClientSession.ClientSessionEvent.WAIT_AUTH, ClientSession.ClientSessionEvent.CLOSED) + setOf(ClientSession.ClientSessionEvent.WAIT_AUTH, ClientSession.ClientSessionEvent.CLOSED) val netconfSessionSpy = spyk(netconfSession, recordPrivateCalls = true) every { netconfSessionSpy["setupNewSSHClient"]() as Unit } just Runs netconfSessionSpy.setClient(mockSshClient) @@ -451,11 +452,11 @@ class NetconfSessionImplTest { succeededSessionFuture.value = mockClientSession every { mockSshClient.connect(deviceInfo.username, deviceInfo.ipAddress, deviceInfo.port) } returns succeededSessionFuture every { mockClientSession.waitFor(any(), any()) } returns - setOf( - ClientSession.ClientSessionEvent.WAIT_AUTH, - ClientSession.ClientSessionEvent.CLOSED, - ClientSession.ClientSessionEvent.AUTHED - ) + setOf( + ClientSession.ClientSessionEvent.WAIT_AUTH, + ClientSession.ClientSessionEvent.CLOSED, + ClientSession.ClientSessionEvent.AUTHED + ) every { mockClientSession.createSubsystemChannel(any()) } returns mockSubsystem every { mockClientChannel.invertedOut } returns sampleInputStream diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt index ab762e821..abb3a8c4c 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt @@ -25,6 +25,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.Dev import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfReceivedEvent class NetconfSessionListenerImplTest { + // Note: mockk's verifyAll is akin to verify with verifyNoMoreInteractions in Mockito private val netconSession = mockk() 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 index 0d791c2a6..98d17e38b 100644 --- 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 @@ -27,10 +27,12 @@ class RpcMessageUtilsTest { @Test fun getConfig() { - val checkString = ("" + + val checkString = ( + "" + "" + "Test-Filter-Content" + - "") + "" + ) val messageId = "Test-Message-ID" val configType = NetconfDatastore.CANDIDATE.datastore @@ -45,10 +47,12 @@ class RpcMessageUtilsTest { @Test fun editConfig() { - val checkString = ("" + + val checkString = ( + "" + "" + "Test-Default-Operation" + - "Test-Filter-Content") + "Test-Filter-Content" + ) val messageId = "Test-Message-ID" val configType = NetconfDatastore.CANDIDATE.datastore @@ -64,9 +68,11 @@ class RpcMessageUtilsTest { @Test fun validate() { - val checkString = ("" + + val checkString = ( + "" + "" + - "") + "" + ) val messageId = "Test-Message-ID" val configType = NetconfDatastore.CANDIDATE.datastore @@ -80,11 +86,13 @@ class RpcMessageUtilsTest { @Test fun cancelCommit() { val checkString = - ("" + + ( + "" + "" + "" + "1234" + - "") + "" + ) val messageId = "Test-Message-ID" @@ -98,10 +106,12 @@ class RpcMessageUtilsTest { @Test fun cancelCommitNoPersistId() { val checkString = - ("" + + ( + "" + "" + "" + - "") + "" + ) val messageId = "Test-Message-ID" @@ -113,9 +123,11 @@ class RpcMessageUtilsTest { @Test fun commit() { - val checkString = ("" + + val checkString = ( + "" + "" + - "") + "" + ) val messageId = "Test-Message-ID" @@ -132,11 +144,13 @@ class RpcMessageUtilsTest { @Test fun commitPersistId() { val checkString = - ("" + + ( + "" + "" + "" + "1234" + - "") + "" + ) val messageId = "Test-Message-ID" @@ -160,13 +174,15 @@ class RpcMessageUtilsTest { @Test fun commitPersist() { val checkString = - ("" + + ( + "" + "" + "" + "" + "30" + "1234" + - "") + "" + ) val messageId = "Test-Message-ID" @@ -189,9 +205,11 @@ class RpcMessageUtilsTest { @Test fun unlock() { - val checkString = ("" + + val checkString = ( + "" + "" + - "") + "" + ) val messageId = "Test-Message-ID" val configType = NetconfDatastore.CANDIDATE.datastore @@ -204,9 +222,11 @@ class RpcMessageUtilsTest { @Test fun deleteConfig() { - val checkString = ("" + + val checkString = ( + "" + "" + - "") + "" + ) val messageId = "Test-Message-ID" val netconfTargetConfig = NetconfDatastore.CANDIDATE.datastore @@ -228,9 +248,11 @@ class RpcMessageUtilsTest { @Test fun discardChanges() { - val checkString = ("" + + val checkString = ( + "" + "" + - "") + "" + ) val messageId = "Test-Message-ID" @@ -242,9 +264,11 @@ class RpcMessageUtilsTest { @Test fun lock() { - val checkString = ("" + + val checkString = ( + "" + "" + - "") + "" + ) val messageId = "Test-Message-ID" val configType = NetconfDatastore.CANDIDATE.datastore @@ -273,8 +297,10 @@ class RpcMessageUtilsTest { @Test fun createHelloString() { - val checkString = (" " + - " hi hello ]]>]]>") + val checkString = ( + " " + + " hi hello ]]>]]>" + ) val capability = listOf("hi", "hello") @@ -306,12 +332,16 @@ class RpcMessageUtilsTest { @Test fun formatRPCRequest() { - val checkString = ("#199" + + val checkString = ( + "#199" + " hi hello " + - "##") + "##" + ) - val request = (" " + - " hi hello ]]>]]>") + val request = ( + " " + + " hi hello ]]>]]>" + ) val messageId = "Test-Message-ID" -- cgit 1.2.3-korg