1 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils
 
   3 import org.junit.Assert.*
 
   4 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException
 
   5 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 
   6 import kotlin.test.Test
 
   7 import kotlin.test.assertFailsWith
 
   9 class NetconfMessageUtilsTest {
 
  12     fun `test getConfig with all parameters present`() {
 
  13         val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType", "customFilterContent")
 
  14         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/getConfig-response-all-parameters.xml")
 
  15         assertEquals("getConfig return was not correct", expectation, outcome)
 
  19     fun `test getConfig with filterContent parameter null`() {
 
  20         val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType",null)
 
  21         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/getConfig-response-filterContent-null.xml")
 
  22         assertEquals("getConfig return was not correct", expectation, outcome)
 
  26     fun `test doWrappedRpc`() {
 
  27         val outcome = NetconfMessageUtils.doWrappedRpc("customMessageId", "customRequest")
 
  28         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/doWrappedRpc-response.xml")
 
  29         assertEquals("doWrappedRpc return was not correct", expectation, outcome)
 
  33     fun `test editConfig with all parameters present`() {
 
  34         val outcome = NetconfMessageUtils.editConfig("customMessageId", "customConfigType", "customDefaultOperation",
 
  35                 "customNewConfiguration")
 
  36         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/editConfig-response-all-parameters.xml")
 
  37         assertEquals("editConfig return was not correct", expectation, outcome)
 
  41     fun `test editConfig with defaultOperation parameter null`() {
 
  42         val outcome = NetconfMessageUtils.editConfig("customMessageId", "customConfigType", null,
 
  43                 "customNewConfiguration")
 
  44         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/editConfig-response-defaultOperation-null.xml")
 
  45         assertEquals("editConfig return was not correct", expectation, outcome)
 
  49     fun `test validate`() {
 
  50         val outcome = NetconfMessageUtils.validate("customMessageId", "customConfigType")
 
  51         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/validate-response.xml")
 
  52         assertEquals("validate return was not correct", expectation, outcome)
 
  56     fun `test commit with both persistId and persist non-empty`() {
 
  57         assertFailsWith(exceptionClass = NetconfException::class, message = "commit should have thrown an exception") {
 
  58             NetconfMessageUtils.commit("customMessageId", false, 1, "customPersist", "customPersistId")
 
  63     fun `test commit with confirmed true, persist empty and persistId non-empty`() {
 
  64         assertFailsWith(exceptionClass = NetconfException::class, message = "commit should have thrown an exception") {
 
  65             NetconfMessageUtils.commit("customMessageId", true, 1, "", "customPersistId")
 
  70     fun `test commit with confirmed true, persistId empty and persist empty`() {
 
  71         val outcome = NetconfMessageUtils.commit("customMessageId", true, 1, "", "")
 
  72         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml")
 
  73         assertEquals("commit return was not correct", expectation, outcome)
 
  77     fun `test commit with confirmed false, persistId non-empty and persist empty`() {
 
  78         val outcome = NetconfMessageUtils.commit("customMessageId", false, 1, "", "customPersistId")
 
  79         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml")
 
  80         assertEquals("commit return was not correct", expectation, outcome)
 
  84     fun `test commit with confirmed false, persistId empty and persist non-empty`() {
 
  85         val outcome = NetconfMessageUtils.commit("customMessageId", false, 1, "customPersist", "")
 
  86         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml")
 
  87         assertEquals("commit return was not correct", expectation, outcome)
 
  91     fun `test cancelCommit with all parameters not empty`() {
 
  92         val outcome = NetconfMessageUtils.cancelCommit("customMessageId", "customPersistId")
 
  93         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/cancelCommit-response-all-parameters-not-empty.xml")
 
  94         assertEquals("cancelCommit return was not correct", expectation, outcome)
 
  98     fun `test cancelCommit with persistId empty`() {
 
  99         val outcome = NetconfMessageUtils.cancelCommit("customMessageId", "")
 
 100         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/cancelCommit-response-persistId-empty.xml")
 
 101         assertEquals("cancelCommit return was not correct", expectation, outcome)
 
 105     fun `test unlock with all parameters not empty`() {
 
 106         val outcome = NetconfMessageUtils.unlock("customMessageId", "customConfigType")
 
 107         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/unlock-response-all-parameters-not-empty.xml")
 
 108         assertEquals("unlock return was not correct", expectation, outcome)
 
 112     fun `test deleteConfig with all parameters not empty`() {
 
 113         val outcome = NetconfMessageUtils.deleteConfig("customMessageId", "customConfigType")
 
 114         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/deleteConfig-response-all-parameters-not-empty.xml")
 
 115         assertEquals("deleteConfig return was not correct", expectation, outcome)
 
 119     fun `test deleteConfig with configType equals to NetconfDatastore_RUNNING_datastore`() {
 
 120         assertFailsWith(exceptionClass = NetconfException::class, message = "deleteConfig should have thrown an exception") {
 
 121             NetconfMessageUtils.deleteConfig("customMessageId", NetconfDatastore.RUNNING.datastore)
 
 126     fun `test discardChanges with all parameters not empty`() {
 
 127         val outcome = NetconfMessageUtils.discardChanges("customMessageId")
 
 128         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/discardChanges-response-all-parameters-not-empty.xml")
 
 129         assertEquals("discardChanges return was not correct", expectation, outcome)
 
 133     fun `test lock with all parameters not empty`() {
 
 134         val outcome = NetconfMessageUtils.lock("customMessageId", "customConfigType")
 
 135         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/lock-response-all-parameters-not-empty.xml")
 
 136         assertEquals("lock return was not correct", expectation, outcome)
 
 140     fun `test closeSession with force true`() {
 
 141         val outcome = NetconfMessageUtils.closeSession("customMessageId", true)
 
 142         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/closeSession-response-force-true.xml")
 
 143         assertEquals("closeSession return was not correct", expectation, outcome)
 
 147     fun `test closeSession with force false`() {
 
 148         val outcome = NetconfMessageUtils.closeSession("customMessageId", false)
 
 149         val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/closeSession-response-force-false.xml")
 
 150         assertEquals("closeSession return was not correct", expectation, outcome)
 
 153     //TODO validateRPCXML
 
 156     fun `test getMsgId with valid message`() {
 
 157         val messageId = "1234"
 
 158         val outcome = NetconfMessageUtils.getMsgId("message-id=\"${messageId}\"")
 
 159         val expectation = messageId
 
 160         assertEquals("getMsgId return was not correct", expectation, outcome)
 
 164     fun `test getMsgId with RpcMessageUtils_HELLO message`() {
 
 165         val outcome = NetconfMessageUtils.getMsgId(RpcMessageUtils.HELLO)
 
 166         val expectation = "-1"
 
 167         assertEquals("getMsgId return was not correct", expectation, outcome)
 
 171     fun `test getMsgId with invalid message`() {
 
 172         val outcome = NetconfMessageUtils.getMsgId("invalid message")
 
 174         assertEquals("getMsgId return was not correct", expectation, outcome)
 
 177 //TODO validateChunkedFraming