@@ -0,0 +1,3246 @@
+/*%0A * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * WSO2 Inc. licenses this file to you under the Apache License,%0A * Version 2.0 (the %22License%22); you may not use this file except%0A * in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage org.wso2.carbon.uuf.renderablecreator.hbs.internal.serialize;%0A%0Aimport jdk.nashorn.api.scripting.NashornScriptEngineFactory;%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.testng.Assert;%0Aimport org.testng.annotations.DataProvider;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.io.IOException;%0Aimport java.util.List;%0Aimport javax.script.Bindings;%0Aimport javax.script.ScriptContext;%0Aimport javax.script.ScriptEngine;%0Aimport javax.script.ScriptException;%0A%0A/**%0A * Created by sajith on 5/9/17.%0A */%0Apublic class JsonSerializerTest %7B%0A%0A    private static final int NUMBER_OF_TESTS = 6;%0A%0A    @DataProvider%0A    public Object%5B%5D%5B%5D safeTestData() throws IOException %7B%0A        return getTestData(%22output%22);%0A    %7D%0A%0A    @DataProvider%0A    public Object%5B%5D%5B%5D prettyTestData() throws IOException %7B%0A        return getTestData(%22pretty-output%22);%0A    %7D%0A%0A    @Test(dataProvider = %22safeTestData%22)%0A    public void testToJson(String jsScript, String expectedJson) throws ScriptException %7B%0A        Object jsObject = executeJavaScript(jsScript).get(%22input%22);%0A        String actualJson = JsonSerializer.toSafeJson(jsObject);%0A        Assert.assertEquals(actualJson, expectedJson);%0A    %7D%0A%0A    @Test(dataProvider = %22prettyTestData%22)%0A    public void testToPrettyJson(String jsScript, String expectedJson) throws ScriptException %7B%0A        Object jsObject = executeJavaScript(jsScript).get(%22input%22);%0A        String actualJson = JsonSerializer.toPrettyJson(jsObject);%0A        Assert.assertEquals(actualJson, expectedJson);%0A    %7D%0A%0A    private static Object%5B%5D%5B%5D getTestData(String outputFileNamePrefix) throws IOException %7B%0A        Object%5B%5D%5B%5D data = new Object%5BNUMBER_OF_TESTS%5D%5B2%5D;%0A        for (int i = 1; i %3C= NUMBER_OF_TESTS; i++) %7B%0A            data%5Bi - 1%5D = new Object%5B%5D%7BreadResource(%22/serialize/input%22 + i + %22.js%22),%0A                    readResource(%22/serialize/%22 + outputFileNamePrefix + i + %22.txt%22)%7D;%0A        %7D%0A        return data;%0A    %7D%0A%0A    private static String readResource(String path) throws IOException %7B%0A        List%3CString%3E lines = IOUtils.readLines(JsonSerializerTest.class.getResourceAsStream(path),%0A                                               %22UTF-8%22);%0A        return String.join(%22%5Cn%22, lines);%0A    %7D%0A%0A    private static Bindings executeJavaScript(String jsScript) throws ScriptException %7B%0A        NashornScriptEngineFactory scriptEngineFactory = new NashornScriptEngineFactory();%0A        ScriptEngine engine = scriptEngineFactory.getScriptEngine(%22-strict%22, %22--optimistic-types%22);%0A        engine.eval(jsScript);%0A        return engine.getBindings(ScriptContext.ENGINE_SCOPE);%0A    %7D%0A%7D%0A

add JsonSerializerTest test class