diff options
Diffstat (limited to 'appc-config/appc-config-generator/provider/src/test/java/org')
-rw-r--r-- | appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestJSONTool.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestJSONTool.java b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestJSONTool.java new file mode 100644 index 000000000..fcc0c7c27 --- /dev/null +++ b/appc-config/appc-config-generator/provider/src/test/java/org/onap/sdnc/config/generator/tool/TestJSONTool.java @@ -0,0 +1,42 @@ +package org.onap.sdnc.config.generator.tool; + +import org.codehaus.jettison.json.JSONException; +import org.junit.Assert; +import org.junit.Test; + +public class TestJSONTool { + + @Test + public void testEscapeInternalJson() { + String testData = "{\"test1\":\"value1\",\"test2\":\"{\"key1\":\"value\"}\"}"; + String expectedOutput = "{\"test1\":\"value1\",\"test2\":\"{\\\"key1\\\":\\\"value\\\"}\"}"; + try { + Assert.assertEquals(expectedOutput, JSONTool.escapeInternalJson(testData)); + } catch (JSONException e) { + Assert.fail(); + } + } + + @Test + public void testEscapeInternalJson_alreadyEscaped() { + String testData = "{\"test1\":\"value1\",\"test2\":\"{\\\"key1\\\":\\\"value\\\"}\"}"; + String expectedOutput = "{\"test1\":\"value1\",\"test2\":\"{\\\"key1\\\":\\\"value\\\"}\"}"; + try { + Assert.assertEquals(expectedOutput, JSONTool.escapeInternalJson(testData)); + } catch (JSONException e) { + Assert.fail(); + } + } + + @Test + public void testEscapeInternalJson_withNewLines() { + String testData = "{\"test1\":\"value1\",\"test2\":\"\n{\"key1\":\"value\"\n}\"}"; + String expectedOutput = "{\"test1\":\"value1\",\"test2\":\"\n{\\\"key1\\\":\\\"value\\\"\n}\"}"; + try { + Assert.assertEquals(expectedOutput, JSONTool.escapeInternalJson(testData)); + } catch (JSONException e) { + Assert.fail(); + } + } + +} |