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