2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.appc.util;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.openecomp.appc.util.JsonUtil;
28 import java.io.IOException;
29 import java.util.HashMap;
31 import java.util.Properties;
33 import static org.junit.Assert.*;
37 public class TestJsonUtil {
40 public void testConvertJsonStringToFlatMap() {
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) {
52 Assert.fail(e.toString());
57 public void testConvertJsonStringToFlatMapWithInnerJson() {
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) {
68 Assert.fail(e.toString());