55985
|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
import javax.management.remote.rest.json.JSONElement;
|
|
5 |
import javax.management.remote.rest.json.parser.JSONParser;
|
|
6 |
import javax.management.remote.rest.json.parser.ParseException;
|
|
7 |
import org.testng.Assert;
|
|
8 |
import org.testng.annotations.AfterClass;
|
|
9 |
import org.testng.annotations.AfterMethod;
|
|
10 |
import org.testng.annotations.BeforeClass;
|
|
11 |
import org.testng.annotations.BeforeMethod;
|
|
12 |
import org.testng.annotations.DataProvider;
|
|
13 |
import org.testng.annotations.Test;
|
|
14 |
|
|
15 |
/**
|
|
16 |
*
|
|
17 |
* @author harsha
|
|
18 |
*/
|
|
19 |
public class JsonParserTest {
|
|
20 |
|
|
21 |
public JsonParserTest() {
|
|
22 |
}
|
|
23 |
|
|
24 |
// TODO add test methods here.
|
|
25 |
// The methods must be annotated with annotation @Test. For example:
|
|
26 |
//
|
|
27 |
// @Test
|
|
28 |
// public void hello() {}
|
|
29 |
|
|
30 |
@BeforeClass
|
|
31 |
public static void setUpClass() throws Exception {
|
|
32 |
}
|
|
33 |
|
|
34 |
@AfterClass
|
|
35 |
public static void tearDownClass() throws Exception {
|
|
36 |
}
|
|
37 |
|
|
38 |
@BeforeMethod
|
|
39 |
public void setUpMethod() throws Exception {
|
|
40 |
}
|
|
41 |
|
|
42 |
@AfterMethod
|
|
43 |
public void tearDownMethod() throws Exception {
|
|
44 |
}
|
|
45 |
|
|
46 |
@DataProvider
|
|
47 |
public Object[][] getJsonString() {
|
|
48 |
Object[][] data = new Object[2][1];
|
|
49 |
data[0][0] = "{organisms:[\n" +
|
|
50 |
" {\n" +
|
|
51 |
" id:10929,\n" +
|
|
52 |
" name:\"Bovine Rotavirus\"\n" +
|
|
53 |
" },\n" +
|
|
54 |
" {\n" +
|
|
55 |
" id:9606,\n" +
|
|
56 |
" name:\"Homo Sapiens\"\n" +
|
|
57 |
" }\n" +
|
|
58 |
" ],\n" +
|
|
59 |
"proteins:[\n" +
|
|
60 |
" {\n" +
|
|
61 |
" label:\"NSP3\",\n" +
|
|
62 |
" description:\"Rotavirus Non Structural Protein 3\",\n" +
|
|
63 |
" organism-id: 10929,\n" +
|
|
64 |
" acc: \"ACB38353\"\n" +
|
|
65 |
" },\n" +
|
|
66 |
" {\n" +
|
|
67 |
" label:\"EIF4G\",\n" +
|
|
68 |
" description:\"eukaryotic translation initiation factor 4 gamma\",\n" +
|
|
69 |
" organism-id: 9606,\n" +
|
|
70 |
" boolflag: true,\n" +
|
|
71 |
" longFloat: 12351123.1235123e-10,\n" +
|
|
72 |
" singleQuote: \'asd\',\n" +
|
|
73 |
" acc:\"AAI40897\"\n" +
|
|
74 |
" }\n" +
|
|
75 |
" ],\n" +
|
|
76 |
"interactions:[\n" +
|
|
77 |
" {\n" +
|
|
78 |
" label:\"NSP3 interacts with EIF4G1\",\n" +
|
|
79 |
" pubmed-id:[77120248,38201627],\n" +
|
|
80 |
" proteins:[\"ACB38353\",\"AAI40897\"]\n" +
|
|
81 |
" }\n" +
|
|
82 |
" ]}";
|
|
83 |
|
|
84 |
data[1][0] = "{\"name\":\"com.example:type=QueueSampler\",\"exec\":\"testMethod1\",\"params\":[[1,2,3],\"abc\",5,[\"asd\",\"3\",\"67\",\"778\"],[{date:\"2016-3-2\",size:3,head:\"head\"}],[{date:\"2016-3-2\",size:3,head:\"head\"}]]}";
|
|
85 |
return data;
|
|
86 |
}
|
|
87 |
|
|
88 |
@Test (dataProvider = "getJsonString")
|
|
89 |
public void parserTest(String input) throws ParseException {
|
|
90 |
JSONParser jsonParser = new JSONParser(input);
|
|
91 |
JSONElement parse = jsonParser.parse();
|
|
92 |
String output = parse.toJsonString();
|
|
93 |
System.out.println("\t: " + input);
|
|
94 |
System.out.println("\t: " + output);
|
|
95 |
// Assert.assertEquals(input, output);
|
|
96 |
}
|
|
97 |
}
|