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