Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-core / src / test / kotlin / org / onap / ccsdk / cds / controllerblueprints / core / utils / JacksonUtilsTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.cds.controllerblueprints.core.utils
19
20 import com.att.eelf.configuration.EELFLogger
21 import com.att.eelf.configuration.EELFManager
22 import org.junit.Test
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
24 import kotlin.test.assertNotNull
25 import kotlin.test.assertTrue
26
27 /**
28  * JacksonUtilsTest
29  * @author Brinda Santh
30  * ${DATA}
31  */
32 class JacksonUtilsTest {
33
34     private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
35
36     @Test
37     fun testJsonNodeFromClassPathFile() {
38         val filePath = "data/default-context.json"
39         JacksonUtils.jsonNodeFromClassPathFile(filePath)
40     }
41
42     @Test
43     fun testJsonNodeFromFile() {
44         val filePath = "src/test/resources/data/default-context.json"
45         JacksonUtils.jsonNodeFromFile(filePath)
46     }
47
48     @Test
49     fun testGetListFromJson() {
50         val content = "[\"good\",\"boy\" ]"
51         val nodeType = JacksonUtils.getListFromJson(content, String::class.java)
52         assertNotNull(nodeType, "Failed to get String array from content")
53     }
54
55
56     @Test
57     fun testJsonValue() {
58         val filePath = "data/alltype-data.json"
59         val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath)
60         assertNotNull(rootJson, "Failed to get all type data json node")
61         val intValue = rootJson.get("intValue")
62         assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value")
63         val floatValue = rootJson.get("floatValue")
64         assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value")
65         val stringValue = rootJson.get("stringValue")
66         assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value")
67         val booleanValue = rootJson.get("booleanValue")
68         assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value")
69         val arrayStringValue = rootJson.get("arrayStringValue")
70         assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value")
71         val mapValue = rootJson.get("mapValue")
72         assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value")
73
74         assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed")
75
76
77     }
78 }