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.features.model.utils;
\r
20 import static org.junit.Assert.assertNotNull;
\r
21 import static org.junit.Assert.assertTrue;
\r
22 import java.util.HashMap;
\r
23 import java.util.Map;
\r
24 import org.junit.Test;
\r
25 import com.fasterxml.jackson.databind.JsonNode;
\r
27 public class TransformationUtilsTest {
\r
30 public void testGetJson() {
\r
31 Map<String, Object> configparameters = new HashMap<String, Object>();
\r
32 configparameters.put("key", "value");
\r
33 String json = TransformationUtils.getJson(configparameters);
\r
34 assertTrue("{\"key\":\"value\"}".equals(json));
\r
38 public void testGetJsonNodeForString() {
\r
39 String content = "{\"key\":\"value\"}";
\r
40 JsonNode jsonNodeForString = TransformationUtils.getJsonNodeForString(content);
\r
41 assertNotNull(jsonNodeForString);
\r
45 public void testGetMapfromJson() {
\r
46 String content = "{\"key\":\"value\"}";
\r
47 Map<String, Object> mapfromJson = TransformationUtils.getMapfromJson(content);
\r
48 assertTrue(mapfromJson.size() == 1);
\r
49 assertTrue("value".equals(mapfromJson.get("key")));
\r
53 public void testGetMapfromJsonString() {
\r
54 String content = "{\"key\":\"value\"}";
\r
55 Map<String, Object> mapfromJson = TransformationUtils.getMapfromJsonString(content);
\r
56 assertTrue(mapfromJson.size() == 1);
\r
57 assertTrue("value".equals(mapfromJson.get("key")));
\r
61 public void testConvertJson2RootProperties() throws Exception {
\r
62 Map<String, String> context = new HashMap<String, String>();
\r
63 String jsonContent = "{\"key\":\"value\"}";
\r
64 Map<String, String> convertJson2RootProperties =
\r
65 TransformationUtils.convertJson2RootProperties(context, jsonContent);
\r
66 assertTrue(convertJson2RootProperties.size() == 1);
\r
67 assertTrue("value".equals(convertJson2RootProperties.get("key")));
\r
70 @SuppressWarnings("unchecked")
\r
72 public void testGetJsonNodeAndTreeToValueAndConvertJson2Properties() throws Exception {
\r
73 Map<String, String> configparameters = new HashMap<String, String>();
\r
74 configparameters.put("key", "value");
\r
75 JsonNode jsonNode = TransformationUtils.getJsonNode(configparameters);
\r
76 assertNotNull(jsonNode);
\r
78 Map<String, String> result = TransformationUtils.treeToValue(jsonNode, HashMap.class);
\r
79 assertTrue("value".equals(result.get("key")));
\r
81 result = TransformationUtils.convertJson2Properties(null, jsonNode, null);
\r
82 assertTrue("value".equals(result.get("key")));
\r
86 public void testGetJsonSchema() {
\r
87 String jsonSchema = TransformationUtils.getJsonSchema(String.class);
\r
88 assertNotNull(jsonSchema);
\r