summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/netconf-executor/src
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2019-11-22 18:06:08 -0500
committerKAPIL SINGAL <ks220y@att.com>2019-11-26 21:32:38 +0000
commit341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch)
tree113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/blueprintsprocessor/functions/netconf-executor/src
parentd274e5fc552cf9ae25500f504f0434981cf3accf (diff)
Formatting Code base with ktlint
No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com> Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src')
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt16
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt4
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt60
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfDevice.kt2
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt2
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorExtensions.kt11
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfo.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt23
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt17
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicator.kt88
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt17
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImpl.kt77
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt3
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtils.kt83
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt27
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/DeviceInfoTest.kt17
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessageTest.kt7
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicatorTest.kt117
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfMessageStateTest.kt149
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImplTest.kt17
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImplTest.kt144
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt26
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt28
-rw-r--r--ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/RpcMessageUtilsTest.kt131
26 files changed, 636 insertions, 439 deletions
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 cdee3903b..1262e8500 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
@@ -31,8 +31,8 @@ import org.springframework.stereotype.Component
@Component("component-netconf-executor")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
- : AbstractComponentFunction() {
+open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
+ AbstractComponentFunction() {
companion object {
const val SCRIPT_TYPE = "script-type"
@@ -56,9 +56,10 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic
}
scriptComponent = componentFunctionScriptingService
- .scriptInstance<AbstractScriptComponentFunction>(this, scriptType,
- scriptClassReference, scriptDependencies)
-
+ .scriptInstance<AbstractScriptComponentFunction>(
+ this, scriptType,
+ scriptClassReference, scriptDependencies
+ )
checkNotNull(scriptComponent) { "failed to get netconf script component" }
@@ -68,7 +69,6 @@ open class ComponentNetconfExecutor(private var componentFunctionScriptingServic
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
bluePrintRuntimeService.getBluePrintError()
- .addError("Failed in ComponentNetconfExecutor : ${runtimeException.message}")
-
+ .addError("Failed in ComponentNetconfExecutor : ${runtimeException.message}")
}
-} \ No newline at end of file
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
index 73c82acb2..abaa7fed1 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/JsonParserService.kt
@@ -19,6 +19,4 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
import org.springframework.stereotype.Service
@Service("json-parser-service")
-class JsonParserService {
-
-} \ No newline at end of file
+class JsonParserService
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
index 5e0b4a117..58e6151f0 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
@@ -25,40 +25,62 @@ import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptC
@Deprecated("Methods defined as extension function of AbstractComponentFunction")
abstract class NetconfComponentFunction : AbstractScriptComponentFunction() {
- @Deprecated(" Use resourceResolutionService method directly",
- replaceWith = ReplaceWith("resourceResolutionService()",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceResolutionService"))
+ @Deprecated(
+ " Use resourceResolutionService method directly",
+ replaceWith = ReplaceWith(
+ "resourceResolutionService()",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceResolutionService"
+ )
+ )
open fun resourceResolutionService(): ResourceResolutionService =
- functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+ functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
// Called from python script
- @Deprecated(" Use netconfDeviceInfo method directly",
- replaceWith = ReplaceWith("netconfDeviceInfo(requirementName)",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo"))
+ @Deprecated(
+ " Use netconfDeviceInfo method directly",
+ replaceWith = ReplaceWith(
+ "netconfDeviceInfo(requirementName)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.netconfDeviceInfo"
+ )
+ )
fun initializeNetconfConnection(requirementName: String): NetconfDevice {
val deviceInfo = netconfDeviceInfo(requirementName)
return NetconfDevice(deviceInfo)
}
- @Deprecated(" Use artifactContent method directly",
- replaceWith = ReplaceWith("artifactContent(artifactName)",
- "org.onap.ccsdk.cds.blueprintsprocessor.services.execution.artifactContent"))
+ @Deprecated(
+ " Use artifactContent method directly",
+ replaceWith = ReplaceWith(
+ "artifactContent(artifactName)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.services.execution.artifactContent"
+ )
+ )
fun generateMessage(artifactName: String): String {
return bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName)
}
- @Deprecated(" Use storedContentFromResolvedArtifact method directly",
- replaceWith = ReplaceWith("storedContentFromResolvedArtifact(resolutionKey, artifactName)",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifact"))
+ @Deprecated(
+ " Use storedContentFromResolvedArtifact method directly",
+ replaceWith = ReplaceWith(
+ "storedContentFromResolvedArtifact(resolutionKey, artifactName)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.storedContentFromResolvedArtifact"
+ )
+ )
fun resolveFromDatabase(resolutionKey: String, artifactName: String): String = runBlocking {
resourceResolutionService().resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey)
}
- @Deprecated(" Use contentFromResolvedArtifact method directly",
- replaceWith = ReplaceWith("resolveAndGenerateMessage(artifactPrefix)",
- "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resolveAndGenerateMessage"))
+ @Deprecated(
+ " Use contentFromResolvedArtifact method directly",
+ replaceWith = ReplaceWith(
+ "resolveAndGenerateMessage(artifactPrefix)",
+ "org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resolveAndGenerateMessage"
+ )
+ )
fun resolveAndGenerateMessage(artifactPrefix: String): String = runBlocking {
- resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
- artifactPrefix, mapOf())
+ resourceResolutionService().resolveResources(
+ bluePrintRuntimeService, nodeTemplateName,
+ artifactPrefix, mapOf()
+ )
}
-} \ No newline at end of file
+}
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 61090f485..a69e4d9d6 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
@@ -28,4 +28,4 @@ data class NetconfDevice(val deviceInfo: DeviceInfo) {
netconfSession = NetconfSessionImpl(deviceInfo, netconfRpcService)
netconfRpcService.setNetconfSession(netconfSession)
}
-} \ No newline at end of file
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt
index 214969346..f9aa38f8c 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/NetconfExecutorConfiguration.kt
@@ -25,4 +25,4 @@ import org.springframework.context.annotation.Configuration
@ComponentScan
@EnableConfigurationProperties
@ConditionalOnProperty(name = ["blueprintsprocessor.netconfExecutor.enabled"], havingValue = "true")
-open class NetconfExecutorConfiguration \ No newline at end of file
+open class NetconfExecutorConfiguration
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 510621b2e..f52cb0a62 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
@@ -29,8 +29,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
* Register the Netconf module exposed dependency
*/
fun BluePrintDependencyService.netconfClientService(): ResourceResolutionService =
- instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
-
+ instance(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
fun AbstractComponentFunction.netconfDevice(requirementName: String): NetconfDevice {
val deviceInfo = netconfDeviceInfo(requirementName)
@@ -43,8 +42,10 @@ fun AbstractComponentFunction.netconfDeviceInfo(requirementName: String): Device
val requirement = blueprintContext.nodeTemplateRequirement(nodeTemplateName, requirementName)
- val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(requirement
- .node!!, requirement.capability!!)
+ val capabilityProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(
+ requirement
+ .node!!, requirement.capability!!
+ )
return netconfDeviceInfo(capabilityProperties)
}
@@ -55,4 +56,4 @@ private fun AbstractComponentFunction.netconfDeviceInfo(capabilityProperty: Muta
/**
* Blocking Methods called from Jython Scripts
- */ \ No newline at end of file
+ */
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 2395dddb8..2f10bb56b 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
@@ -40,7 +40,8 @@ class DeviceInfo {
override fun toString(): String {
return "$ipAddress:$port"
}
- //TODO: should this be a data class instead? Is anything using the JSON serdes?
+
+ // TODO: should this be a data class instead? Is anything using the JSON serdes?
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
index 7e6a88b48..62a6ac3e3 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfException.kt
@@ -20,5 +20,4 @@ class NetconfException : Exception {
constructor(cause: Throwable) : super(cause)
constructor(message: String) : super(message)
constructor(message: String, cause: Throwable) : super(message, cause)
-
-} \ No newline at end of file
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
index 1d5f515d0..744476c2a 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessage.kt
@@ -18,17 +18,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
-data class DeviceResponse(var status: String? = null,
- var errorMessage: String? = null,
- var responseMessage: String? = null,
- var requestMessage: String? = null) {
+data class DeviceResponse(
+ var status: String? = null,
+ var errorMessage: String? = null,
+ var responseMessage: String? = null,
+ var requestMessage: String? = null
+) {
fun isSuccess(): Boolean {
return this.status == RpcStatus.SUCCESS && this.errorMessage.isNullOrEmpty()
}
}
-
/**
* Creates an event of a given type and for the specified subject and the current time.
*
@@ -37,10 +38,12 @@ data class DeviceResponse(var status: String? = null,
* @param messageId id of the message related to the event
* @param deviceInfo device of event
*/
-class NetconfReceivedEvent(val type: Type,
- val messagePayload: String = "",
- val messageId: String = "",
- val deviceInfo: DeviceInfo) {
+class NetconfReceivedEvent(
+ val type: Type,
+ val messagePayload: String = "",
+ val messageId: String = "",
+ val deviceInfo: DeviceInfo
+) {
enum class Type {
DEVICE_REPLY,
@@ -48,4 +51,4 @@ class NetconfReceivedEvent(val type: Type,
DEVICE_ERROR,
SESSION_CLOSED
}
-} \ No newline at end of file
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
index ecb6267f5..ea93ebd40 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfRpcService.kt
@@ -54,8 +54,11 @@ interface NetconfRpcService {
* @param editDefaultOperation, default set to none. Valid values: merge, replace, create, delete, none
* @return Device response
*/
- fun editConfig(messageContent: String, configTarget: String = NetconfDatastore.CANDIDATE.datastore,
- editDefaultOperation: String = ModifyAction.NONE.action): DeviceResponse
+ fun editConfig(
+ messageContent: String,
+ configTarget: String = NetconfDatastore.CANDIDATE.datastore,
+ editDefaultOperation: String = ModifyAction.NONE.action
+ ): DeviceResponse
/**
* Invoke custom RPC as provided as input.
@@ -96,8 +99,12 @@ interface NetconfRpcService {
* If unspecified, the confirm timeout defaults to 600 seconds.
* @return Device response
*/
- fun commit(confirmed: Boolean = false, confirmTimeout: Int = 60, persist: String = "",
- persistId: String = ""): DeviceResponse
+ fun commit(
+ confirmed: Boolean = false,
+ confirmTimeout: Int = 60,
+ persist: String = "",
+ persistId: String = ""
+ ): DeviceResponse
/**
* Cancels an ongoing confirmed commit. If the <persist-id> parameter is not given,
@@ -148,4 +155,4 @@ interface NetconfRpcService {
* @return Device response
*/
fun get(filter: String): DeviceResponse
-} \ No newline at end of file
+}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
index 0272d1a19..ceeb444f7 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfSession.kt
@@ -25,7 +25,6 @@ interface NetconfSession {
*/
fun connect()
-
/**
* Disconnect netconf session
*/
@@ -83,4 +82,4 @@ interface NetconfSession {
* @return Network capabilities as strings in a Set.
*/
fun getDeviceCapabilitiesSet(): Set<String>
-} \ No newline at end of file
+}
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 06a71cad3..8f8fc1463 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
@@ -22,15 +22,26 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.Net
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils
import org.slf4j.LoggerFactory
-import java.io.*
-import java.nio.charset.*
-import java.util.concurrent.*
+import java.io.BufferedReader
+import java.io.IOException
+import java.io.InputStream
+import java.io.InputStreamReader
+import java.io.OutputStream
+import java.io.OutputStreamWriter
+import java.nio.charset.StandardCharsets
+import java.util.concurrent.CancellationException
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.ExecutionException
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.TimeoutException
-class NetconfDeviceCommunicator(private var inputStream: InputStream,
- private var out: OutputStream,
- private val deviceInfo: DeviceInfo,
- private val sessionListener: NetconfSessionListener,
- private var replies: MutableMap<String, CompletableFuture<String>>) : Thread() {
+class NetconfDeviceCommunicator(
+ private var inputStream: InputStream,
+ private var out: OutputStream,
+ private val deviceInfo: DeviceInfo,
+ private val sessionListener: NetconfSessionListener,
+ private var replies: MutableMap<String, CompletableFuture<String>>
+) : Thread() {
private val log = LoggerFactory.getLogger(NetconfDeviceCommunicator::class.java)
private var state = NetconfMessageState.NO_MATCHING_PATTERN
@@ -62,9 +73,12 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
if (deviceReply == RpcMessageUtils.END_PATTERN) {
socketClosed = true
bufferReader.close()
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_UNREGISTERED,
- deviceInfo = deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_UNREGISTERED,
+ deviceInfo = deviceInfo
+ )
+ )
} else {
deviceReply = deviceReply.replace(RpcMessageUtils.END_PATTERN, "")
receivedMessage(deviceReply)
@@ -75,9 +89,12 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
if (!NetconfMessageUtils.validateChunkedFraming(deviceReply)) {
log.debug("$deviceInfo: Received badly framed message $deviceReply")
socketClosed = true
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_ERROR,
- deviceInfo = deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_ERROR,
+ deviceInfo = deviceInfo
+ )
+ )
} else {
deviceReply = deviceReply.replace(RpcMessageUtils.MSGLEN_REGEX_PATTERN.toRegex(), "")
deviceReply = deviceReply.replace(NetconfMessageUtils.CHUNKED_END_REGEX_PATTERN.toRegex(), "")
@@ -86,20 +103,22 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
}
}
}
-
} catch (e: IOException) {
log.warn("$deviceInfo: Fail while reading from channel", e)
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_ERROR,
- deviceInfo = deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_ERROR,
+ deviceInfo = deviceInfo
+ )
+ )
}
-
}
/**
* State machine for the Netconf message parser
*/
internal enum class NetconfMessageState {
+
NO_MATCHING_PATTERN {
override fun evaluateChar(c: Char): NetconfMessageState {
return when (c) {
@@ -207,25 +226,29 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
log.error("$deviceInfo: Failed to send message : \n $request", e)
future.completeExceptionally(e)
}
-
}
return future
}
private fun receivedMessage(deviceReply: String) {
- if (deviceReply.contains(RpcMessageUtils.RPC_REPLY) || deviceReply.contains(RpcMessageUtils.RPC_ERROR)
- || deviceReply.contains(RpcMessageUtils.HELLO)) {
- log.info("$deviceInfo: Received message with messageId: {} \n $deviceReply",
- NetconfMessageUtils.getMsgId(deviceReply))
-
+ if (deviceReply.contains(RpcMessageUtils.RPC_REPLY) || deviceReply.contains(RpcMessageUtils.RPC_ERROR) ||
+ deviceReply.contains(RpcMessageUtils.HELLO)
+ ) {
+ log.info(
+ "$deviceInfo: Received message with messageId: {} \n $deviceReply",
+ NetconfMessageUtils.getMsgId(deviceReply)
+ )
} else {
log.error("$deviceInfo: Invalid message received: \n $deviceReply")
}
- sessionListener.accept(NetconfReceivedEvent(
- NetconfReceivedEvent.Type.DEVICE_REPLY,
- deviceReply,
- NetconfMessageUtils.getMsgId(deviceReply),
- deviceInfo))
+ sessionListener.accept(
+ NetconfReceivedEvent(
+ NetconfReceivedEvent.Type.DEVICE_REPLY,
+ deviceReply,
+ NetconfMessageUtils.getMsgId(deviceReply),
+ deviceInfo
+ )
+ )
}
/**
@@ -241,7 +264,10 @@ class NetconfDeviceCommunicator(private var inputStream: InputStream,
* @throws TimeoutException if the wait timed outStream
*/
internal fun getFutureFromSendMessage(
- fut: CompletableFuture<String>, timeout: Long, timeUnit: TimeUnit): String {
+ fut: CompletableFuture<String>,
+ timeout: Long,
+ timeUnit: TimeUnit
+ ): String {
return fut.get(timeout, timeUnit)
}
}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt
index 2e33b9aa2..b9fab06b1 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt
@@ -17,7 +17,11 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.*
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceResponse
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfRpcService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
import org.slf4j.LoggerFactory
@@ -58,7 +62,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ
override fun invokeRpc(rpc: String): DeviceResponse {
var output = DeviceResponse()
- //Attempt to extract the message-id field from the <rpc call
+ // Attempt to extract the message-id field from the <rpc call
val updatedMessageId = messageIdInteger.getAndIncrement().toString()
val origMessageId = NetconfMessageUtils.getMsgId(rpc)
log.info("$deviceInfo: invokeRpc: updating rpc original message-id:($origMessageId) to messageId($updatedMessageId)")
@@ -197,8 +201,11 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ
return output
}
- override fun editConfig(messageContent: String, configTarget: String,
- editDefaultOperation: String): DeviceResponse {
+ override fun editConfig(
+ messageContent: String,
+ configTarget: String,
+ editDefaultOperation: String
+ ): DeviceResponse {
var response = DeviceResponse()
val messageId = messageIdInteger.getAndIncrement().toString()
log.info("$deviceInfo: editConfig: messageId($messageId)")
@@ -252,7 +259,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ
response.requestMessage = request
val rpcResponse = netconfSession.asyncRpc(request, messageId).get(responseTimeout.toLong(), TimeUnit.SECONDS)
- //TODO catch TimeoutException and ExecutionException
+ // TODO catch TimeoutException and ExecutionException
if (!NetconfMessageUtils.checkReply(rpcResponse)) {
log.error("RPC response didn't pass validation... $rpcResponse")
throw NetconfException(rpcResponse)
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 6be93179f..3d3eee8f0 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
@@ -22,14 +22,22 @@ import org.apache.sshd.client.SshClient
import org.apache.sshd.client.channel.ClientChannel
import org.apache.sshd.client.session.ClientSession
import org.apache.sshd.common.FactoryManager
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.*
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfRpcService
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSession
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfSessionListener
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcMessageUtils
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
import org.slf4j.LoggerFactory
import java.io.IOException
-import java.util.*
-import java.util.concurrent.*
+import java.util.Collections
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.ConcurrentHashMap
+import java.util.concurrent.ExecutionException
+import java.util.concurrent.TimeUnit
+import java.util.concurrent.TimeoutException
class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcService: NetconfRpcService) :
NetconfSession {
@@ -55,8 +63,10 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
override fun connect() {
try {
- log.info("$deviceInfo: Connecting to Netconf Device with timeouts C:${deviceInfo.connectTimeout}, " +
- "R:${deviceInfo.replyTimeout}, I:${deviceInfo.idleTimeout}")
+ log.info(
+ "$deviceInfo: Connecting to Netconf Device with timeouts C:${deviceInfo.connectTimeout}, " +
+ "R:${deviceInfo.replyTimeout}, I:${deviceInfo.idleTimeout}"
+ )
startConnection()
log.info("$deviceInfo: Connected to Netconf Device")
} catch (e: NetconfException) {
@@ -67,13 +77,14 @@ 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) {
+ while (rpcService.closeSession(false).status
+ .equals(RpcStatus.FAILURE, true) && retryNum > 0
+ ) {
log.error("disconnect: graceful disconnect failed, retrying $retryNum times...")
- retryNum--;
+ retryNum--
}
- //if we can't close the session, try to force terminate.
- if(retryNum == 0) {
+ // if we can't close the session, try to force terminate.
+ if (retryNum == 0) {
log.error("disconnect: trying to force-terminate the session.")
rpcService.closeSession(true)
}
@@ -95,13 +106,17 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
checkAndReestablish()
try {
- return streamHandler.getFutureFromSendMessage(streamHandler.sendMessage(formattedRequest, messageId),
- replyTimeout.toLong(), TimeUnit.SECONDS)
+ return streamHandler.getFutureFromSendMessage(
+ streamHandler.sendMessage(formattedRequest, messageId),
+ replyTimeout.toLong(), TimeUnit.SECONDS
+ )
} catch (e: InterruptedException) {
throw NetconfException("$deviceInfo: Interrupted while waiting for reply for request: $formattedRequest", e)
} catch (e: TimeoutException) {
- throw NetconfException("$deviceInfo: Timed out while waiting for reply for request $formattedRequest after $replyTimeout sec.",
- e)
+ throw NetconfException(
+ "$deviceInfo: Timed out while waiting for reply for request $formattedRequest after $replyTimeout sec.",
+ e
+ )
} catch (e: ExecutionException) {
log.warn("$deviceInfo: Closing session($sessionId) due to unexpected Error", e)
try {
@@ -179,10 +194,9 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
} catch (e: Exception) {
throw NetconfException("$deviceInfo: Failed to establish SSH session", e)
}
-
}
- //Needed to unit test connect method interacting with client.start in startClient() below
+ // Needed to unit test connect method interacting with client.start in startClient() below
private fun setupNewSSHClient() {
client = SshClient.setUpDefaultClient()
}
@@ -210,8 +224,12 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
private fun authSession() {
session.addPasswordIdentity(deviceInfo.password)
session.auth().verify(connectionTimeout, TimeUnit.SECONDS)
- val event = session.waitFor(ImmutableSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH,
- ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED), 0)
+ val event = session.waitFor(
+ ImmutableSet.of(
+ ClientSession.ClientSessionEvent.WAIT_AUTH,
+ ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED
+ ), 0
+ )
if (!event.contains(ClientSession.ClientSessionEvent.AUTHED)) {
throw NetconfException("$deviceInfo: Failed to authenticate session.")
}
@@ -233,8 +251,10 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
private fun setupHandler() {
val sessionListener: NetconfSessionListener = NetconfSessionListenerImpl(this)
- streamHandler = NetconfDeviceCommunicator(channel.invertedOut, channel.invertedIn, deviceInfo,
- sessionListener, replies)
+ streamHandler = NetconfDeviceCommunicator(
+ channel.invertedOut, channel.invertedIn, deviceInfo,
+ sessionListener, replies
+ )
exchangeHelloMessage()
}
@@ -254,7 +274,7 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
}
val capabilityMatcher = NetconfMessageUtils.CAPABILITY_REGEX_PATTERN.matcher(serverHelloResponse)
- while (capabilityMatcher.find()) { //TODO: refactor to add unit test easily for device capability accumulation.
+ while (capabilityMatcher.find()) { // TODO: refactor to add unit test easily for device capability accumulation.
deviceCapabilities.add(capabilityMatcher.group(1))
}
}
@@ -300,9 +320,18 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ
* internal function for accessing errorReplies for testing.
*/
internal fun getErrorReplies() = errorReplies
+
internal fun clearErrorReplies() = errorReplies.clear()
internal fun clearReplies() = replies.clear()
- internal fun setClient(client: SshClient) { this.client = client }
- internal fun setSession(session: ClientSession) { this.session = session }
- internal fun setChannel(channel: ClientChannel) { this.channel = channel }
+ internal fun setClient(client: SshClient) {
+ this.client = client
+ }
+
+ internal fun setSession(session: ClientSession) {
+ this.session = session
+ }
+
+ internal fun setChannel(channel: ClientChannel) {
+ this.channel = channel
+ }
}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt
index c8b9c5543..e27b51d16 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImpl.kt
@@ -28,6 +28,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.Net
*/
internal class NetconfSessionListenerImpl(private val session: NetconfSessionImpl) : NetconfSessionListener {
+
override fun accept(event: NetconfReceivedEvent) {
when (event.type) {
NetconfReceivedEvent.Type.DEVICE_UNREGISTERED -> session.disconnect()
@@ -36,4 +37,4 @@ internal class NetconfSessionListenerImpl(private val session: NetconfSessionImp
NetconfReceivedEvent.Type.DEVICE_REPLY -> session.addDeviceReply(event.messageId, event.messagePayload)
}
}
-} \ No newline at end of file
+}
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 34816b79b..232dca621 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
@@ -28,7 +28,6 @@ import javax.xml.XMLConstants
import javax.xml.parsers.DocumentBuilderFactory
import kotlin.text.Charsets.UTF_8
-
class NetconfMessageUtils {
companion object {
@@ -91,8 +90,12 @@ class NetconfMessageUtils {
return rpc.toString()
}
- fun editConfig(messageId: String, configType: String, defaultOperation: String?,
- newConfiguration: String): String {
+ fun editConfig(
+ messageId: String,
+ configType: String,
+ defaultOperation: String?,
+ newConfiguration: String
+ ): String {
val request = StringBuilder()
request.append("<edit-config>").append(NEW_LINE)
request.append(RpcMessageUtils.TARGET_OPEN).append(NEW_LINE)
@@ -127,16 +130,25 @@ class NetconfMessageUtils {
return doWrappedRpc(messageId, request.toString())
}
- fun commit(messageId: String, confirmed: Boolean, confirmTimeout: Int, persist: String,
- persistId: String): String {
+ fun commit(
+ messageId: String,
+ confirmed: Boolean,
+ confirmTimeout: Int,
+ persist: String,
+ persistId: String
+ ): String {
if (!persist.isEmpty() && !persistId.isEmpty()) {
- throw NetconfException("Can't proceed <commit> with both persist($persist) and " +
- "persistId($persistId) specified. Only one should be specified.")
+ throw NetconfException(
+ "Can't proceed <commit> with both persist($persist) and " +
+ "persistId($persistId) specified. Only one should be specified."
+ )
}
if (confirmed && !persistId.isEmpty()) {
- throw NetconfException("Can't proceed <commit> with both confirmed flag and " +
- "persistId($persistId) specified. Only one should be specified.")
+ throw NetconfException(
+ "Can't proceed <commit> with both confirmed flag and " +
+ "persistId($persistId) specified. Only one should be specified."
+ )
}
val request = StringBuilder()
@@ -221,15 +233,15 @@ class NetconfMessageUtils {
fun closeSession(messageId: String, force: Boolean): String {
val request = StringBuilder()
- //TODO: kill-session without session-id is a cisco-only variant.
- //will fail on JUNIPER device.
- //netconf RFC for kill-session requires session-id
- //Cisco can accept <kill-session/> for current session
- //or <kill-session><session-id>####</session-id></kill-session>
- //as long as session ID is not the same as the current session.
-
- //Juniperhttps://www.juniper.net/documentation/en_US/junos/topics/task/operational/netconf-session-terminating.html
- //will accept only with session-id
+ // TODO: kill-session without session-id is a cisco-only variant.
+ // will fail on JUNIPER device.
+ // netconf RFC for kill-session requires session-id
+ // Cisco can accept <kill-session/> for current session
+ // or <kill-session><session-id>####</session-id></kill-session>
+ // as long as session ID is not the same as the current session.
+
+ // Juniperhttps://www.juniper.net/documentation/en_US/junos/topics/task/operational/netconf-session-terminating.html
+ // will accept only with session-id
if (force) {
request.append("<kill-session/>")
} else {
@@ -254,7 +266,6 @@ class NetconfMessageUtils {
} catch (e: Exception) {
return false
}
-
}
fun getMsgId(message: String): String {
@@ -355,8 +366,8 @@ 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
}
@@ -373,7 +384,8 @@ class NetconfMessageUtils {
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].length
+ )
} else {
request = RpcMessageUtils.XML_HEADER + "\n" + request
}
@@ -385,12 +397,18 @@ class NetconfMessageUtils {
var request = request
if (request.contains(RpcMessageUtils.MESSAGE_ID_STRING)) {
request =
- request.replaceFirst((RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.NUMBER_BETWEEN_QUOTES_MATCHER).toRegex(),
- RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE)
+ request.replaceFirst(
+ (RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.NUMBER_BETWEEN_QUOTES_MATCHER).toRegex(),
+ RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE
+ )
} else if (!request.contains(RpcMessageUtils.MESSAGE_ID_STRING) && !request.contains(
- RpcMessageUtils.HELLO)) {
- request = request.replaceFirst(RpcMessageUtils.END_OF_RPC_OPEN_TAG.toRegex(),
- RpcMessageUtils.QUOTE_SPACE + RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE + ">")
+ RpcMessageUtils.HELLO
+ )
+ ) {
+ request = request.replaceFirst(
+ RpcMessageUtils.END_OF_RPC_OPEN_TAG.toRegex(),
+ RpcMessageUtils.QUOTE_SPACE + RpcMessageUtils.MESSAGE_ID_STRING + RpcMessageUtils.EQUAL + RpcMessageUtils.QUOTE + messageId + RpcMessageUtils.QUOTE + ">"
+ )
}
return updateRequestLength(request)
}
@@ -398,12 +416,16 @@ class NetconfMessageUtils {
fun updateRequestLength(request: String): String {
if (request.contains(NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE)) {
val oldLen =
- Integer.parseInt(request.split(RpcMessageUtils.HASH.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
- NEW_LINE.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[0])
+ Integer.parseInt(
+ request.split(RpcMessageUtils.HASH.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
+ NEW_LINE.toRegex()
+ ).dropLastWhile({ it.isEmpty() }).toTypedArray()[0]
+ )
val rpcWithEnding = request.substring(request.indexOf('<'))
val firstBlock =
request.split(RpcMessageUtils.MSGLEN_REGEX_PATTERN.toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()[1].split(
- (NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE).toRegex()).dropLastWhile(
+ (NEW_LINE + RpcMessageUtils.HASH + RpcMessageUtils.HASH + NEW_LINE).toRegex()
+ ).dropLastWhile(
{ it.isEmpty() }).toTypedArray()[0]
var newLen = 0
newLen = firstBlock.toByteArray(UTF_8).size
@@ -420,5 +442,4 @@ class NetconfMessageUtils {
} else false
}
}
-
}
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
index be3ee4614..f3df55b4b 100644
--- 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
@@ -54,16 +54,22 @@ class ComponentNetconfExecutorTest {
coEvery { blueprintJythonService.jythonComponentInstance(any(), any()) } returns mockAbstractScriptComponentFunction
- val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext,
- blueprintJythonService)
+ val componentFunctionScriptingService = ComponentFunctionScriptingService(
+ applicationContext,
+ blueprintJythonService
+ )
val componentNetconfExecutor = ComponentNetconfExecutor(componentFunctionScriptingService)
- val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json",
- ExecutionServiceInput::class.java)!!
+ 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 bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
+ "1234",
+ "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+ )
val assignmentParams = """{
"ipAddress" : "127.0.0.1",
@@ -77,12 +83,14 @@ class ComponentNetconfExecutorTest {
""".trimIndent()
bluePrintRuntimeService.assignInputs(json.asJsonType())
- bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
- JacksonUtils.jsonNode(assignmentParams))
+ bluePrintRuntimeService.setNodeTemplateAttributeValue(
+ "resource-assignment", "assignment-params",
+ JacksonUtils.jsonNode(assignmentParams)
+ )
componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
- //TODO("Set Attribute properties")
+ // TODO("Set Attribute properties")
val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf")
stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor")
@@ -98,4 +106,3 @@ class ComponentNetconfExecutorTest {
}
}
}
-
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 4e1ff655d..ab051597b 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
@@ -16,7 +16,6 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api
-
import org.junit.Test
import kotlin.test.assertEquals
@@ -24,13 +23,13 @@ class DeviceInfoTest {
@Test
fun testToString() {
- val di: DeviceInfo = DeviceInfo().apply {
- username = "username"
- password = "password"
- ipAddress = "localhost"
- port = 2224
- connectTimeout = 10
- }
+ val di: DeviceInfo = DeviceInfo().apply {
+ username = "username"
+ password = "password"
+ ipAddress = "localhost"
+ port = 2224
+ connectTimeout = 10
+ }
assertEquals("localhost:2224", di.toString())
}
-} \ 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/api/NetconfMessageTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/api/NetconfMessageTest.kt
index 70bf0158d..e5bacc547 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
@@ -37,13 +37,13 @@ class NetconfMessageTest {
val dr: DeviceResponse = genUnsuccessfulEmptyDeviceResponse()
assertFalse(dr.isSuccess())
- //case 2: Success, but with error message
+ // case 2: Success, but with error message
val dr2: DeviceResponse = genUnsuccessfulEmptyDeviceResponse()
dr2.errorMessage = "Some error message."
assertFalse(dr2.isSuccess())
}
- //helper function to generate a device response
+ // helper function to generate a device response
private fun genSuccessfulEmptyDeviceResponse(): DeviceResponse {
return DeviceResponse().apply {
status = RpcStatus.SUCCESS
@@ -61,5 +61,4 @@ class NetconfMessageTest {
requestMessage = ""
}
}
-
-} \ 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/core/NetconfDeviceCommunicatorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfDeviceCommunicatorTest.kt
index 2240f48c2..1991fc4f6 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
@@ -16,7 +16,13 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core
-import io.mockk.*
+import io.mockk.CapturingSlot
+import io.mockk.Runs
+import io.mockk.every
+import io.mockk.just
+import io.mockk.mockk
+import io.mockk.spyk
+import io.mockk.verify
import org.junit.Before
import org.junit.Test
import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
@@ -27,9 +33,10 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.R
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
-import java.nio.charset.*
-import java.util.concurrent.*
-import java.util.regex.*
+import java.nio.charset.StandardCharsets
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.ConcurrentHashMap
+import java.util.regex.Pattern
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
@@ -43,10 +50,9 @@ class NetconfDeviceCommunicatorTest {
private lateinit var replies: MutableMap<String, CompletableFuture<String>>
private val endPatternCharArray: List<Int> = 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)
+ // using example from section 4.2 of RFC6242 (https://tools.ietf.org/html/rfc6242#section-4.2)
private val validChunkedEncodedMsg = """
|
|#4
@@ -82,25 +88,27 @@ class NetconfDeviceCommunicatorTest {
val communicator: NetconfDeviceCommunicator =
NetconfDeviceCommunicator(mockInputStream, mockOutputStream, genDeviceInfo(), netconfSessionListener, replies)
communicator.join()
- //verify
+ // verify
verify { mockInputStream.read(any(), any(), any()) }
}
@Test
fun `NetconfDeviceCommunicator unregisters device on END_PATTERN`() {
- //The reader will generate RpcMessageUtils.END_PATTERN "]]>]]>" which tells Netconf
- //to unregister the device.
- //we want to capture the slot to return the value as inputStreamReader will pass a char array
- //create a slot where NetconfReceivedEvent will be placed to further verify Type.DEVICE_UNREGISTERED
+ // The reader will generate RpcMessageUtils.END_PATTERN "]]>]]>" which tells Netconf
+ // to unregister the device.
+ // we want to capture the slot to return the value as inputStreamReader will pass a char array
+ // create a slot where NetconfReceivedEvent will be placed to further verify Type.DEVICE_UNREGISTERED
val eventSlot = CapturingSlot<NetconfReceivedEvent>()
every { netconfSessionListener.accept(event = capture(eventSlot)) } just Runs
stubInputStream = RpcMessageUtils.END_PATTERN.byteInputStream(StandardCharsets.UTF_8)
val inputStreamSpy = spyk(stubInputStream)
- //RUN the test
- val communicator = NetconfDeviceCommunicator(inputStreamSpy, mockOutputStream,
- genDeviceInfo(), netconfSessionListener, replies)
+ // RUN the test
+ val communicator = NetconfDeviceCommunicator(
+ inputStreamSpy, mockOutputStream,
+ genDeviceInfo(), netconfSessionListener, replies
+ )
communicator.join()
- //Verify
+ // Verify
verify { inputStreamSpy.close() }
assertTrue { eventSlot.isCaptured }
assertEquals(NetconfReceivedEvent.Type.DEVICE_UNREGISTERED, eventSlot.captured.type)
@@ -114,11 +122,13 @@ class NetconfDeviceCommunicatorTest {
stubInputStream = "".byteInputStream(StandardCharsets.UTF_8)
val inputStreamSpy = spyk(stubInputStream)
every { inputStreamSpy.read(any(), any(), any()) } returns 1 andThenThrows IOException("Fake IO Exception")
- //RUN THE TEST
- val communicator = NetconfDeviceCommunicator(inputStreamSpy, mockOutputStream,
- genDeviceInfo(), netconfSessionListener, replies)
+ // RUN THE TEST
+ val communicator = NetconfDeviceCommunicator(
+ inputStreamSpy, mockOutputStream,
+ genDeviceInfo(), netconfSessionListener, replies
+ )
communicator.join()
- //Verify
+ // Verify
assertTrue { eventSlot.isCaptured }
assertEquals(genDeviceInfo(), eventSlot.captured.deviceInfo)
assertEquals(NetconfReceivedEvent.Type.DEVICE_ERROR, eventSlot.captured.type)
@@ -130,14 +140,16 @@ class NetconfDeviceCommunicatorTest {
val payload = "<rpc-reply>blah</rpc-reply>"
stubInputStream = "$payload${RpcMessageUtils.END_PATTERN}".byteInputStream(StandardCharsets.UTF_8)
every { netconfSessionListener.accept(event = capture(eventSlot)) } just Runs
- //RUN the test
- val communicator = NetconfDeviceCommunicator(stubInputStream, mockOutputStream,
- genDeviceInfo(), netconfSessionListener, replies)
+ // RUN the test
+ val communicator = NetconfDeviceCommunicator(
+ stubInputStream, mockOutputStream,
+ genDeviceInfo(), netconfSessionListener, replies
+ )
communicator.join()
- //Verify
- verify(exactly = 0) { mockInputStream.close() } //make sure the reader is not closed as this could cause problems
+ // Verify
+ verify(exactly = 0) { mockInputStream.close() } // make sure the reader is not closed as this could cause problems
assertTrue { eventSlot.isCaptured }
- //eventually, sessionListener is called with message type DEVICE_REPLY
+ // eventually, sessionListener is called with message type DEVICE_REPLY
assertEquals(NetconfReceivedEvent.Type.DEVICE_REPLY, eventSlot.captured.type)
assertEquals(payload, eventSlot.captured.messagePayload)
}
@@ -150,16 +162,18 @@ class NetconfDeviceCommunicatorTest {
every { netconfSessionListener.accept(event = capture(eventSlot)) } just Runs
stubInputStream = payloadWithChunkedEnding.byteInputStream(StandardCharsets.UTF_8)
- //we have to ensure that the input stream is processed, so need to create a spy object.
+ // we have to ensure that the input stream is processed, so need to create a spy object.
val inputStreamSpy = spyk(stubInputStream)
- //RUN the test
- val communicator = NetconfDeviceCommunicator(inputStreamSpy, mockOutputStream, genDeviceInfo(),
- netconfSessionListener, replies)
+ // RUN the test
+ val communicator = NetconfDeviceCommunicator(
+ inputStreamSpy, mockOutputStream, genDeviceInfo(),
+ netconfSessionListener, replies
+ )
communicator.join()
- //Verify
- verify(exactly = 0) { inputStreamSpy.close() } //make sure the reader is not closed as this could cause problems
+ // Verify
+ verify(exactly = 0) { inputStreamSpy.close() } // make sure the reader is not closed as this could cause problems
assertTrue { eventSlot.isCaptured }
- //eventually, sessionListener is called with message type DEVICE_REPLY
+ // eventually, sessionListener is called with message type DEVICE_REPLY
assertEquals(NetconfReceivedEvent.Type.DEVICE_ERROR, eventSlot.captured.type)
assertEquals("", eventSlot.captured.messagePayload)
}
@@ -170,23 +184,25 @@ class NetconfDeviceCommunicatorTest {
stubInputStream = validChunkedEncodedMsg.byteInputStream(StandardCharsets.UTF_8)
val inputStreamSpy = spyk(stubInputStream)
every { netconfSessionListener.accept(event = capture(eventSlot)) } just Runs
- //RUN the test
+ // RUN the test
NetconfDeviceCommunicator(inputStreamSpy, mockOutputStream, genDeviceInfo(), netconfSessionListener, replies).join()
- //Verify
- verify(exactly = 0) { inputStreamSpy.close() } //make sure the reader is not closed as this could cause problems
+ // Verify
+ verify(exactly = 0) { inputStreamSpy.close() } // make sure the reader is not closed as this could cause problems
assertTrue { eventSlot.isCaptured }
- //eventually, sessionListener is called with message type DEVICE_REPLY
+ // eventually, sessionListener is called with message type DEVICE_REPLY
assertEquals(NetconfReceivedEvent.Type.DEVICE_REPLY, eventSlot.captured.type)
- assertEquals("""
+ assertEquals(
+ """
<rpc message-id="102"
xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<close-session/>
</rpc>
- """.trimIndent(), eventSlot.captured.messagePayload)
+ """.trimIndent(), eventSlot.captured.messagePayload
+ )
}
@Test
- //test to ensure that we have a valid test message to be then used in the case of chunked message
+ // test to ensure that we have a valid test message to be then used in the case of chunked message
// validation code path
fun `chunked sample is validated by the chunked response regex`() {
val test1 = "\n#10\nblah\n##\n"
@@ -196,7 +212,7 @@ class NetconfDeviceCommunicatorTest {
}
@Test
- //Verify that our test sample passes the second pattern for chunked size
+ // Verify that our test sample passes the second pattern for chunked size
fun `chunkSizeMatcher pattern finds matches in chunkedMessageSample`() {
val sizePattern = Pattern.compile("\\n#([1-9][0-9]*)\\n")
val matcher = sizePattern.matcher(validChunkedEncodedMsg)
@@ -207,17 +223,18 @@ class NetconfDeviceCommunicatorTest {
fun `sendMessage writes the request to NetconfDeviceCommunicator Writer`() {
val msgPayload = "some text"
val msgId = "100"
- stubInputStream = "".byteInputStream(StandardCharsets.UTF_8) //no data available in the stream...
+ stubInputStream = "".byteInputStream(StandardCharsets.UTF_8) // no data available in the stream...
every { mockOutputStream.write(any(), any(), any()) } just Runs
every { mockOutputStream.write(msgPayload.toByteArray(Charsets.UTF_8)) } just Runs
every { mockOutputStream.flush() } just Runs
- //Run the command
+ // Run the command
val communicator = NetconfDeviceCommunicator(
stubInputStream, mockOutputStream,
- genDeviceInfo(), netconfSessionListener, replies)
+ genDeviceInfo(), netconfSessionListener, replies
+ )
val completableFuture = communicator.sendMessage(msgPayload, msgId)
communicator.join()
- //verify
+ // verify
verify { mockOutputStream.write(any(), any(), any()) }
verify { mockOutputStream.flush() }
assertFalse { completableFuture.isCompletedExceptionally }
@@ -227,14 +244,15 @@ class NetconfDeviceCommunicatorTest {
fun `sendMessage on IOError returns completed exceptionally future`() {
val msgPayload = "some text"
val msgId = "100"
- every { mockOutputStream.write(any(), any(), any()) } throws IOException("Some IO error occurred!")
- stubInputStream = "".byteInputStream(StandardCharsets.UTF_8) //no data available in the stream...
- //Run the command
+ every { mockOutputStream.write(any(), any(), any()) } throws IOException("Some IO error occurred!")
+ stubInputStream = "".byteInputStream(StandardCharsets.UTF_8) // no data available in the stream...
+ // Run the command
val communicator = NetconfDeviceCommunicator(
stubInputStream, mockOutputStream,
- genDeviceInfo(), netconfSessionListener, replies)
+ genDeviceInfo(), netconfSessionListener, replies
+ )
val completableFuture = communicator.sendMessage(msgPayload, msgId)
- //verify
+ // verify
verify { mockOutputStream.write(any(), any(), any()) }
verify(exactly = 0) { mockOutputStream.flush() }
assertTrue { completableFuture.isCompletedExceptionally }
@@ -248,5 +266,4 @@ class NetconfDeviceCommunicatorTest {
port = 4567
}
}
-
}
diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfMessageStateTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfMessageStateTest.kt
index ce7594c4a..e68e5d865 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfMessageStateTest.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfMessageStateTest.kt
@@ -27,121 +27,166 @@ class NetconfMessageStateTest {
@Test
fun `NO_MATCHING_PATTERN transitions`() {
- assertEquals(NetconfMessageState.FIRST_BRACKET,
- NetconfMessageState.NO_MATCHING_PATTERN.evaluateChar(']'))
- assertEquals(NetconfMessageState.FIRST_LF,
- NetconfMessageState.NO_MATCHING_PATTERN.evaluateChar('\n'))
-
- charList.minus(listOf(']','\n')).forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.NO_MATCHING_PATTERN.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.FIRST_BRACKET,
+ NetconfMessageState.NO_MATCHING_PATTERN.evaluateChar(']')
+ )
+ assertEquals(
+ NetconfMessageState.FIRST_LF,
+ NetconfMessageState.NO_MATCHING_PATTERN.evaluateChar('\n')
+ )
+
+ charList.minus(listOf(']', '\n')).forEach {
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.NO_MATCHING_PATTERN.evaluateChar(it)
+ )
}
}
@Test
fun `FIRST_BRACKET transitions`() {
- assertEquals(NetconfMessageState.SECOND_BRACKET,
- NetconfMessageState.FIRST_BRACKET.evaluateChar(']'))
+ assertEquals(
+ NetconfMessageState.SECOND_BRACKET,
+ NetconfMessageState.FIRST_BRACKET.evaluateChar(']')
+ )
- charList.minus( ']').forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.FIRST_BRACKET.evaluateChar(it))
+ charList.minus(']').forEach {
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.FIRST_BRACKET.evaluateChar(it)
+ )
}
}
@Test
fun `SECOND_BRACKET transitions`() {
- assertEquals(NetconfMessageState.FIRST_BIGGER,
- NetconfMessageState.SECOND_BRACKET.evaluateChar('>'))
+ assertEquals(
+ NetconfMessageState.FIRST_BIGGER,
+ NetconfMessageState.SECOND_BRACKET.evaluateChar('>')
+ )
charList.minus('>').forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.SECOND_BRACKET.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.SECOND_BRACKET.evaluateChar(it)
+ )
}
}
@Test
fun `FIRST_BIGGER transitions`() {
- assertEquals(NetconfMessageState.THIRD_BRACKET,
- NetconfMessageState.FIRST_BIGGER.evaluateChar(']'))
+ assertEquals(
+ NetconfMessageState.THIRD_BRACKET,
+ NetconfMessageState.FIRST_BIGGER.evaluateChar(']')
+ )
charList.minus(']').forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.FIRST_BIGGER.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.FIRST_BIGGER.evaluateChar(it)
+ )
}
}
@Test
fun `THIRD_BRACKET transitions`() {
- assertEquals(NetconfMessageState.ENDING_BIGGER,
- NetconfMessageState.THIRD_BRACKET.evaluateChar(']'))
+ assertEquals(
+ NetconfMessageState.ENDING_BIGGER,
+ NetconfMessageState.THIRD_BRACKET.evaluateChar(']')
+ )
charList.minus(']').forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.THIRD_BRACKET.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.THIRD_BRACKET.evaluateChar(it)
+ )
}
}
@Test
fun `ENDING_BIGGER transitions`() {
- assertEquals(NetconfMessageState.END_PATTERN,
- NetconfMessageState.ENDING_BIGGER.evaluateChar('>'))
+ assertEquals(
+ NetconfMessageState.END_PATTERN,
+ NetconfMessageState.ENDING_BIGGER.evaluateChar('>')
+ )
charList.minus('>').forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.ENDING_BIGGER.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.ENDING_BIGGER.evaluateChar(it)
+ )
}
}
@Test
fun `FIRST_LF transitions`() {
- assertEquals(NetconfMessageState.FIRST_HASH,
- NetconfMessageState.FIRST_LF.evaluateChar('#'))
- assertEquals(NetconfMessageState.FIRST_BRACKET,
- NetconfMessageState.FIRST_LF.evaluateChar(']'))
- assertEquals(NetconfMessageState.FIRST_LF,
- NetconfMessageState.FIRST_LF.evaluateChar('\n'))
+ assertEquals(
+ NetconfMessageState.FIRST_HASH,
+ NetconfMessageState.FIRST_LF.evaluateChar('#')
+ )
+ assertEquals(
+ NetconfMessageState.FIRST_BRACKET,
+ NetconfMessageState.FIRST_LF.evaluateChar(']')
+ )
+ assertEquals(
+ NetconfMessageState.FIRST_LF,
+ NetconfMessageState.FIRST_LF.evaluateChar('\n')
+ )
charList.minus(listOf('#', ']', '\n')).forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.FIRST_LF.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.FIRST_LF.evaluateChar(it)
+ )
}
}
@Test
fun `FIRST_HASH transitions`() {
- assertEquals(NetconfMessageState.SECOND_HASH,
- NetconfMessageState.FIRST_HASH.evaluateChar('#'))
+ assertEquals(
+ NetconfMessageState.SECOND_HASH,
+ NetconfMessageState.FIRST_HASH.evaluateChar('#')
+ )
charList.minus('#').forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.FIRST_HASH.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.FIRST_HASH.evaluateChar(it)
+ )
}
}
@Test
fun `SECOND_HASH transitions`() {
- assertEquals(NetconfMessageState.END_CHUNKED_PATTERN,
- NetconfMessageState.SECOND_HASH.evaluateChar('\n'))
-
- charList.minus( '\n').forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.SECOND_HASH.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.END_CHUNKED_PATTERN,
+ NetconfMessageState.SECOND_HASH.evaluateChar('\n')
+ )
+
+ charList.minus('\n').forEach {
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.SECOND_HASH.evaluateChar(it)
+ )
}
}
@Test
fun `END_CHUNKED_PATTERN transitions`() {
charList.forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.END_CHUNKED_PATTERN.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.END_CHUNKED_PATTERN.evaluateChar(it)
+ )
}
}
@Test
fun `END_PATTERN transitions`() {
charList.forEach {
- assertEquals(NetconfMessageState.NO_MATCHING_PATTERN,
- NetconfMessageState.END_PATTERN.evaluateChar(it))
+ assertEquals(
+ NetconfMessageState.NO_MATCHING_PATTERN,
+ NetconfMessageState.END_PATTERN.evaluateChar(it)
+ )
}
}
-
}
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 7b0b799bc..9a3652aa1 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
@@ -21,7 +21,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
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.api.DeviceResponse
@@ -39,11 +38,15 @@ class NetconfRpcServiceImplTest {
companion object {
private const val someString = "someString"
private const val replyStr = "this is a reply"
- private val failedDeviceResponse = DeviceResponse(status = RpcStatus.FAILURE,
- requestMessage = "request message", responseMessage = replyStr) //responseMessage will be null in this POJO
- private val successfulDeviceResponse = DeviceResponse(status = RpcStatus.SUCCESS,
- requestMessage = "request message", responseMessage = replyStr) //responseMessage will be null in this POJO
- //but will be set later from mockSession
+ private val failedDeviceResponse = DeviceResponse(
+ status = RpcStatus.FAILURE,
+ requestMessage = "request message", responseMessage = replyStr
+ ) // responseMessage will be null in this POJO
+ private val successfulDeviceResponse = DeviceResponse(
+ 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
private val deviceInfo: DeviceInfo = DeviceInfo().apply {
@@ -375,4 +378,4 @@ class NetconfRpcServiceImplTest {
assertTrue { rpcResult.errorMessage!!.contains("failed in 'closeSession' command") }
}
}
-} \ 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/core/NetconfSessionImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionImplTest.kt
index e3cda5a49..b94c092e3 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
@@ -16,7 +16,13 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core
-import io.mockk.*
+import io.mockk.CapturingSlot
+import io.mockk.Runs
+import io.mockk.every
+import io.mockk.just
+import io.mockk.mockk
+import io.mockk.spyk
+import io.mockk.verify
import org.apache.sshd.client.SshClient
import org.apache.sshd.client.channel.ChannelSubsystem
import org.apache.sshd.client.channel.ClientChannel
@@ -37,8 +43,10 @@ import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.InputStream
-import java.nio.charset.*
-import java.util.concurrent.*
+import java.nio.charset.StandardCharsets
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.ExecutionException
+import java.util.concurrent.TimeoutException
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue
@@ -106,7 +114,7 @@ class NetconfSessionImplTest {
verify { session["startClient"]() }
}
- //look for NetconfException being thrown when cannot connect
+ // look for NetconfException being thrown when cannot connect
@Test
fun `connect throws NetconfException on error`() {
val errMsg = "$deviceInfo: Failed to establish SSH session"
@@ -119,7 +127,7 @@ class NetconfSessionImplTest {
@Test
fun `disconnect without force option for rpcService succeeds`() {
- //rpcService.closeSession succeeds with status not RpcStatus.FAILURE
+ // rpcService.closeSession succeeds with status not RpcStatus.FAILURE
every { rpcService.closeSession(false) } returns SUCCESSFUL_DEVICE_RESPONSE
every { mockClientSession.close() } just Runs
every { mockSshClient.close() } just Runs
@@ -128,9 +136,9 @@ class NetconfSessionImplTest {
netconfSessionSpy.setSession(mockClientSession)
netconfSessionSpy.setClient(mockSshClient)
netconfSessionSpy.setChannel(mockClientChannel)
- //RUN
+ // RUN
netconfSessionSpy.disconnect()
- //make sure that rpcService.close session is not called again.
+ // make sure that rpcService.close session is not called again.
verify(exactly = 0) { rpcService.closeSession(true) }
verify { mockClientSession.close() }
verify { mockSshClient.close() }
@@ -139,24 +147,23 @@ class NetconfSessionImplTest {
@Test
fun `disconnect with force option for rpcService succeeds`() {
- //rpcService.closeSession succeeds with status not RpcStatus.FAILURE
+ // 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
netconfSessionSpy.setSession(mockClientSession)
netconfSessionSpy.setClient(mockSshClient)
netconfSessionSpy.setChannel(mockClientChannel)
- //RUN
+ // RUN
netconfSessionSpy.disconnect()
- //VERIFY
+ // VERIFY
verify(exactly = 2) { rpcService.closeSession(any()) }
verify { mockClientSession.close() }
verify { mockSshClient.close() }
verify { mockClientChannel.close() }
-
}
@Test
@@ -185,9 +192,9 @@ class NetconfSessionImplTest {
every { mockSshClient.isClosed } returns true
netconfSessionSpy.setClient(mockSshClient)
every { netconfSessionSpy["startConnection"]() as Unit } just Runs
- //Call method
+ // Call method
netconfSessionSpy.checkAndReestablish()
- //Verify
+ // Verify
verify { netconfSessionSpy.clearReplies() }
verify { netconfSessionSpy["startConnection"]() }
}
@@ -200,9 +207,9 @@ class NetconfSessionImplTest {
every { netconfSessionSpy["startSession"]() as Unit } just Runs
netconfSessionSpy.setClient(mockSshClient)
netconfSessionSpy.setSession(mockClientSession)
- //Call method
+ // Call method
netconfSessionSpy.checkAndReestablish()
- //Verify
+ // Verify
verify { netconfSessionSpy.clearReplies() }
verify { netconfSessionSpy["startSession"]() }
}
@@ -217,59 +224,57 @@ class NetconfSessionImplTest {
netconfSessionSpy.setClient(mockSshClient)
netconfSessionSpy.setSession(mockClientSession)
netconfSessionSpy.setChannel(mockClientChannel)
- //Call method
+ // Call method
netconfSessionSpy.checkAndReestablish()
- //Verify
+ // Verify
verify { netconfSessionSpy.clearReplies() }
verify { netconfSessionSpy["openChannel"]() }
}
-
@Test
fun `syncRpc runs normally`() {
val netconfSessionSpy = spyk(netconfSession)
val futureRet: CompletableFuture<String> = CompletableFuture.completedFuture(futureMsg)
- //test the case where SSH connection did not need to be re-established.
- //put an existing item into the replies
+ // test the case where SSH connection did not need to be re-established.
+ // put an existing item into the replies
netconfSessionSpy.getReplies()["somekey"] = CompletableFuture.completedFuture("${futureMsg}2")
every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet
every { netconfCommunicator.getFutureFromSendMessage(any(), any(), any()) } returns futureRet.get()
every { netconfSessionSpy.checkAndReestablish() } just Runs
- //call the method
+ // call the method
assertEquals(futureMsg, netconfSessionSpy.syncRpc("0", "0"))
- //make sure the replies didn't change
+ // 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() }
}
-
@Test
fun `syncRpc still succeeds and replies are cleared on client disconnect`() {
val netconfSessionSpy = spyk(netconfSession, recordPrivateCalls = true)
val futureRet: CompletableFuture<String> = CompletableFuture.completedFuture(futureMsg)
- //put an item into the replies
+ // put an item into the replies
netconfSessionSpy.getReplies()["somekey"] = CompletableFuture.completedFuture("${futureMsg}2")
- //tests the case where SSH session needs to be re-established.
+ // tests the case where SSH session needs to be re-established.
every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet
every { netconfSessionSpy["startClient"]() as Unit } just Runs
every { netconfCommunicator.getFutureFromSendMessage(any(), any(), any()) } returns futureRet.get()
every { mockSshClient.isClosed } returns true
netconfSessionSpy.setClient(mockSshClient)
- //call the method
+ // call the method
assertEquals(futureMsg, netconfSessionSpy.syncRpc("0", "0"))
- //make sure the replies got cleared out
+ // make sure the replies got cleared out
assertTrue { netconfSessionSpy.getReplies().isEmpty() }
verify(exactly = 1) { netconfSessionSpy.clearReplies() }
}
- //Test for handling CompletableFuture.get returns InterruptedException inside NetconfDeviceCommunicator
+ // Test for handling CompletableFuture.get returns InterruptedException inside NetconfDeviceCommunicator
@Test
fun `syncRpc throws NetconfException if InterruptedException is caught`() {
val expectedExceptionMsg = "$deviceInfo: Interrupted while waiting for reply for request: $formattedRequest"
@@ -279,21 +284,22 @@ class NetconfSessionImplTest {
every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet
every { netconfCommunicator.getFutureFromSendMessage(any(), any(), any()) } throws InterruptedException("interrupted")
every { netconfSessionSpy.checkAndReestablish() } just Runs
- //call the method
+ // call the method
netconfSessionSpy.syncRpc("0", "0")
}
}
@Test
fun `syncRpc throws NetconfException if TimeoutException is caught`() {
- val expectedExceptionMsg = "$deviceInfo: Timed out while waiting for reply for request $formattedRequest after ${deviceInfo.replyTimeout} sec."
+ val expectedExceptionMsg =
+ "$deviceInfo: Timed out while waiting for reply for request $formattedRequest after ${deviceInfo.replyTimeout} sec."
assertFailsWith(exceptionClass = NetconfException::class, message = expectedExceptionMsg) {
val netconfSessionSpy = spyk(netconfSession)
val futureRet: CompletableFuture<String> = CompletableFuture.completedFuture(futureMsg)
every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet
every { netconfCommunicator.getFutureFromSendMessage(any(), any(), any()) } throws TimeoutException("timed out")
every { netconfSessionSpy.checkAndReestablish() } just Runs
- //call the method
+ // call the method
netconfSessionSpy.syncRpc("0", "0")
}
}
@@ -306,11 +312,11 @@ class NetconfSessionImplTest {
val futureRet: CompletableFuture<String> = 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)
- //call the method
+ // call the method
netconfSessionSpy.syncRpc("0", "0")
}
}
@@ -323,12 +329,12 @@ class NetconfSessionImplTest {
val futureRet: CompletableFuture<String> = 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
+ // call the method
netconfSessionSpy.syncRpc("0", "0")
- //make sure replies are cleared...
+ // make sure replies are cleared...
verify(exactly = 1) { netconfSessionSpy.clearReplies() }
verify(exactly = 1) { netconfSessionSpy.clearErrorReplies() }
}
@@ -340,12 +346,12 @@ class NetconfSessionImplTest {
every { netconfSessionSpy.checkAndReestablish() } just Runs
val futureRet: CompletableFuture<String> = CompletableFuture.completedFuture(futureMsg)
every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet
- //run the method
+ // run the method
val rpcResultFuture = netconfSessionSpy.asyncRpc("0", "0")
every { netconfSessionSpy.checkAndReestablish() } just Runs
- //make sure the future gets resolved
+ // make sure the future gets resolved
assertTrue { rpcResultFuture.get() == futureMsg }
- //make sure that clearReplies wasn't called (reestablishConnection check)
+ // make sure that clearReplies wasn't called (reestablishConnection check)
verify(exactly = 0) { netconfSessionSpy.clearReplies() }
}
@@ -357,7 +363,7 @@ class NetconfSessionImplTest {
throw Exception("blah")
}
every { netconfCommunicator.sendMessage(any(), any()) } returns futureRet
- //run the method
+ // run the method
val rpcResultFuture = netconfSessionSpy.asyncRpc("0", "0")
every { netconfSessionSpy.checkAndReestablish() } just Runs
val e = assertFailsWith(exceptionClass = ExecutionException::class, message = futureMsg) {
@@ -386,11 +392,11 @@ class NetconfSessionImplTest {
fun `startSession tries to connect to user supplied device`() {
every { mockSshClient.start() } just Runs
every { mockSshClient.properties } returns hashMapOf<String, Any>()
- //setup slots to capture values from the invocations
+ // setup slots to capture values from the invocations
val userSlot = CapturingSlot<String>()
val ipSlot = CapturingSlot<String>()
val portSlot = CapturingSlot<Int>()
- //create a future that succeeded
+ // create a future that succeeded
val succeededFuture = DefaultConnectFuture(Any(), Any())
succeededFuture.value = mockClientSession
every { mockSshClient.connect(capture(userSlot), capture(ipSlot), capture(portSlot)) } returns succeededFuture
@@ -398,9 +404,9 @@ class NetconfSessionImplTest {
every { netconfSessionSpy["authSession"]() as Unit } just Runs
every { netconfSessionSpy["setupNewSSHClient"]() as Unit } just Runs
netconfSessionSpy.setClient(mockSshClient)
- //RUN
+ // RUN
netconfSessionSpy.connect()
- //Verify
+ // Verify
verify { mockSshClient.connect(deviceInfo.username, deviceInfo.ipAddress, deviceInfo.port) }
assertEquals(deviceInfo.username, userSlot.captured)
assertEquals(deviceInfo.ipAddress, ipSlot.captured)
@@ -411,11 +417,11 @@ class NetconfSessionImplTest {
@Test
fun `authSession throws exception if ClientSession is not AUTHED`() {
assertFailsWith(exceptionClass = NetconfException::class) {
- //after client session connects,
+ // after client session connects,
every { mockSshClient.start() } just Runs
every { mockSshClient.properties } returns hashMapOf<String, Any>()
val succeededAuthFuture = DefaultAuthFuture(Any(), Any())
- succeededAuthFuture.value = true //AuthFuture's value is Boolean
+ succeededAuthFuture.value = true // AuthFuture's value is Boolean
val passSlot = CapturingSlot<String>()
every { mockClientSession.addPasswordIdentity(capture(passSlot)) } just Runs
every { mockClientSession.auth() } returns succeededAuthFuture
@@ -423,21 +429,21 @@ 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)
- //RUN
+ // RUN
netconfSessionSpy.connect()
}
}
- //common mock initializer for more weird tests.
- private fun setupOpenChannelMocks(): Unit {
+ // common mock initializer for more weird tests.
+ private fun setupOpenChannelMocks() {
every { mockSshClient.start() } just Runs
every { mockSshClient.properties } returns hashMapOf<String, Any>()
val succeededAuthFuture = DefaultAuthFuture(Any(), Any())
- succeededAuthFuture.value = true //AuthFuture's value is Boolean
+ succeededAuthFuture.value = true // AuthFuture's value is Boolean
val passSlot = CapturingSlot<String>()
every { mockClientSession.addPasswordIdentity(capture(passSlot)) } just Runs
every { mockClientSession.auth() } returns succeededAuthFuture
@@ -445,9 +451,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
@@ -456,7 +464,7 @@ class NetconfSessionImplTest {
@Test
fun `authSession opensChannel if ClientSession is AUTHED and session can be opened`() {
- //after client session connects, make sure the client receives authentication
+ // after client session connects, make sure the client receives authentication
setupOpenChannelMocks()
val channelFuture = DefaultOpenFuture(Any(), Any())
channelFuture.value = true
@@ -471,17 +479,16 @@ class NetconfSessionImplTest {
every { netconfSessionSpy["setupNewSSHClient"]() as Unit } just Runs
every { netconfSessionSpy["setupHandler"]() as Unit } just Runs
netconfSessionSpy.setClient(mockSshClient)
- //Run
+ // Run
netconfSessionSpy.connect()
- //Verify
+ // Verify
verify { mockSubsystem.open() }
}
-
@Test
fun `authSession throws NetconfException if ClientSession is AUTHED but channelFuture timed out or not open`() {
assertFailsWith(exceptionClass = NetconfException::class) {
- //after client session connects, make sure the client receives authentication
+ // after client session connects, make sure the client receives authentication
setupOpenChannelMocks()
val channelFuture = DefaultOpenFuture(Any(), Any())
every { mockSubsystem.open() } returns channelFuture
@@ -489,14 +496,13 @@ class NetconfSessionImplTest {
every { netconfSessionSpy["setupNewSSHClient"]() as Unit } just Runs
every { netconfSessionSpy["setupHandler"]() as Unit } just Runs
netconfSessionSpy.setClient(mockSshClient)
- //Run
+ // Run
netconfSessionSpy.connect()
- //Verify
+ // Verify
verify { mockSubsystem.open() }
}
}
-
@Test
fun `disconnect closes session, channel, and client`() {
every { rpcService.closeSession(false) } returns SUCCESSFUL_DEVICE_RESPONSE
@@ -507,16 +513,16 @@ class NetconfSessionImplTest {
netconfSessionSpy.setChannel(mockClientChannel)
netconfSessionSpy.setClient(mockSshClient)
netconfSessionSpy.setSession(mockClientSession)
- //RUN
+ // RUN
netconfSessionSpy.disconnect()
- //VERIFY
+ // VERIFY
verify { mockClientSession.close() }
verify { mockClientChannel.close() }
verify { mockSshClient.close() }
}
@Test
- fun `disconnect wraps IOException if channel doesn't close`() { //this test is equivalent to others
+ fun `disconnect wraps IOException if channel doesn't close`() { // this test is equivalent to others
every { rpcService.closeSession(false) } returns SUCCESSFUL_DEVICE_RESPONSE
every { mockClientSession.close() } just Runs
every { mockClientChannel.close() } throws IOException("channel doesn't want to close!")
@@ -524,9 +530,9 @@ class NetconfSessionImplTest {
netconfSessionSpy.setChannel(mockClientChannel)
netconfSessionSpy.setClient(mockSshClient)
netconfSessionSpy.setSession(mockClientSession)
- //RUN
+ // RUN
netconfSessionSpy.disconnect()
- //VERIFY
+ // VERIFY
verify { mockClientSession.close() }
}
}
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 f3817b7fc..ab762e821 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
@@ -16,16 +16,16 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core
-import org.junit.Test
import io.mockk.every
import io.mockk.mockk
import io.mockk.verifyAll
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.api.NetconfReceivedEvent
class NetconfSessionListenerImplTest {
- //Note: mockk's verifyAll is akin to verify with verifyNoMoreInteractions in Mockito
+ // Note: mockk's verifyAll is akin to verify with verifyNoMoreInteractions in Mockito
private val netconSession = mockk<NetconfSessionImpl>()
@Before
@@ -36,7 +36,7 @@ class NetconfSessionListenerImplTest {
}
@Test
- //NetconfReceivedEvent wth DEVICE_UNREGISTERED TYPE should call disconnect() on the NetconfSession
+ // NetconfReceivedEvent wth DEVICE_UNREGISTERED TYPE should call disconnect() on the NetconfSession
fun deviceUnregisteredMessageShouldCallSessionDisconnect() {
val netconfSessionListener = NetconfSessionListenerImpl(netconSession)
val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.DEVICE_UNREGISTERED)
@@ -45,7 +45,7 @@ class NetconfSessionListenerImplTest {
}
@Test
- //NetconfReceivedEvent wth SESSION_CLOSED TYPE should ALSO call disconnect() on the NetconfSession
+ // NetconfReceivedEvent wth SESSION_CLOSED TYPE should ALSO call disconnect() on the NetconfSession
fun sessionClosedMessageShouldCallSesionDisconnect() {
val netconfSessionListener = NetconfSessionListenerImpl(netconSession)
val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.SESSION_CLOSED)
@@ -54,8 +54,8 @@ class NetconfSessionListenerImplTest {
}
@Test
- //NetconfReceivedEvent wth DEVICE_ERROR TYPE should call addDeviceErrorReply() on the NetconfSession
- //with the event message payload
+ // NetconfReceivedEvent wth DEVICE_ERROR TYPE should call addDeviceErrorReply() on the NetconfSession
+ // with the event message payload
fun deviceErrorMessageShouldCallAddDeviceErrorReply() {
val netconfSessionListener = NetconfSessionListenerImpl(netconSession)
val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.DEVICE_ERROR)
@@ -64,7 +64,7 @@ class NetconfSessionListenerImplTest {
}
@Test
- //NetconfReceivedEvent wth DEVICE_REPLY TYPE should call addDeviceReply(messageId, payload) on the NetconfSession
+ // NetconfReceivedEvent wth DEVICE_REPLY TYPE should call addDeviceReply(messageId, payload) on the NetconfSession
fun deviceReplyMessageShouldCallAddDeviceReply() {
val netconfSessionListener = NetconfSessionListenerImpl(netconSession)
val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.DEVICE_REPLY)
@@ -74,14 +74,14 @@ class NetconfSessionListenerImplTest {
/**
* Helper to generate {@link NetconfReceivedEvent} object based on the {@link NetconfReceivedEvent.Type}
- * @param type {@link NetconfReceivedEvent.Type} of event
+ * @param type {@link NetconfReceivedEvent.Type} of event
*/
private fun genEventByType(type: NetconfReceivedEvent.Type): NetconfReceivedEvent {
return NetconfReceivedEvent(
- type,
- "messagePayload",
- "messageId",
- DeviceInfo()
+ type,
+ "messagePayload",
+ "messageId",
+ DeviceInfo()
)
}
-} \ 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/NetconfMessageUtilsTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt
index fcfa12570..cec0fda66 100644
--- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt
+++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt
@@ -40,7 +40,7 @@ class NetconfMessageUtilsTest {
@Test
fun `test getConfig with filterContent parameter null`() {
- val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType",null)
+ val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType", null)
val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/getConfig-response-filterContent-null.xml")
assertEquals("getConfig return was not correct", expectation, outcome)
}
@@ -54,16 +54,20 @@ class NetconfMessageUtilsTest {
@Test
fun `test editConfig with all parameters present`() {
- val outcome = NetconfMessageUtils.editConfig("customMessageId", "customConfigType", "customDefaultOperation",
- "customNewConfiguration")
+ val outcome = NetconfMessageUtils.editConfig(
+ "customMessageId", "customConfigType", "customDefaultOperation",
+ "customNewConfiguration"
+ )
val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/editConfig-response-all-parameters.xml")
assertEquals("editConfig return was not correct", expectation, outcome)
}
@Test
fun `test editConfig with defaultOperation parameter null`() {
- val outcome = NetconfMessageUtils.editConfig("customMessageId", "customConfigType", null,
- "customNewConfiguration")
+ val outcome = NetconfMessageUtils.editConfig(
+ "customMessageId", "customConfigType", null,
+ "customNewConfiguration"
+ )
val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/editConfig-response-defaultOperation-null.xml")
assertEquals("editConfig return was not correct", expectation, outcome)
}
@@ -92,21 +96,24 @@ class NetconfMessageUtilsTest {
@Test
fun `test commit with confirmed true, persistId empty and persist empty`() {
val outcome = NetconfMessageUtils.commit("customMessageId", true, 1, "", "")
- val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml")
+ val expectation =
+ JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml")
assertEquals("commit return was not correct", expectation, outcome)
}
@Test
fun `test commit with confirmed false, persistId non-empty and persist empty`() {
val outcome = NetconfMessageUtils.commit("customMessageId", false, 1, "", "customPersistId")
- val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml")
+ val expectation =
+ JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml")
assertEquals("commit return was not correct", expectation, outcome)
}
@Test
fun `test commit with confirmed false, persistId empty and persist non-empty`() {
val outcome = NetconfMessageUtils.commit("customMessageId", false, 1, "customPersist", "")
- val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml")
+ val expectation =
+ JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml")
assertEquals("commit return was not correct", expectation, outcome)
}
@@ -173,7 +180,7 @@ class NetconfMessageUtilsTest {
assertEquals("closeSession return was not correct", expectation, outcome)
}
- //TODO validateRPCXML
+ // TODO validateRPCXML
@Test
fun `test getMsgId with valid message`() {
@@ -197,6 +204,5 @@ class NetconfMessageUtilsTest {
assertEquals("getMsgId return was not correct", expectation, outcome)
}
-//TODO validateChunkedFraming
-
+ // TODO validateChunkedFraming
}
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 b80dc2d88..0d791c2a6 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,29 +27,28 @@ class RpcMessageUtilsTest {
@Test
fun getConfig() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<get-config><source><candidate/></source><filter type=\"subtree\">Test-Filter-Content</filter>"
- + "</get-config></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<get-config><source><candidate/></source><filter type=\"subtree\">Test-Filter-Content</filter>" +
+ "</get-config></rpc>")
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(), "")
+ NetconfMessageUtils.getConfig(messageId, configType, filterContent).replace("[\n\r\t]".toRegex(), "")
assertTrue(NetconfMessageUtils.validateRPCXML(result))
Assert.assertEquals(checkString, result)
}
-
@Test
fun editConfig() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<edit-config><target><candidate/></target><default-operation>Test-Default-Operation</default-operation>"
- + "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">Test-Filter-Content</config></edit-config></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<edit-config><target><candidate/></target><default-operation>Test-Default-Operation</default-operation>" +
+ "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">Test-Filter-Content</config></edit-config></rpc>")
val messageId = "Test-Message-ID"
val configType = NetconfDatastore.CANDIDATE.datastore
@@ -57,7 +56,7 @@ class RpcMessageUtilsTest {
val defaultOperation = "Test-Default-Operation"
val result =
- NetconfMessageUtils.editConfig(messageId, configType, defaultOperation, filterContent).replace("[\n\r\t]".toRegex(), "")
+ NetconfMessageUtils.editConfig(messageId, configType, defaultOperation, filterContent).replace("[\n\r\t]".toRegex(), "")
assertTrue(NetconfMessageUtils.validateRPCXML(result))
Assert.assertEquals(checkString, result)
@@ -65,9 +64,9 @@ class RpcMessageUtilsTest {
@Test
fun validate() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<validate><source><candidate/></source></validate></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<validate><source><candidate/></source></validate></rpc>")
val messageId = "Test-Message-ID"
val configType = NetconfDatastore.CANDIDATE.datastore
@@ -81,16 +80,16 @@ class RpcMessageUtilsTest {
@Test
fun cancelCommit() {
val checkString =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<cancel-commit>" +
- "<persist-id>1234</persist-id>" +
- "</cancel-commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<cancel-commit>" +
+ "<persist-id>1234</persist-id>" +
+ "</cancel-commit></rpc>")
val messageId = "Test-Message-ID"
val cancelCommitPersistId =
- NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "")
+ NetconfMessageUtils.cancelCommit(messageId, "1234").replace("[\n\r\t]".toRegex(), "")
assertTrue(NetconfMessageUtils.validateRPCXML(cancelCommitPersistId))
Assert.assertEquals(checkString, cancelCommitPersistId)
@@ -99,10 +98,10 @@ class RpcMessageUtilsTest {
@Test
fun cancelCommitNoPersistId() {
val checkString =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<cancel-commit>" +
- "</cancel-commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<cancel-commit>" +
+ "</cancel-commit></rpc>")
val messageId = "Test-Message-ID"
@@ -114,31 +113,30 @@ class RpcMessageUtilsTest {
@Test
fun commit() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<commit></commit></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<commit></commit></rpc>")
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(), "")
+ 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 =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<commit>" +
- "<persist-id>1234</persist-id>" +
- "</commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<commit>" +
+ "<persist-id>1234</persist-id>" +
+ "</commit></rpc>")
val messageId = "Test-Message-ID"
@@ -149,8 +147,10 @@ class RpcMessageUtilsTest {
try {
NetconfMessageUtils.commit(messageId, true, 30, "", "1234").replace("[\n\r\t]".toRegex(), "")
} catch (e: NetconfException) {
- Assert.assertEquals("Can't proceed <commit> with both confirmed flag and persistId(1234) specified. Only one should be specified.",
- e.message)
+ Assert.assertEquals(
+ "Can't proceed <commit> with both confirmed flag and persistId(1234) specified. Only one should be specified.",
+ e.message
+ )
return
}
@@ -160,13 +160,13 @@ class RpcMessageUtilsTest {
@Test
fun commitPersist() {
val checkString =
- ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
- "<commit>" +
- "<confirmed/>" +
- "<confirm-timeout>30</confirm-timeout>" +
- "<persist>1234</persist>" +
- "</commit></rpc>")
+ ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<commit>" +
+ "<confirmed/>" +
+ "<confirm-timeout>30</confirm-timeout>" +
+ "<persist>1234</persist>" +
+ "</commit></rpc>")
val messageId = "Test-Message-ID"
@@ -178,8 +178,10 @@ class RpcMessageUtilsTest {
try {
NetconfMessageUtils.commit(messageId, false, 30, "1234", "1234").replace("[\n\r\t]".toRegex(), "")
} catch (e: NetconfException) {
- Assert.assertEquals("Can't proceed <commit> with both persist(1234) and persistId(1234) specified. Only one should be specified.",
- e.message)
+ Assert.assertEquals(
+ "Can't proceed <commit> with both persist(1234) and persistId(1234) specified. Only one should be specified.",
+ e.message
+ )
return
}
fail()
@@ -187,9 +189,9 @@ class RpcMessageUtilsTest {
@Test
fun unlock() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<unlock><target><candidate/></target></unlock></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<unlock><target><candidate/></target></unlock></rpc>")
val messageId = "Test-Message-ID"
val configType = NetconfDatastore.CANDIDATE.datastore
@@ -202,9 +204,9 @@ class RpcMessageUtilsTest {
@Test
fun deleteConfig() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<delete-config><target><candidate/></target></delete-config></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<delete-config><target><candidate/></target></delete-config></rpc>")
val messageId = "Test-Message-ID"
val netconfTargetConfig = NetconfDatastore.CANDIDATE.datastore
@@ -226,9 +228,9 @@ class RpcMessageUtilsTest {
@Test
fun discardChanges() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<discard-changes/></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<discard-changes/></rpc>")
val messageId = "Test-Message-ID"
@@ -240,9 +242,9 @@ class RpcMessageUtilsTest {
@Test
fun lock() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<lock><target><candidate/></target></lock></rpc>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ "<rpc message-id=\"Test-Message-ID\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" +
+ "<lock><target><candidate/></target></lock></rpc>")
val messageId = "Test-Message-ID"
val configType = NetconfDatastore.CANDIDATE.datastore
@@ -271,8 +273,8 @@ class RpcMessageUtilsTest {
@Test
fun createHelloString() {
- val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> "
- +"<capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>]]>]]>")
+ val checkString = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> " +
+ "<capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>]]>]]>")
val capability = listOf<String>("hi", "hello")
@@ -303,19 +305,19 @@ class RpcMessageUtilsTest {
}
@Test
- fun formatRPCRequest(){
+ fun formatRPCRequest() {
val checkString = ("#199" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> <capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>" +
"##")
- val request = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> "
- +"<capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>]]>]]>")
+ val request = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"> " +
+ "<capabilities> <capability>hi</capability> <capability>hello</capability> </capabilities></hello>]]>]]>")
val messageId = "Test-Message-ID"
- val capabilities = setOf<String>("hi", "hello","urn:ietf:params:netconf:base:1.1")
+ val capabilities = setOf<String>("hi", "hello", "urn:ietf:params:netconf:base:1.1")
- val result = NetconfMessageUtils.formatRPCRequest(request,messageId,capabilities).replace("[\n\r\t]".toRegex(), "")
+ val result = NetconfMessageUtils.formatRPCRequest(request, messageId, capabilities).replace("[\n\r\t]".toRegex(), "")
Assert.assertEquals(checkString, result)
}
@@ -329,5 +331,4 @@ class RpcMessageUtilsTest {
println("Don't fear \"[Fatal Error] :1:1: Content is not allowed in prolog.\" TODO: adjust logging for NetconfMessageUtils")
assertFalse { NetconfMessageUtils.validateRPCXML("really bad XML ~~~input") }
}
-
}