From dbd67ee741f4e3d255dfbe2674ad45ea854598fd Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Sun, 7 Apr 2019 22:13:50 -0400 Subject: Adding NetconfRpcServiceImplTest for netconf-executor Issue-ID: CCSDK-1126 Change-Id: Ib223ed93bbc8a81dea1d1fdf8c2aa12ef91ff9a8 Signed-off-by: Oleg Mitsura --- .../netconf/executor/api/NetconfMessage.kt | 45 ++++++---------------- .../netconf/executor/core/NetconfRpcServiceImpl.kt | 22 +++++------ .../netconf/executor/core/NetconfSessionImpl.kt | 8 ++-- 3 files changed, 26 insertions(+), 49 deletions(-) (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/main') 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 ef3605c66..1d5f515d0 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 @@ -1,5 +1,5 @@ /* - * Copyright © 2017-2019 AT&T, Bell Canada + * Copyright © 2019 Bell Canada * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,25 +18,13 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus -class DeviceResponse { - var status: String? = null - var errorMessage: String? = null - var responseMessage: String? = null - var requestMessage: String? = null - private var subDeviceResponse: MutableMap? = null - - fun addSubDeviceResponse(key: String, subDeviceResponse: DeviceResponse) { - if (this.subDeviceResponse == null) { - this.subDeviceResponse = hashMapOf() - } - this.subDeviceResponse!![key] = subDeviceResponse - } +data class DeviceResponse(var status: String? = null, + var errorMessage: String? = null, + var responseMessage: String? = null, + var requestMessage: String? = null) { fun isSuccess(): Boolean { - if (this.status != RpcStatus.SUCCESS && !this.errorMessage.isNullOrEmpty()) { - return false - } - return true + return this.status == RpcStatus.SUCCESS && this.errorMessage.isNullOrEmpty() } } @@ -45,13 +33,14 @@ class DeviceResponse { * Creates an event of a given type and for the specified subject and the current time. * * @param type event type - * @param payload message from the device + * @param messagePayload message from the device * @param messageId id of the message related to the event * @param deviceInfo device of event */ -class NetconfReceivedEvent - (private var type: Type, private var payload: String = "", private var messageId: String = "", - private var deviceInfo: DeviceInfo) { +class NetconfReceivedEvent(val type: Type, + val messagePayload: String = "", + val messageId: String = "", + val deviceInfo: DeviceInfo) { enum class Type { DEVICE_REPLY, @@ -59,16 +48,4 @@ class NetconfReceivedEvent DEVICE_ERROR, SESSION_CLOSED } - - fun getType(): Type { - return type - } - - fun getMessagePayload(): String { - return payload - } - - fun getMessageID(): String { - return messageId - } } \ 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/NetconfRpcServiceImpl.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfRpcServiceImpl.kt index 4619460e3..e4e3ffe4a 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 @@ -49,7 +49,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(rpc, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in invokeRpc command $e.message" + output.errorMessage = "$deviceInfo: failed in 'invokeRpc' command ${e.message}" } return output } @@ -63,7 +63,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(message, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in get-config command $e.message" + output.errorMessage = "$deviceInfo: failed in 'get-config' command ${e.message}" } return output } @@ -78,7 +78,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(deleteConfigMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in delete config command $e.message" + output.errorMessage = "$deviceInfo: failed in 'delete-config' command ${e.message}" } return output } @@ -93,7 +93,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(lockMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in lock command $e.message" + output.errorMessage = "$deviceInfo: failed in 'lock' command ${e.message}" } return output @@ -109,7 +109,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(unlockMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in lock command $e.message" + output.errorMessage = "$deviceInfo: failed in 'unLock' command ${e.message}" } return output } @@ -123,7 +123,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(messageContent, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in commit command $e.message" + output.errorMessage = "$deviceInfo: failed in 'commit' command ${e.message}" } return output } @@ -137,7 +137,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(messageContent, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in cancelCommit command $e.message" + output.errorMessage = "$deviceInfo: failed in 'cancelCommit' command ${e.message}" } return output } @@ -152,7 +152,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(discardChangesMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in discard changes command " + e.message + output.errorMessage = "$deviceInfo: failed in 'discard-config' command ${e.message}" } return output } @@ -169,7 +169,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ response = asyncRpc(editMessage, messageId) } catch (e: Exception) { response.status = RpcStatus.FAILURE - response.errorMessage = e.message + response.errorMessage = "$deviceInfo: failed in 'editConfig' command ${e.message}" } return response } @@ -183,7 +183,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(validateMessage, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in validate command " + e.message + output.errorMessage = "$deviceInfo: failed in 'validate' command ${e.message}" } return output } @@ -197,7 +197,7 @@ class NetconfRpcServiceImpl(private var deviceInfo: DeviceInfo) : NetconfRpcServ output = asyncRpc(messageContent, messageId) } catch (e: Exception) { output.status = RpcStatus.FAILURE - output.errorMessage = "$deviceInfo: failed in closeSession command " + e.message + output.errorMessage = "$deviceInfo: failed in 'closeSession' command ${e.message}" } return output } 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 de4cda950..ae4d8444c 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 @@ -264,12 +264,12 @@ class NetconfSessionImpl(private val deviceInfo: DeviceInfo, private val rpcServ inner class NetconfSessionListenerImpl : NetconfSessionListener { override fun notify(event: NetconfReceivedEvent) { - val messageId = event.getMessageID() + val messageId = event.messageId - when (event.getType()) { + when (event.type) { NetconfReceivedEvent.Type.DEVICE_UNREGISTERED -> disconnect() - NetconfReceivedEvent.Type.DEVICE_ERROR -> errorReplies.add(event.getMessagePayload()) - NetconfReceivedEvent.Type.DEVICE_REPLY -> replies[messageId]?.complete(event.getMessagePayload()) + NetconfReceivedEvent.Type.DEVICE_ERROR -> errorReplies.add(event.messagePayload) + NetconfReceivedEvent.Type.DEVICE_REPLY -> replies[messageId]?.complete(event.messagePayload) NetconfReceivedEvent.Type.SESSION_CLOSED -> disconnect() } } -- cgit 1.2.3-korg