-
Notifications
You must be signed in to change notification settings - Fork 76
/
DatastaxNumberTest.java
242 lines (198 loc) · 7.83 KB
/
DatastaxNumberTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package org.sfm.datastax;
import com.datastax.driver.core.Session;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sfm.reflect.ReflectionService;
import org.sfm.utils.LibrarySets;
import org.sfm.utils.MultiClassLoaderJunitRunner;
import java.math.BigDecimal;
import java.math.BigInteger;
import static org.junit.Assert.assertEquals;
@RunWith(MultiClassLoaderJunitRunner.class)
@LibrarySets(
librarySets = {
//IFJAVA8_START
"http://repo1.maven.org/maven2/com/datastax/cassandra/cassandra-driver-core/3.0.3/cassandra-driver-core-3.0.3.jar",
//IFJAVA8_END
"http://repo1.maven.org/maven2/com/datastax/cassandra/cassandra-driver-core/2.1.8/cassandra-driver-core-2.1.8.jar"
},
includes={ReflectionService.class, DatastaxCrud.class, DatastaxCrudTest.class},
excludes = { "org.junit", "org.sfm.datastax.DatastaxCrudTest", "io.netty"},
names={"v303", "v218"}
)
public class DatastaxNumberTest extends AbstractDatastaxTest {
@Before
public void prepareTable() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
session.execute("create table IF NOT EXISTS test_number(bi bigint primary key, i int, vi varint, dec decimal, f float, d double)");
if (session.execute("select * from test_number").isExhausted()) {
session.execute("insert into test_number(bi, i, vi, dec, f, d) values(1, 2, 3, 3.5, 3.7, 3.9)");
}
}
});
}
@Test
public void testGetFloat() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final FloatObject nObject = DatastaxMapperFactory.newInstance().mapTo(FloatObject.class).iterator(session.execute("select * from test_number")).next();
assertEquals(1.0, nObject.bi, 0.001);
assertEquals(2.0, nObject.i, 0.001);
assertEquals(3.0, nObject.vi, 0.001);
assertEquals(3.5, nObject.dec, 0.001);
assertEquals(3.7, nObject.f, 0.001);
assertEquals(3.9, nObject.d, 0.001);
}
});
}
public static class FloatObject {
public float bi;
public float i;
public float vi;
public float dec;
public float f;
public float d;
}
@Test
public void testGetDouble() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final DoubleObject nObject = DatastaxMapperFactory.newInstance().mapTo(DoubleObject.class).iterator(session.execute("select * from test_number")).next();
assertEquals(1.0, nObject.bi, 0.001);
assertEquals(2.0, nObject.i, 0.001);
assertEquals(3.0, nObject.vi, 0.001);
assertEquals(3.5, nObject.dec, 0.001);
assertEquals(3.7, nObject.f, 0.001);
assertEquals(3.9, nObject.d, 0.001);
}
});
}
public static class DoubleObject {
public double bi;
public double i;
public double vi;
public double dec;
public double f;
public double d;
}
@Test
public void testGetBigDecimal() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final BigDecimalObject nObject = DatastaxMapperFactory.newInstance().mapTo(BigDecimalObject.class).iterator(session.execute("select * from test_number")).next();
assertEquals(1.0, nObject.bi.doubleValue(), 0.001);
assertEquals(2.0, nObject.i.doubleValue(), 0.001);
assertEquals(3.0, nObject.vi.doubleValue(), 0.001);
assertEquals(3.5, nObject.dec.doubleValue(), 0.001);
assertEquals(3.7, nObject.f.doubleValue(), 0.001);
assertEquals(3.9, nObject.d.doubleValue(), 0.001);
}
});
}
public static class BigDecimalObject {
public BigDecimal bi;
public BigDecimal i;
public BigDecimal vi;
public BigDecimal dec;
public BigDecimal f;
public BigDecimal d;
}
@Test
public void testGetShort() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final ShortObject nObject = DatastaxMapperFactory.newInstance().mapTo(ShortObject.class).iterator(session.execute("select * from test_number")).next();
assertEquals(1, nObject.bi);
assertEquals(2, nObject.i);
assertEquals(3, nObject.vi);
assertEquals(3, nObject.dec);
assertEquals(3, nObject.f);
assertEquals(3, nObject.d);
}
});
}
public static class ShortObject {
public short bi;
public short i;
public short vi;
public short dec;
public short f;
public short d;
}
@Test
public void testGetInt() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final IntObject nObject = DatastaxMapperFactory.newInstance().mapTo(IntObject.class).iterator(session.execute("select * from test_number")).next();
assertEquals(1, nObject.bi);
assertEquals(2, nObject.i);
assertEquals(3, nObject.vi);
assertEquals(3, nObject.dec);
assertEquals(3, nObject.f);
assertEquals(3, nObject.d);
}
});
}
public static class IntObject {
public int bi;
public int i;
public int vi;
public int dec;
public int f;
public int d;
}
@Test
public void testGetLong() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final LongObject nObject = DatastaxMapperFactory.newInstance().mapTo(LongObject.class).iterator(session.execute("select * from test_number")).next();
assertEquals(1, nObject.bi);
assertEquals(2, nObject.i);
assertEquals(3, nObject.vi);
assertEquals(3, nObject.dec);
assertEquals(3, nObject.f);
assertEquals(3, nObject.d);
}
});
}
public static class LongObject {
public long bi;
public long i;
public long vi;
public long dec;
public long f;
public long d;
}
@Test
public void testGetBigInteger() throws Exception {
testInSession(new Callback() {
@Override
public void call(Session session) throws Exception {
final BigIntegerObject nObject = DatastaxMapperFactory.newInstance().mapTo(BigIntegerObject.class).iterator(session.execute("select * from test_number")).next();
assertEquals(1, nObject.bi.longValue());
assertEquals(2, nObject.i.longValue());
assertEquals(3, nObject.vi.longValue());
assertEquals(3, nObject.dec.longValue());
assertEquals(3, nObject.f.longValue());
assertEquals(3, nObject.d.longValue());
}
});
}
public static class BigIntegerObject {
public BigInteger bi;
public BigInteger i;
public BigInteger vi;
public BigInteger dec;
public BigInteger f;
public BigInteger d;
}
}