jaroslav@919
|
1 |
/**
|
jaroslav@919
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@919
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@919
|
4 |
*
|
jaroslav@919
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@919
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@919
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@919
|
8 |
*
|
jaroslav@919
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@919
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@919
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@919
|
12 |
* GNU General Public License for more details.
|
jaroslav@919
|
13 |
*
|
jaroslav@919
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@919
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@919
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@919
|
17 |
*/
|
jaroslav@919
|
18 |
package org.apidesign.bck2brwsr.htmlpage;
|
jaroslav@919
|
19 |
|
jaroslav@919
|
20 |
import java.util.Iterator;
|
jaroslav@919
|
21 |
import org.json.JSONException;
|
jaroslav@919
|
22 |
import org.json.JSONObject;
|
jaroslav@919
|
23 |
import org.json.JSONTokener;
|
jaroslav@919
|
24 |
import org.testng.annotations.Test;
|
jaroslav@919
|
25 |
import static org.testng.Assert.*;
|
jaroslav@919
|
26 |
|
jaroslav@919
|
27 |
/** Need to verify that models produce reasonable JSON objects.
|
jaroslav@919
|
28 |
*
|
jaroslav@919
|
29 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@919
|
30 |
*/
|
jaroslav@919
|
31 |
public class JSONTest {
|
jaroslav@919
|
32 |
|
jaroslav@919
|
33 |
@Test public void personToString() throws JSONException {
|
jaroslav@919
|
34 |
Person p = new Person();
|
jaroslav@919
|
35 |
p.setSex(Sex.MALE);
|
jaroslav@919
|
36 |
p.setFirstName("Jarda");
|
jaroslav@919
|
37 |
p.setLastName("Tulach");
|
jaroslav@919
|
38 |
|
jaroslav@919
|
39 |
JSONTokener t = new JSONTokener(p.toString());
|
jaroslav@919
|
40 |
JSONObject o;
|
jaroslav@919
|
41 |
try {
|
jaroslav@919
|
42 |
o = new JSONObject(t);
|
jaroslav@919
|
43 |
} catch (JSONException ex) {
|
jaroslav@919
|
44 |
throw new AssertionError("Can't parse " + p.toString(), ex);
|
jaroslav@919
|
45 |
}
|
jaroslav@919
|
46 |
|
jaroslav@919
|
47 |
Iterator it = o.sortedKeys();
|
jaroslav@919
|
48 |
assertEquals(it.next(), "firstName");
|
jaroslav@919
|
49 |
assertEquals(it.next(), "lastName");
|
jaroslav@919
|
50 |
assertEquals(it.next(), "sex");
|
jaroslav@919
|
51 |
|
jaroslav@919
|
52 |
assertEquals(o.getString("firstName"), "Jarda");
|
jaroslav@919
|
53 |
assertEquals(o.getString("lastName"), "Tulach");
|
jaroslav@919
|
54 |
assertEquals(o.getString("sex"), "MALE");
|
jaroslav@919
|
55 |
}
|
jaroslav@919
|
56 |
|
jaroslav@919
|
57 |
|
jaroslav@919
|
58 |
}
|