Moving all files to root directory
[appc.git] / appc-common / src / test / java / org / openecomp / appc / util / TestJsonUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.util;
23
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.openecomp.appc.util.JsonUtil;
27
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.Properties;
32
33 import static org.junit.Assert.*;
34
35
36
37 public class TestJsonUtil {
38
39     @Test
40     public void testConvertJsonStringToFlatMap() {
41         try {
42             String jsonString = "{\"A\":\"A-value\",\"B\":{\"C\":\"B.C-value\",\"D\":\"B.D-value\"}}";
43             Map<String, String> flatMap = JsonUtil.convertJsonStringToFlatMap(jsonString);
44             assertNotNull(flatMap);
45             Map<String, String> expectedMap = new HashMap<>();
46             expectedMap.put("A","A-value");
47             expectedMap.put("B.C","B.C-value");
48             expectedMap.put("B.D","B.D-value");
49             assertEquals(expectedMap,flatMap);
50         } catch (IOException e) {
51             e.printStackTrace();
52             Assert.fail(e.toString());
53         }
54     }
55
56     @Test
57     public void testConvertJsonStringToFlatMapWithInnerJson() {
58         try {
59             String jsonString = "{\"A\":\"A-value\",\"B\":\"{\\\"C\\\":\\\"C-value\\\",\\\"D\\\":\\\"D-value\\\"}\"}";
60             Map<String, String> flatMap = JsonUtil.convertJsonStringToFlatMap(jsonString);
61             assertNotNull(flatMap);
62             Map<String, String> expectedMap = new HashMap<>();
63             expectedMap.put("A","A-value");
64             expectedMap.put("B","{\"C\":\"C-value\",\"D\":\"D-value\"}");
65             assertEquals(expectedMap,flatMap);
66         } catch (IOException e) {
67             e.printStackTrace();
68             Assert.fail(e.toString());
69         }
70     }
71 }