2 * Copyright © 2019 Bell Canada
3 * Modifications Copyright (c) 2019 IBM
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils
19 import org.junit.Assert.assertEquals
20 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfException
21 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
22 import kotlin.test.Test
23 import kotlin.test.assertFailsWith
25 class NetconfMessageUtilsTest {
28 fun `test getConfig with all parameters present`() {
29 val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType", "customFilterContent")
30 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/getConfig-response-all-parameters.xml")
31 assertEquals("getConfig return was not correct", expectation, outcome)
35 fun `test get operational`() {
36 val outcome = NetconfMessageUtils.get("customMessageId", "customConfigType")
37 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/get-response.xml")
38 assertEquals("get return was not correct", expectation, outcome)
42 fun `test getConfig with filterContent parameter null`() {
43 val outcome = NetconfMessageUtils.getConfig("customMessageId", "customConfigType",null)
44 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/getConfig-response-filterContent-null.xml")
45 assertEquals("getConfig return was not correct", expectation, outcome)
49 fun `test doWrappedRpc`() {
50 val outcome = NetconfMessageUtils.doWrappedRpc("customMessageId", "customRequest")
51 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/doWrappedRpc-response.xml")
52 assertEquals("doWrappedRpc return was not correct", expectation, outcome)
56 fun `test editConfig with all parameters present`() {
57 val outcome = NetconfMessageUtils.editConfig("customMessageId", "customConfigType", "customDefaultOperation",
58 "customNewConfiguration")
59 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/editConfig-response-all-parameters.xml")
60 assertEquals("editConfig return was not correct", expectation, outcome)
64 fun `test editConfig with defaultOperation parameter null`() {
65 val outcome = NetconfMessageUtils.editConfig("customMessageId", "customConfigType", null,
66 "customNewConfiguration")
67 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/editConfig-response-defaultOperation-null.xml")
68 assertEquals("editConfig return was not correct", expectation, outcome)
72 fun `test validate`() {
73 val outcome = NetconfMessageUtils.validate("customMessageId", "customConfigType")
74 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/validate-response.xml")
75 assertEquals("validate return was not correct", expectation, outcome)
79 fun `test commit with both persistId and persist non-empty`() {
80 assertFailsWith(exceptionClass = NetconfException::class, message = "commit should have thrown an exception") {
81 NetconfMessageUtils.commit("customMessageId", false, 1, "customPersist", "customPersistId")
86 fun `test commit with confirmed true, persist empty and persistId non-empty`() {
87 assertFailsWith(exceptionClass = NetconfException::class, message = "commit should have thrown an exception") {
88 NetconfMessageUtils.commit("customMessageId", true, 1, "", "customPersistId")
93 fun `test commit with confirmed true, persistId empty and persist empty`() {
94 val outcome = NetconfMessageUtils.commit("customMessageId", true, 1, "", "")
95 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-true-and-persistId-empty-and-persist-empty.xml")
96 assertEquals("commit return was not correct", expectation, outcome)
100 fun `test commit with confirmed false, persistId non-empty and persist empty`() {
101 val outcome = NetconfMessageUtils.commit("customMessageId", false, 1, "", "customPersistId")
102 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-empty-and-persist-not-empty.xml")
103 assertEquals("commit return was not correct", expectation, outcome)
107 fun `test commit with confirmed false, persistId empty and persist non-empty`() {
108 val outcome = NetconfMessageUtils.commit("customMessageId", false, 1, "customPersist", "")
109 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/commit-response-confirmed-false-and-persistId-not-empty-and-persist-empty.xml")
110 assertEquals("commit return was not correct", expectation, outcome)
114 fun `test cancelCommit with all parameters not empty`() {
115 val outcome = NetconfMessageUtils.cancelCommit("customMessageId", "customPersistId")
116 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/cancelCommit-response-all-parameters-not-empty.xml")
117 assertEquals("cancelCommit return was not correct", expectation, outcome)
121 fun `test cancelCommit with persistId empty`() {
122 val outcome = NetconfMessageUtils.cancelCommit("customMessageId", "")
123 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/cancelCommit-response-persistId-empty.xml")
124 assertEquals("cancelCommit return was not correct", expectation, outcome)
128 fun `test unlock with all parameters not empty`() {
129 val outcome = NetconfMessageUtils.unlock("customMessageId", "customConfigType")
130 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/unlock-response-all-parameters-not-empty.xml")
131 assertEquals("unlock return was not correct", expectation, outcome)
135 fun `test deleteConfig with all parameters not empty`() {
136 val outcome = NetconfMessageUtils.deleteConfig("customMessageId", "customConfigType")
137 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/deleteConfig-response-all-parameters-not-empty.xml")
138 assertEquals("deleteConfig return was not correct", expectation, outcome)
142 fun `test deleteConfig with configType equals to NetconfDatastore_RUNNING_datastore`() {
143 assertFailsWith(exceptionClass = NetconfException::class, message = "deleteConfig should have thrown an exception") {
144 NetconfMessageUtils.deleteConfig("customMessageId", NetconfDatastore.RUNNING.datastore)
149 fun `test discardChanges with all parameters not empty`() {
150 val outcome = NetconfMessageUtils.discardChanges("customMessageId")
151 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/discardChanges-response-all-parameters-not-empty.xml")
152 assertEquals("discardChanges return was not correct", expectation, outcome)
156 fun `test lock with all parameters not empty`() {
157 val outcome = NetconfMessageUtils.lock("customMessageId", "customConfigType")
158 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/lock-response-all-parameters-not-empty.xml")
159 assertEquals("lock return was not correct", expectation, outcome)
163 fun `test closeSession with force true`() {
164 val outcome = NetconfMessageUtils.closeSession("customMessageId", true)
165 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/closeSession-response-force-true.xml")
166 assertEquals("closeSession return was not correct", expectation, outcome)
170 fun `test closeSession with force false`() {
171 val outcome = NetconfMessageUtils.closeSession("customMessageId", false)
172 val expectation = JacksonUtils.getClassPathFileContent("netconf-messages/closeSession-response-force-false.xml")
173 assertEquals("closeSession return was not correct", expectation, outcome)
176 //TODO validateRPCXML
179 fun `test getMsgId with valid message`() {
180 val messageId = "1234"
181 val outcome = NetconfMessageUtils.getMsgId("message-id=\"${messageId}\"")
182 val expectation = messageId
183 assertEquals("getMsgId return was not correct", expectation, outcome)
187 fun `test getMsgId with RpcMessageUtils_HELLO message`() {
188 val outcome = NetconfMessageUtils.getMsgId(RpcMessageUtils.HELLO)
189 val expectation = "-1"
190 assertEquals("getMsgId return was not correct", expectation, outcome)
194 fun `test getMsgId with invalid message`() {
195 val outcome = NetconfMessageUtils.getMsgId("invalid message")
197 assertEquals("getMsgId return was not correct", expectation, outcome)
200 //TODO validateChunkedFraming