From 911d06d21b99332348c8885fa0bb4e7bf0402f29 Mon Sep 17 00:00:00 2001 From: Rodrigo Ottero Date: Thu, 13 Jun 2019 14:53:24 +0100 Subject: Adding tests to NetconfMessageUtilsTest.kt Change-Id: If7a0d90ce264e7362e7118132303653eaaef9e69 Issue-ID: CCSDK-1046 Signed-off-by: Rodrigo Ottero --- .../executor/utils/NetconfMessageUtilsTest.kt | 179 +++++++++++++++++++++ ...celCommit-response-all-parameters-not-empty.xml | 5 + .../cancelCommit-response-persistId-empty.xml | 5 + .../closeSession-response-force-false.xml | 4 + .../closeSession-response-force-true.xml | 4 + ...e-and-persistId-empty-and-persist-not-empty.xml | 5 + ...e-and-persistId-not-empty-and-persist-empty.xml | 5 + ...-true-and-persistId-empty-and-persist-empty.xml | 5 + ...eteConfig-response-all-parameters-not-empty.xml | 8 + ...rdChanges-response-all-parameters-not-empty.xml | 4 + .../netconf-messages/doWrappedRpc-response.xml | 3 + .../editConfig-response-all-parameters.xml | 12 ++ .../editConfig-response-defaultOperation-null.xml | 11 ++ .../getConfig-response-all-parameters.xml | 11 ++ .../getConfig-response-filterContent-null.xml | 8 + .../lock-response-all-parameters-not-empty.xml | 8 + .../unlock-response-all-parameters-not-empty.xml | 8 + .../netconf-messages/validate-response.xml | 8 + 18 files changed, 293 insertions(+) create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-all-parameters-not-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-persistId-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-false.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-true.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/deleteConfig-response-all-parameters-not-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/discardChanges-response-all-parameters-not-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/doWrappedRpc-response.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-all-parameters.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-defaultOperation-null.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-all-parameters.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-filterContent-null.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/lock-response-all-parameters-not-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/unlock-response-all-parameters-not-empty.xml create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/validate-response.xml (limited to 'ms/blueprintsprocessor/functions') 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 new file mode 100644 index 000000000..e24659d1d --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/utils/NetconfMessageUtilsTest.kt @@ -0,0 +1,179 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils + +import org.junit.Assert.* +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import kotlin.test.Test +import kotlin.test.assertFailsWith + +class NetconfMessageUtilsTest { + + @Test + fun `test getConfig with all parameters present`() { + val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType", "customFilterContent") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/getConfig-response-all-parameters.xml") + assertEquals("getConfig return was not correct", expectation, outcome) + } + + @Test + fun `test getConfig with filterContent parameter 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) + } + + @Test + fun `test doWrappedRpc`() { + val outcome = NetconfMessageUtils.doWrappedRpc("customMessageId", "customRequest") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/doWrappedRpc-response.xml") + assertEquals("doWrappedRpc return was not correct", expectation, outcome) + } + + @Test + fun `test editConfig with all parameters present`() { + 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 expectation = JacksonUtils.getClassPathFileContent("netconf-messages/editConfig-response-defaultOperation-null.xml") + assertEquals("editConfig return was not correct", expectation, outcome) + } + + @Test + fun `test validate`() { + val outcome = NetconfMessageUtils.validate("customMessageId", "customConfigType") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/validate-response.xml") + assertEquals("validate return was not correct", expectation, outcome) + } + + @Test + fun `test commit with both persistId and persist non-empty`() { + assertFailsWith(exceptionClass = NetconfException::class, message = "commit should have thrown an exception") { + NetconfMessageUtils.commit("customMessageId", false, 1, "customPersist", "customPersistId") + } + } + + @Test + fun `test commit with confirmed true, persist empty and persistId non-empty`() { + assertFailsWith(exceptionClass = NetconfException::class, message = "commit should have thrown an exception") { + NetconfMessageUtils.commit("customMessageId", true, 1, "", "customPersistId") + } + } + + @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") + 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") + 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") + assertEquals("commit return was not correct", expectation, outcome) + } + + @Test + fun `test cancelCommit with all parameters not empty`() { + val outcome = NetconfMessageUtils.cancelCommit("customMessageId", "customPersistId") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/cancelCommit-response-all-parameters-not-empty.xml") + assertEquals("cancelCommit return was not correct", expectation, outcome) + } + + @Test + fun `test cancelCommit with persistId empty`() { + val outcome = NetconfMessageUtils.cancelCommit("customMessageId", "") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/cancelCommit-response-persistId-empty.xml") + assertEquals("cancelCommit return was not correct", expectation, outcome) + } + + @Test + fun `test unlock with all parameters not empty`() { + val outcome = NetconfMessageUtils.unlock("customMessageId", "customConfigType") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/unlock-response-all-parameters-not-empty.xml") + assertEquals("unlock return was not correct", expectation, outcome) + } + + @Test + fun `test deleteConfig with all parameters not empty`() { + val outcome = NetconfMessageUtils.deleteConfig("customMessageId", "customConfigType") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/deleteConfig-response-all-parameters-not-empty.xml") + assertEquals("deleteConfig return was not correct", expectation, outcome) + } + + @Test + fun `test deleteConfig with configType equals to NetconfDatastore_RUNNING_datastore`() { + assertFailsWith(exceptionClass = NetconfException::class, message = "deleteConfig should have thrown an exception") { + NetconfMessageUtils.deleteConfig("customMessageId", NetconfDatastore.RUNNING.datastore) + } + } + + @Test + fun `test discardChanges with all parameters not empty`() { + val outcome = NetconfMessageUtils.discardChanges("customMessageId") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/discardChanges-response-all-parameters-not-empty.xml") + assertEquals("discardChanges return was not correct", expectation, outcome) + } + + @Test + fun `test lock with all parameters not empty`() { + val outcome = NetconfMessageUtils.lock("customMessageId", "customConfigType") + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/lock-response-all-parameters-not-empty.xml") + assertEquals("lock return was not correct", expectation, outcome) + } + + @Test + fun `test closeSession with force true`() { + val outcome = NetconfMessageUtils.closeSession("customMessageId", true) + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/closeSession-response-force-true.xml") + assertEquals("closeSession return was not correct", expectation, outcome) + } + + @Test + fun `test closeSession with force false`() { + val outcome = NetconfMessageUtils.closeSession("customMessageId", false) + val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/closeSession-response-force-false.xml") + assertEquals("closeSession return was not correct", expectation, outcome) + } + + //TODO validateRPCXML + + @Test + fun `test getMsgId with valid message`() { + val messageId = "1234" + val outcome = NetconfMessageUtils.getMsgId("message-id=\"${messageId}\"") + val expectation = messageId + assertEquals("getMsgId return was not correct", expectation, outcome) + } + + @Test + fun `test getMsgId with RpcMessageUtils_HELLO message`() { + val outcome = NetconfMessageUtils.getMsgId(RpcMessageUtils.HELLO) + val expectation = "-1" + assertEquals("getMsgId return was not correct", expectation, outcome) + } + + @Test + fun `test getMsgId with invalid message`() { + val outcome = NetconfMessageUtils.getMsgId("invalid message") + val expectation = "" + assertEquals("getMsgId return was not correct", expectation, outcome) + } + +//TODO validateChunkedFraming + +} diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-all-parameters-not-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-all-parameters-not-empty.xml new file mode 100644 index 000000000..7f5a44cc5 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-all-parameters-not-empty.xml @@ -0,0 +1,5 @@ + + + +customPersistId + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-persistId-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-persistId-empty.xml new file mode 100644 index 000000000..5ffaf6fd9 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/cancelCommit-response-persistId-empty.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-false.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-false.xml new file mode 100644 index 000000000..282097b71 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-false.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-true.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-true.xml new file mode 100644 index 000000000..01a28d923 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/closeSession-response-force-true.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml new file mode 100644 index 000000000..d19e5b41e --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml @@ -0,0 +1,5 @@ + + + +customPersistId + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml new file mode 100644 index 000000000..ac489b774 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml new file mode 100644 index 000000000..ad0fef80f --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml @@ -0,0 +1,5 @@ + + + +1 + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/deleteConfig-response-all-parameters-not-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/deleteConfig-response-all-parameters-not-empty.xml new file mode 100644 index 000000000..1758bde55 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/deleteConfig-response-all-parameters-not-empty.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/discardChanges-response-all-parameters-not-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/discardChanges-response-all-parameters-not-empty.xml new file mode 100644 index 000000000..3559dd9f6 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/discardChanges-response-all-parameters-not-empty.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/doWrappedRpc-response.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/doWrappedRpc-response.xml new file mode 100644 index 000000000..0f6c3e76b --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/doWrappedRpc-response.xml @@ -0,0 +1,3 @@ + + +customRequest \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-all-parameters.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-all-parameters.xml new file mode 100644 index 000000000..f4a789fea --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-all-parameters.xml @@ -0,0 +1,12 @@ + + + + + + +customDefaultOperation + +customNewConfiguration + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-defaultOperation-null.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-defaultOperation-null.xml new file mode 100644 index 000000000..8efa46e20 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/editConfig-response-defaultOperation-null.xml @@ -0,0 +1,11 @@ + + + + + + + +customNewConfiguration + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-all-parameters.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-all-parameters.xml new file mode 100644 index 000000000..4135c166b --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-all-parameters.xml @@ -0,0 +1,11 @@ + + + + + + + +customFilterContent + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-filterContent-null.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-filterContent-null.xml new file mode 100644 index 000000000..dee751944 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/getConfig-response-filterContent-null.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/lock-response-all-parameters-not-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/lock-response-all-parameters-not-empty.xml new file mode 100644 index 000000000..1329e37b5 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/lock-response-all-parameters-not-empty.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/unlock-response-all-parameters-not-empty.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/unlock-response-all-parameters-not-empty.xml new file mode 100644 index 000000000..35a07f724 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/unlock-response-all-parameters-not-empty.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/validate-response.xml b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/validate-response.xml new file mode 100644 index 000000000..3947be6e2 --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/resources/netconf-messages/validate-response.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg