e24659d1d559dc5fc6ae4ef78c466ec6ab2c3d19
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / netconf-executor / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / netconf / executor / utils / NetconfMessageUtilsTest.kt
1 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils
2
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
8
9 class NetconfMessageUtilsTest {
10
11     @Test
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)
16     }
17
18     @Test
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)
23     }
24
25     @Test
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)
30     }
31
32     @Test
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)
38     }
39
40     @Test
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)
46     }
47
48     @Test
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)
53     }
54
55     @Test
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")
59         }
60     }
61
62     @Test
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")
66         }
67     }
68
69     @Test
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)
74     }
75
76     @Test
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)
81     }
82
83     @Test
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)
88     }
89
90     @Test
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)
95     }
96
97     @Test
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)
102     }
103
104     @Test
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)
109     }
110
111     @Test
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)
116     }
117
118     @Test
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)
122         }
123     }
124
125     @Test
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)
130     }
131
132     @Test
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)
137     }
138
139     @Test
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)
144     }
145
146     @Test
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)
151     }
152
153     //TODO validateRPCXML
154
155     @Test
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)
161     }
162
163     @Test
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)
168     }
169
170     @Test
171     fun `test getMsgId with invalid message`() {
172         val outcome = NetconfMessageUtils.getMsgId("invalid message")
173         val expectation = ""
174         assertEquals("getMsgId return was not correct", expectation, outcome)
175     }
176
177 //TODO validateChunkedFraming
178
179 }