test/jdk/javax/management/remote/rest/json/JsonParserTest.java
author hb
Mon, 01 Jan 2018 23:59:14 +0530
branchjmx-rest-api
changeset 56002 60ab3b595a8e
permissions -rw-r--r--
Lot of bug fixes Added test cases
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56002
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     1
package json;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     2
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     3
import com.oracle.jmx.remote.rest.json.JSONElement;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     4
import com.oracle.jmx.remote.rest.json.parser.JSONParser;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     5
import com.oracle.jmx.remote.rest.json.parser.ParseException;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     6
import com.oracle.jmx.remote.rest.json.parser.TokenMgrError;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     7
import org.testng.annotations.DataProvider;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     8
import org.testng.annotations.Test;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
     9
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    10
@Test
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    11
public class JsonParserTest {
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    12
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    13
    @DataProvider(name = "getOkStrings")
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    14
    Object[][] getOkStrings() {
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    15
        Object[][] output = new Object[5][1];
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    16
        output[0][0] = "\"ac" + "\nde\\bf\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    17
        output[1][0] = "\"abcd\\\"cdef\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    18
        output[2][0] = "\"abcd\\\\cdef\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    19
        output[3][0] = "\"abc\\rdcde\\f\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    20
        output[4][0] = "\"\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    21
        return output;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    22
    }
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    23
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    24
    @DataProvider(name = "getKoStrings")
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    25
    Object[][] getKoStrings() {
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    26
        Object[][] output = new Object[3][1];
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    27
        output[0][0] = "\"a\\ef\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    28
        output[1][0] = "\"abg\"cde\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    29
        output[2][0] = "\"a\\\bgcde\"";
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    30
        return output;
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    31
    }
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    32
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    33
    @Test(dataProvider = "getOkStrings")
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    34
    public void testOk(String input) throws ParseException {
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    35
        JSONParser parser = new JSONParser(input);
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    36
        System.out.println("Input: " + input + ", Output: " +parser.parse().toJsonString());
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    37
    }
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    38
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    39
    @Test(dataProvider = "getKoStrings")
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    40
    public void testKo(String input) {
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    41
        try{
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    42
            JSONParser parser = new JSONParser(input);
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    43
            JSONElement parse = parser.parse();
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    44
            System.out.println("Input: " + input + ", Output: " + parse.toJsonString());
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    45
            throw new RuntimeException("FAILED");
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    46
        } catch (ParseException ex) {
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    47
        } catch (TokenMgrError error) {}
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    48
    }
60ab3b595a8e Lot of bug fixes
hb
parents:
diff changeset
    49
}