Controller Blueprints Nitrogen to Oxygen Migration
[ccsdk/features.git] / blueprints-processor / plugin / model-provider / src / test / java / org / onap / ccsdk / features / model / utils / TransformationUtilsTest.java
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 \r
27 import com.fasterxml.jackson.databind.JsonNode;\r
28 \r
29 public class TransformationUtilsTest {\r
30 \r
31     @Test\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
37     }\r
38 \r
39     @Test\r
40     public void testGetJsonNodeForString() {\r
41         String content = "{\"key\":\"value\"}";\r
42         JsonNode jsonNodeForString = TransformationUtils.getJsonNodeForString(content);\r
43         assertNotNull(jsonNodeForString);\r
44     }\r
45 \r
46     @Test\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
52     }\r
53 \r
54     @Test\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
60     }\r
61 \r
62     @Test\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
70     }\r
71 \r
72     @SuppressWarnings("unchecked")\r
73     @Test\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
79 \r
80         Map<String, String> result = TransformationUtils.treeToValue(jsonNode, HashMap.class);\r
81         assertTrue("value".equals(result.get("key")));\r
82 \r
83         result = TransformationUtils.convertJson2Properties(null, jsonNode, null);\r
84         assertTrue("value".equals(result.get("key")));\r
85     }\r
86 \r
87     @Test\r
88     public void testGetJsonSchema() {\r
89         String jsonSchema = TransformationUtils.getJsonSchema(String.class);\r
90         assertNotNull(jsonSchema);\r
91     }\r
92 }\r