2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 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.
18 package org.onap.ccsdk.cds.controllerblueprints.core.utils
21 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
22 import org.slf4j.LoggerFactory
23 import kotlin.test.assertNotNull
24 import kotlin.test.assertTrue
28 * @author Brinda Santh
31 class JacksonUtilsTest {
33 private val log = LoggerFactory.getLogger(this::class.toString())
36 fun testJsonNodeFromClassPathFile() {
37 val filePath = "data/default-context.json"
38 JacksonUtils.jsonNodeFromClassPathFile(filePath)
42 fun testJsonNodeFromFile() {
43 val filePath = "src/test/resources/data/default-context.json"
44 JacksonUtils.jsonNodeFromFile(filePath)
48 fun testGetListFromJson() {
49 val content = "[\"good\",\"boy\" ]"
50 val nodeType = JacksonUtils.getListFromJson(content, String::class.java)
51 assertNotNull(nodeType, "Failed to get String array from content")
56 val filePath = "data/alltype-data.json"
57 val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath)
58 assertNotNull(rootJson, "Failed to get all type data json node")
59 val intValue = rootJson.get("intValue")
60 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value")
61 val floatValue = rootJson.get("floatValue")
62 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value")
63 val stringValue = rootJson.get("stringValue")
64 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value")
65 val booleanValue = rootJson.get("booleanValue")
66 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value")
67 val arrayStringValue = rootJson.get("arrayStringValue")
68 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value")
69 // FIX needed for ("complex type JSON & MAP")
70 // val mapValue = rootJson.get("mapValue")
71 // assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value")
73 assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed")