blob: 707a4c2575daf074b439411b5380b69870836165 [file] [log] [blame]
Bryan Duxburyafa80ea2009-01-15 23:47:51 +00001package org.apache.thrift.test;
David Reiss25be92b2009-01-05 21:02:58 +00002
3import java.util.LinkedList;
4import thrift.test.OneOfEachBeans;
5
6public class JavaBeansTest {
7 public static void main(String[] args) throws Exception {
8 // Test isSet methods
9 OneOfEachBeans ooe = new OneOfEachBeans();
10
11 // Nothing should be set
12 if (ooe.is_set_a_bite())
13 throw new RuntimeException("isSet method error: unset field returned as set!");
14 if (ooe.is_set_base64())
15 throw new RuntimeException("isSet method error: unset field returned as set!");
16 if (ooe.is_set_byte_list())
17 throw new RuntimeException("isSet method error: unset field returned as set!");
18 if (ooe.is_set_double_precision())
19 throw new RuntimeException("isSet method error: unset field returned as set!");
20 if (ooe.is_set_i16_list())
21 throw new RuntimeException("isSet method error: unset field returned as set!");
22 if (ooe.is_set_i64_list())
23 throw new RuntimeException("isSet method error: unset field returned as set!");
24 if (ooe.is_set_boolean_field())
25 throw new RuntimeException("isSet method error: unset field returned as set!");
26 if (ooe.is_set_integer16())
27 throw new RuntimeException("isSet method error: unset field returned as set!");
28 if (ooe.is_set_integer32())
29 throw new RuntimeException("isSet method error: unset field returned as set!");
30 if (ooe.is_set_integer64())
31 throw new RuntimeException("isSet method error: unset field returned as set!");
32 if (ooe.is_set_some_characters())
33 throw new RuntimeException("isSet method error: unset field returned as set!");
34
35 for (int i = 1; i < 12; i++){
36 if (ooe.isSet(i))
37 throw new RuntimeException("isSet method error: unset field " + i + " returned as set!");
38 }
39
40 // Everything is set
41 ooe.set_a_bite((byte) 1);
42 ooe.set_base64("bytes".getBytes());
43 ooe.set_byte_list(new LinkedList());
44 ooe.set_double_precision(1);
45 ooe.set_i16_list(new LinkedList());
46 ooe.set_i64_list(new LinkedList());
47 ooe.set_boolean_field(true);
48 ooe.set_integer16((short) 1);
49 ooe.set_integer32(1);
50 ooe.set_integer64(1);
51 ooe.set_some_characters("string");
52
53 if (!ooe.is_set_a_bite())
54 throw new RuntimeException("isSet method error: set field returned as unset!");
55 if (!ooe.is_set_base64())
56 throw new RuntimeException("isSet method error: set field returned as unset!");
57 if (!ooe.is_set_byte_list())
58 throw new RuntimeException("isSet method error: set field returned as unset!");
59 if (!ooe.is_set_double_precision())
60 throw new RuntimeException("isSet method error: set field returned as unset!");
61 if (!ooe.is_set_i16_list())
62 throw new RuntimeException("isSet method error: set field returned as unset!");
63 if (!ooe.is_set_i64_list())
64 throw new RuntimeException("isSet method error: set field returned as unset!");
65 if (!ooe.is_set_boolean_field())
66 throw new RuntimeException("isSet method error: set field returned as unset!");
67 if (!ooe.is_set_integer16())
68 throw new RuntimeException("isSet method error: set field returned as unset!");
69 if (!ooe.is_set_integer32())
70 throw new RuntimeException("isSet method error: set field returned as unset!");
71 if (!ooe.is_set_integer64())
72 throw new RuntimeException("isSet method error: set field returned as unset!");
73 if (!ooe.is_set_some_characters())
74 throw new RuntimeException("isSet method error: set field returned as unset!");
75
76 for (int i = 1; i < 12; i++){
77 if (!ooe.isSet(i))
78 throw new RuntimeException("isSet method error: set field " + i + " returned as unset!");
79 }
80
81 // Should throw exception when field doesn't exist
82 boolean exceptionThrown = false;
83 try{
84 if (ooe.isSet(100));
85 } catch (IllegalArgumentException e){
86 exceptionThrown = true;
87 }
88 if (!exceptionThrown)
89 throw new RuntimeException("isSet method error: non-existent field provided as agument but no exception thrown!");
90 }
91}