1 package org.onap.sdnc.config.generator.tool;
3 import org.codehaus.jettison.json.JSONException;
4 import org.junit.Assert;
7 public class TestJSONTool {
10 public void testEscapeInternalJson() {
11 String testData = "{\"test1\":\"value1\",\"test2\":\"{\"key1\":\"value\"}\"}";
12 String expectedOutput = "{\"test1\":\"value1\",\"test2\":\"{\\\"key1\\\":\\\"value\\\"}\"}";
14 Assert.assertEquals(expectedOutput, JSONTool.escapeInternalJson(testData));
15 } catch (JSONException e) {
21 public void testEscapeInternalJson_alreadyEscaped() {
22 String testData = "{\"test1\":\"value1\",\"test2\":\"{\\\"key1\\\":\\\"value\\\"}\"}";
23 String expectedOutput = "{\"test1\":\"value1\",\"test2\":\"{\\\"key1\\\":\\\"value\\\"}\"}";
25 Assert.assertEquals(expectedOutput, JSONTool.escapeInternalJson(testData));
26 } catch (JSONException e) {
32 public void testEscapeInternalJson_withNewLines() {
33 String testData = "{\"test1\":\"value1\",\"test2\":\"\n{\"key1\":\"value\"\n}\"}";
34 String expectedOutput = "{\"test1\":\"value1\",\"test2\":\"\n{\\\"key1\\\":\\\"value\\\"\n}\"}";
36 Assert.assertEquals(expectedOutput, JSONTool.escapeInternalJson(testData));
37 } catch (JSONException e) {