2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.apps.controllerblueprints.core.utils
\r
20 import org.junit.Test
\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate
\r
23 import com.att.eelf.configuration.EELFLogger
\r
24 import com.att.eelf.configuration.EELFManager
\r
25 import kotlin.test.assertEquals
\r
26 import kotlin.test.assertNotNull
\r
27 import kotlin.test.assertTrue
\r
31 * @author Brinda Santh
\r
34 class JacksonUtilsTest {
\r
36 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
\r
38 val basePath = "load/blueprints"
\r
41 fun testReadValues() {
\r
42 val content = ResourceResolverUtils.getFileContent("baseconfiguration/Definitions/activation-blueprint.json", basePath)
\r
43 val serviceTemplate = JacksonUtils.readValue(content, ServiceTemplate::class.java)
\r
44 assertNotNull(serviceTemplate, "Failed to simple transform Service Template")
\r
45 assertEquals(true, serviceTemplate is ServiceTemplate, "failed to get Service Template instance")
\r
47 val jsonContent = JacksonUtils.getJson(serviceTemplate!!, true)
\r
48 assertNotNull(jsonContent, "Failed to get json content")
\r
52 fun testJsonNodeFromClassPathFile() {
\r
53 val filePath = "data/default-context.json"
\r
54 JacksonUtils.jsonNodeFromClassPathFile(filePath)
\r
58 fun testJsonNodeFromFile() {
\r
59 val filePath = basePath + "/baseconfiguration/Definitions/activation-blueprint.json"
\r
60 JacksonUtils.jsonNodeFromFile(filePath)
\r
64 fun testGetListFromJson() {
\r
65 val content = "[\"good\",\"boy\" ]"
\r
66 val nodeType = JacksonUtils.getListFromJson(content, String::class.java)
\r
67 assertNotNull(nodeType, "Failed to get String array from content")
\r
72 fun testJsonValue() {
\r
73 val filePath = "data/alltype-data.json"
\r
74 val rootJson = JacksonUtils.jsonNodeFromClassPathFile(filePath)
\r
75 assertNotNull(rootJson, "Failed to get all type data json node")
\r
76 val intValue = rootJson.get("intValue")
\r
77 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_INTEGER, intValue), "Failed to get as int value")
\r
78 val floatValue = rootJson.get("floatValue")
\r
79 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_FLOAT, floatValue), "Failed to get as float value")
\r
80 val stringValue = rootJson.get("stringValue")
\r
81 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_STRING, stringValue), "Failed to get as string value")
\r
82 val booleanValue = rootJson.get("booleanValue")
\r
83 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_BOOLEAN, booleanValue), "Failed to get as boolean value")
\r
84 val arrayStringValue = rootJson.get("arrayStringValue")
\r
85 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, arrayStringValue), "Failed to get as List value")
\r
86 val mapValue = rootJson.get("mapValue")
\r
87 assertTrue(JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_MAP, mapValue), "Failed to get as Map value")
\r
89 assertTrue(!JacksonUtils.checkJsonNodeValueOfType(BluePrintConstants.DATA_TYPE_LIST, stringValue), "Negative type failed")
\r