| 30 |
ashish |
1 |
/*
|
|
|
2 |
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
3 |
* or more contributor license agreements. See the NOTICE file
|
|
|
4 |
* distributed with this work for additional information
|
|
|
5 |
* regarding copyright ownership. The ASF licenses this file
|
|
|
6 |
* to you under the Apache License, Version 2.0 (the
|
|
|
7 |
* "License"); you may not use this file except in compliance
|
|
|
8 |
* with the License. You may obtain a copy of the License at
|
|
|
9 |
*
|
|
|
10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
11 |
*
|
|
|
12 |
* Unless required by applicable law or agreed to in writing,
|
|
|
13 |
* software distributed under the License is distributed on an
|
|
|
14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
15 |
* KIND, either express or implied. See the License for the
|
|
|
16 |
* specific language governing permissions and limitations
|
|
|
17 |
* under the License.
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
package org.apache.thrift.test;
|
|
|
21 |
|
|
|
22 |
// Generated code
|
|
|
23 |
import java.util.ArrayList;
|
|
|
24 |
import java.util.HashMap;
|
|
|
25 |
import java.util.HashSet;
|
|
|
26 |
import java.util.List;
|
|
|
27 |
|
|
|
28 |
import org.apache.thrift.protocol.TJSONProtocol;
|
|
|
29 |
import org.apache.thrift.transport.TMemoryBuffer;
|
|
|
30 |
|
|
|
31 |
import thrift.test.Base64;
|
|
|
32 |
import thrift.test.Bonk;
|
|
|
33 |
import thrift.test.HolyMoley;
|
|
|
34 |
import thrift.test.Nesting;
|
|
|
35 |
import thrift.test.OneOfEach;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Tests for the Java implementation of TJSONProtocol. Mirrors the C++ version
|
|
|
39 |
*
|
|
|
40 |
*/
|
|
|
41 |
public class JSONProtoTest {
|
|
|
42 |
|
|
|
43 |
public static void main(String [] args) throws Exception {
|
|
|
44 |
try {
|
|
|
45 |
System.out.println("In JSON Proto test");
|
|
|
46 |
|
|
|
47 |
OneOfEach ooe = Fixtures.oneOfEach;
|
|
|
48 |
Nesting n = Fixtures.nesting;
|
|
|
49 |
|
|
|
50 |
HolyMoley hm = Fixtures.holyMoley;
|
|
|
51 |
|
|
|
52 |
TMemoryBuffer buffer = new TMemoryBuffer(1024);
|
|
|
53 |
TJSONProtocol proto = new TJSONProtocol(buffer);
|
|
|
54 |
|
|
|
55 |
System.out.println("Writing ooe");
|
|
|
56 |
ooe.write(proto);
|
|
|
57 |
System.out.println("Reading ooe");
|
|
|
58 |
OneOfEach ooe2 = new OneOfEach();
|
|
|
59 |
ooe2.read(proto);
|
|
|
60 |
|
|
|
61 |
System.out.println("Comparing ooe");
|
|
|
62 |
if (!ooe.equals(ooe2)) {
|
|
|
63 |
throw new RuntimeException("ooe != ooe2");
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
System.out.println("Writing hm");
|
|
|
67 |
hm.write(proto);
|
|
|
68 |
|
|
|
69 |
System.out.println("Reading hm");
|
|
|
70 |
HolyMoley hm2 = new HolyMoley();
|
|
|
71 |
hm2.read(proto);
|
|
|
72 |
|
|
|
73 |
System.out.println("Comparing hm");
|
|
|
74 |
if (!hm.equals(hm2)) {
|
|
|
75 |
throw new RuntimeException("hm != hm2");
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
hm2.big.get(0).a_bite = (byte)0xFF;
|
|
|
79 |
if (hm.equals(hm2)) {
|
|
|
80 |
throw new RuntimeException("hm should not equal hm2");
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
Base64 base = new Base64();
|
|
|
84 |
base.a = 123;
|
|
|
85 |
base.b1 = "1".getBytes("UTF-8");
|
|
|
86 |
base.b2 = "12".getBytes("UTF-8");
|
|
|
87 |
base.b3 = "123".getBytes("UTF-8");
|
|
|
88 |
base.b4 = "1234".getBytes("UTF-8");
|
|
|
89 |
base.b5 = "12345".getBytes("UTF-8");
|
|
|
90 |
base.b6 = "123456".getBytes("UTF-8");
|
|
|
91 |
|
|
|
92 |
System.out.println("Writing base");
|
|
|
93 |
base.write(proto);
|
|
|
94 |
|
|
|
95 |
System.out.println("Reading base");
|
|
|
96 |
Base64 base2 = new Base64();
|
|
|
97 |
base2.read(proto);
|
|
|
98 |
|
|
|
99 |
System.out.println("Comparing base");
|
|
|
100 |
if (!base.equals(base2)) {
|
|
|
101 |
throw new RuntimeException("base != base2");
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
} catch (Exception ex) {
|
|
|
105 |
ex.printStackTrace();
|
|
|
106 |
throw ex;
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
}
|