| 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 |
import java.util.LinkedList;
|
|
|
23 |
import thrift.test.OneOfEachBeans;
|
|
|
24 |
|
|
|
25 |
public class JavaBeansTest {
|
|
|
26 |
public static void main(String[] args) throws Exception {
|
|
|
27 |
// Test isSet methods
|
|
|
28 |
OneOfEachBeans ooe = new OneOfEachBeans();
|
|
|
29 |
|
|
|
30 |
// Nothing should be set
|
|
|
31 |
if (ooe.is_set_a_bite())
|
|
|
32 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
33 |
if (ooe.is_set_base64())
|
|
|
34 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
35 |
if (ooe.is_set_byte_list())
|
|
|
36 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
37 |
if (ooe.is_set_double_precision())
|
|
|
38 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
39 |
if (ooe.is_set_i16_list())
|
|
|
40 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
41 |
if (ooe.is_set_i64_list())
|
|
|
42 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
43 |
if (ooe.is_set_boolean_field())
|
|
|
44 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
45 |
if (ooe.is_set_integer16())
|
|
|
46 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
47 |
if (ooe.is_set_integer32())
|
|
|
48 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
49 |
if (ooe.is_set_integer64())
|
|
|
50 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
51 |
if (ooe.is_set_some_characters())
|
|
|
52 |
throw new RuntimeException("isSet method error: unset field returned as set!");
|
|
|
53 |
|
|
|
54 |
for (int i = 1; i < 12; i++){
|
|
|
55 |
if (ooe.isSet(i))
|
|
|
56 |
throw new RuntimeException("isSet method error: unset field " + i + " returned as set!");
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// Everything is set
|
|
|
60 |
ooe.set_a_bite((byte) 1);
|
|
|
61 |
ooe.set_base64("bytes".getBytes());
|
|
|
62 |
ooe.set_byte_list(new LinkedList<Byte>());
|
|
|
63 |
ooe.set_double_precision(1);
|
|
|
64 |
ooe.set_i16_list(new LinkedList<Short>());
|
|
|
65 |
ooe.set_i64_list(new LinkedList<Long>());
|
|
|
66 |
ooe.set_boolean_field(true);
|
|
|
67 |
ooe.set_integer16((short) 1);
|
|
|
68 |
ooe.set_integer32(1);
|
|
|
69 |
ooe.set_integer64(1);
|
|
|
70 |
ooe.set_some_characters("string");
|
|
|
71 |
|
|
|
72 |
if (!ooe.is_set_a_bite())
|
|
|
73 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
74 |
if (!ooe.is_set_base64())
|
|
|
75 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
76 |
if (!ooe.is_set_byte_list())
|
|
|
77 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
78 |
if (!ooe.is_set_double_precision())
|
|
|
79 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
80 |
if (!ooe.is_set_i16_list())
|
|
|
81 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
82 |
if (!ooe.is_set_i64_list())
|
|
|
83 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
84 |
if (!ooe.is_set_boolean_field())
|
|
|
85 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
86 |
if (!ooe.is_set_integer16())
|
|
|
87 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
88 |
if (!ooe.is_set_integer32())
|
|
|
89 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
90 |
if (!ooe.is_set_integer64())
|
|
|
91 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
92 |
if (!ooe.is_set_some_characters())
|
|
|
93 |
throw new RuntimeException("isSet method error: set field returned as unset!");
|
|
|
94 |
|
|
|
95 |
for (int i = 1; i < 12; i++){
|
|
|
96 |
if (!ooe.isSet(i))
|
|
|
97 |
throw new RuntimeException("isSet method error: set field " + i + " returned as unset!");
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// Should throw exception when field doesn't exist
|
|
|
101 |
boolean exceptionThrown = false;
|
|
|
102 |
try{
|
|
|
103 |
if (ooe.isSet(100));
|
|
|
104 |
} catch (IllegalArgumentException e){
|
|
|
105 |
exceptionThrown = true;
|
|
|
106 |
}
|
|
|
107 |
if (!exceptionThrown)
|
|
|
108 |
throw new RuntimeException("isSet method error: non-existent field provided as agument but no exception thrown!");
|
|
|
109 |
}
|
|
|
110 |
}
|