Formatting Code base with ktlint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / netconf-executor / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / netconf / executor / api / NetconfMessageTest.kt
1 /*
2  * Copyright © 2019 Bell Canada
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api
18
19 import org.junit.Assert.assertFalse
20 import org.junit.Assert.assertTrue
21 import org.junit.Test
22 import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.RpcStatus
23
24 class NetconfMessageTest {
25     @Test
26     fun testSuccessfulDeviceResponse() {
27         val dr: DeviceResponse = genSuccessfulEmptyDeviceResponse()
28         assertTrue(dr.isSuccess())
29
30         val dr2: DeviceResponse = genSuccessfulEmptyDeviceResponse()
31         dr2.errorMessage = "some error msg"
32         assertFalse(dr2.isSuccess())
33     }
34
35     @Test
36     fun testUnsuccessfulDeviceResponse() {
37         val dr: DeviceResponse = genUnsuccessfulEmptyDeviceResponse()
38         assertFalse(dr.isSuccess())
39
40         // case 2: Success, but with error message
41         val dr2: DeviceResponse = genUnsuccessfulEmptyDeviceResponse()
42         dr2.errorMessage = "Some error message."
43         assertFalse(dr2.isSuccess())
44     }
45
46     // helper function to generate a device response
47     private fun genSuccessfulEmptyDeviceResponse(): DeviceResponse {
48         return DeviceResponse().apply {
49             status = RpcStatus.SUCCESS
50             errorMessage = ""
51             responseMessage = ""
52             requestMessage = ""
53         }
54     }
55
56     private fun genUnsuccessfulEmptyDeviceResponse(): DeviceResponse {
57         return DeviceResponse().apply {
58             status = RpcStatus.FAILURE
59             errorMessage = ""
60             responseMessage = ""
61             requestMessage = ""
62         }
63     }
64 }