f73bc1af20ccbd75ac17408258a06616189512f5
[ccsdk/features.git] /
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  * \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
8  * \r
9  * http://www.apache.org/licenses/LICENSE-2.0\r
10  * \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
16  */\r
17 \r
18 package org.onap.ccsdk.features.model.utils;\r
19 \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
26 \r
27 public class TransformationUtilsTest {\r
28 \r
29     @Test\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
35     }\r
36 \r
37     @Test\r
38     public void testGetJsonNodeForString() {\r
39         String content = "{\"key\":\"value\"}";\r
40         JsonNode jsonNodeForString = TransformationUtils.getJsonNodeForString(content);\r
41         assertNotNull(jsonNodeForString);\r
42     }\r
43 \r
44     @Test\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
50     }\r
51 \r
52     @Test\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
58     }\r
59 \r
60     @Test\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
68     }\r
69 \r
70     @SuppressWarnings("unchecked")\r
71     @Test\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
77 \r
78         Map<String, String> result = TransformationUtils.treeToValue(jsonNode, HashMap.class);\r
79         assertTrue("value".equals(result.get("key")));\r
80 \r
81         result = TransformationUtils.convertJson2Properties(null, jsonNode, null);\r
82         assertTrue("value".equals(result.get("key")));\r
83     }\r
84 \r
85     @Test\r
86     public void testGetJsonSchema() {\r
87         String jsonSchema = TransformationUtils.getJsonSchema(String.class);\r
88         assertNotNull(jsonSchema);\r
89     }\r
90 }\r