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 org.onap.ccsdk.features.model.utils.TransformationUtils;
\r
27 import com.fasterxml.jackson.databind.JsonNode;
\r
29 public class TransformationUtilsTest {
\r
32 public void testGetJson() {
\r
33 Map<String, Object> configparameters = new HashMap<String, Object>();
\r
34 configparameters.put("key", "value");
\r
35 String json = TransformationUtils.getJson(configparameters);
\r
36 assertTrue("{\"key\":\"value\"}".equals(json));
\r
40 public void testGetJsonNodeForString() {
\r
41 String content = "{\"key\":\"value\"}";
\r
42 JsonNode jsonNodeForString = TransformationUtils.getJsonNodeForString(content);
\r
43 assertNotNull(jsonNodeForString);
\r
47 public void testGetMapfromJson() {
\r
48 String content = "{\"key\":\"value\"}";
\r
49 Map<String, Object> mapfromJson = TransformationUtils.getMapfromJson(content);
\r
50 assertTrue(mapfromJson.size() == 1);
\r
51 assertTrue("value".equals(mapfromJson.get("key")));
\r
55 public void testGetMapfromJsonString() {
\r
56 String content = "{\"key\":\"value\"}";
\r
57 Map<String, Object> mapfromJson = TransformationUtils.getMapfromJsonString(content);
\r
58 assertTrue(mapfromJson.size() == 1);
\r
59 assertTrue("value".equals(mapfromJson.get("key")));
\r
63 public void testConvertJson2RootProperties() throws Exception {
\r
64 Map<String, String> context = new HashMap<String, String>();
\r
65 String jsonContent = "{\"key\":\"value\"}";
\r
66 Map<String, String> convertJson2RootProperties =
\r
67 TransformationUtils.convertJson2RootProperties(context, jsonContent);
\r
68 assertTrue(convertJson2RootProperties.size() == 1);
\r
69 assertTrue("value".equals(convertJson2RootProperties.get("key")));
\r
72 @SuppressWarnings("unchecked")
\r
74 public void testGetJsonNodeAndTreeToValueAndConvertJson2Properties() throws Exception {
\r
75 Map<String, String> configparameters = new HashMap<String, String>();
\r
76 configparameters.put("key", "value");
\r
77 JsonNode jsonNode = TransformationUtils.getJsonNode(configparameters);
\r
78 assertNotNull(jsonNode);
\r
80 Map<String, String> result = TransformationUtils.treeToValue(jsonNode, HashMap.class);
\r
81 assertTrue("value".equals(result.get("key")));
\r
83 result = TransformationUtils.convertJson2Properties(null, jsonNode, null);
\r
84 assertTrue("value".equals(result.get("key")));
\r
88 public void testGetJsonSchema() {
\r
89 String jsonSchema = TransformationUtils.getJsonSchema(String.class);
\r
90 assertNotNull(jsonSchema);
\r