Elffuss BraidHub

kikocis/java-driver public

Extend DataType integration test to cover BoundStatement getters.
Changeset54bf5eab84393c161d557c763726e50936be8c04d548bc99f4b0a5aaaaa4746d
Authorolim7t <omichallat+github@gmail.com> · 2015-03-23 19:54 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-03-27 10:56 +01:00
Parentsfef94230b0fd

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/DataTypeIntegrationTest.java +58 −2
@@ -24,6 +24,7 @@
2424 import org.testng.annotations.Test;
2525
2626 import static org.assertj.core.api.Assertions.assertThat;
27+import static org.assertj.core.api.Assertions.fail;
2728
2829 import com.datastax.driver.core.utils.CassandraVersion;
2930
@@ -90,7 +91,9 @@
9091 break;
9192 case PREPARED:
9293 PreparedStatement ps = session.prepare(table.insertStatement);
93- session.execute(ps.bind(table.sampleValue));
94+ BoundStatement bs = ps.bind(table.sampleValue);
95+ checkGetterReturnsBoundValue(bs, table);
96+ session.execute(bs);
9497 break;
9598 }
9699
@@ -109,6 +112,14 @@
109112 }
110113 }
111114
115+ private void checkGetterReturnsBoundValue(BoundStatement bs, TestTable table) {
116+ Object getterResult = getBoundValue(bs, table.testColumnType);
117+ assertThat(getterResult).isEqualTo(table.sampleValue);
118+
119+ // Ensure that bs.getObject() also returns the expected value.
120+ assertThat(bs.getObject(0)).isEqualTo(table.sampleValue);
121+ }
122+
112123 /**
113124 * Abstracts information about a table (corresponding to a given column type).
114125 */
@@ -181,4 +192,49 @@
181192 }
182193 return tables;
183194 }
184-}
No newline at the end of the file
195+
196+ private Object getBoundValue(BoundStatement bs, DataType dataType) {
197+ // This is kind of lame, but better than testing all getters manually
198+ switch (dataType.getName()) {
199+ case ASCII:
200+ return bs.getString(0);
201+ case BIGINT:
202+ return bs.getLong(0);
203+ case BLOB:
204+ return bs.getBytes(0);
205+ case BOOLEAN:
206+ return bs.getBool(0);
207+ case DECIMAL:
208+ return bs.getDecimal(0);
209+ case DOUBLE:
210+ return bs.getDouble(0);
211+ case FLOAT:
212+ return bs.getFloat(0);
213+ case INET:
214+ return bs.getInet(0);
215+ case INT:
216+ return bs.getInt(0);
217+ case TEXT:
218+ case VARCHAR:
219+ return bs.getString(0);
220+ case TIMESTAMP:
221+ return bs.getDate(0);
222+ case UUID:
223+ case TIMEUUID:
224+ return bs.getUUID(0);
225+ case VARINT:
226+ return bs.getVarint(0);
227+ case LIST:
228+ return bs.getList(0, dataType.getTypeArguments().get(0).asJavaClass());
229+ case SET:
230+ return bs.getSet(0, dataType.getTypeArguments().get(0).asJavaClass());
231+ case MAP:
232+ return bs.getMap(0, dataType.getTypeArguments().get(0).asJavaClass(), dataType.getTypeArguments().get(1).asJavaClass());
233+ case CUSTOM:
234+ case COUNTER:
235+ default:
236+ fail("Unexpected type in bound statement test: " + dataType);
237+ return null;
238+ }
239+ }
240+}