test/jdk/javax/management/remote/rest/json/JsonParserTest.java
branchjmx-rest-api
changeset 56004 da55d1429860
parent 56003 4f7f76f6be2f
child 56005 90cff2ac77b8
equal deleted inserted replaced
56003:4f7f76f6be2f 56004:da55d1429860
     1 package json;
       
     2 
       
     3 import com.oracle.jmx.remote.rest.json.JSONElement;
       
     4 import com.oracle.jmx.remote.rest.json.parser.JSONParser;
       
     5 import com.oracle.jmx.remote.rest.json.parser.ParseException;
       
     6 import com.oracle.jmx.remote.rest.json.parser.TokenMgrError;
       
     7 import org.testng.annotations.DataProvider;
       
     8 import org.testng.annotations.Test;
       
     9 
       
    10 @Test
       
    11 public class JsonParserTest {
       
    12 
       
    13     @DataProvider(name = "getOkStrings")
       
    14     Object[][] getOkStrings() {
       
    15         Object[][] output = new Object[5][1];
       
    16         output[0][0] = "\"ac" + "\nde\\bf\"";
       
    17         output[1][0] = "\"abcd\\\"cdef\"";
       
    18         output[2][0] = "\"abcd\\\\cdef\"";
       
    19         output[3][0] = "\"abc\\rdcde\\f\"";
       
    20         output[4][0] = "\"\"";
       
    21         return output;
       
    22     }
       
    23 
       
    24     @DataProvider(name = "getKoStrings")
       
    25     Object[][] getKoStrings() {
       
    26         Object[][] output = new Object[3][1];
       
    27         output[0][0] = "\"a\\ef\"";
       
    28         output[1][0] = "\"abg\"cde\"";
       
    29         output[2][0] = "\"a\\\bgcde\"";
       
    30         return output;
       
    31     }
       
    32 
       
    33     @Test(dataProvider = "getOkStrings")
       
    34     public void testOk(String input) throws ParseException {
       
    35         JSONParser parser = new JSONParser(input);
       
    36         System.out.println("Input: " + input + ", Output: " +parser.parse().toJsonString());
       
    37     }
       
    38 
       
    39     @Test(dataProvider = "getKoStrings")
       
    40     public void testKo(String input) {
       
    41         try{
       
    42             JSONParser parser = new JSONParser(input);
       
    43             JSONElement parse = parser.parse();
       
    44             System.out.println("Input: " + input + ", Output: " + parse.toJsonString());
       
    45             throw new RuntimeException("FAILED");
       
    46         } catch (ParseException ex) {
       
    47         } catch (TokenMgrError error) {}
       
    48     }
       
    49 }