@@ -6,12 +6,11 @@ import org.joda.time.DateTime
6
6
import org .mongodb .scala .bson .collection .immutable .Document
7
7
import org .mongodb .scala .model .Updates
8
8
9
- import java .sql .{ Date , ResultSet , SQLFeatureNotSupportedException , Time , Timestamp }
9
+ import java .sql .*
10
10
11
11
class MongoDbResultSetSuite extends BaseJdbcSuite {
12
-
12
+
13
13
def initializeResultSet (): ResultSet = {
14
- super .beforeAll()
15
14
val data = List (
16
15
Document (" id" -> 1 , " name" -> " test_name" , " active" -> true , " date" -> new DateTime (" 2021-01-01T00:00:00Z" ).toDate),
17
16
Document (" id" -> 2 , " name" -> " another_name" , " active" -> false )
@@ -52,12 +51,43 @@ class MongoDbResultSetSuite extends BaseJdbcSuite {
52
51
assertEquals(resultSet.getInt(" id" ), 1 )
53
52
}
54
53
54
+ test(" getByte() should return the correct value" ) {
55
+ val resultSet = initializeResultSet()
56
+ resultSet.next()
57
+ assertEquals(resultSet.getByte(" id" ), 1 .toByte)
58
+ }
59
+
60
+ test(" getBytes() should return the correct value" ) {
61
+ val resultSet = initializeResultSet()
62
+ resultSet.next()
63
+ assertEquals(resultSet.getByte(" id" ), 1 .toByte)
64
+ }
65
+
66
+ test(" getShort() should return the correct value" ) {
67
+ val resultSet = initializeResultSet()
68
+ resultSet.next()
69
+ assertEquals(resultSet.getShort(" id" ), 1 .toShort)
70
+ }
71
+
72
+ test(" getFloat() should return the correct value" ) {
73
+ val resultSet = initializeResultSet()
74
+ resultSet.next()
75
+ assertEquals(resultSet.getFloat(" id" ), 1 .toFloat)
76
+ }
77
+
55
78
test(" getDouble() should return the correct value" ) {
56
79
val resultSet = initializeResultSet()
57
80
resultSet.next()
58
81
assertEquals(resultSet.getDouble(" id" ), 1.0 )
59
82
}
60
83
84
+ test(" getBigDecimal() should return the correct value" ) {
85
+ val resultSet = initializeResultSet()
86
+ resultSet.next()
87
+ assertEquals(resultSet.getBigDecimal(" id" ), new java.math.BigDecimal (1 ))
88
+ assertEquals(resultSet.getBigDecimal(" id" , 1 ), new java.math.BigDecimal (1 ).setScale(1 ))
89
+ }
90
+
61
91
test(" getDate() should return the correct value" ) {
62
92
val resultSet = initializeResultSet()
63
93
resultSet.next()
@@ -195,7 +225,7 @@ class MongoDbResultSetSuite extends BaseJdbcSuite {
195
225
196
226
test(" findColumn() should return the correct column index" ) {
197
227
val resultSet = initializeResultSet()
198
- assertEquals(resultSet.findColumn(" id" ), 0 )
228
+ assertEquals(resultSet.findColumn(" id" ), 1 )
199
229
}
200
230
201
231
test(" getWarnings() should return null" ) {
@@ -227,7 +257,7 @@ class MongoDbResultSetSuite extends BaseJdbcSuite {
227
257
val resultSet = initializeResultSet()
228
258
assert(! resultSet.isWrapperFor(classOf [MongoDbResultSet ]))
229
259
}
230
-
260
+
231
261
test(" updateNull should update the value to null" ) {
232
262
val resultSet = initializeResultSet()
233
263
resultSet.next()
@@ -246,38 +276,52 @@ class MongoDbResultSetSuite extends BaseJdbcSuite {
246
276
val resultSet = initializeResultSet()
247
277
resultSet.next()
248
278
resultSet.updateInt(1 , 42 )
249
- assert(resultSet.getInt(1 ) == 42 )
279
+ assertEquals(resultSet.getInt(1 ), 42 )
280
+ }
281
+
282
+ test(" updateFloat should update the value" ) {
283
+ val resultSet = initializeResultSet()
284
+ resultSet.next()
285
+ resultSet.updateFloat(1 , 42 .toFloat)
286
+ assertEquals(resultSet.getFloat(1 ), 42 .toFloat)
287
+ }
288
+
289
+ test(" updateBigDecimal should update the value" ) {
290
+ val resultSet = initializeResultSet()
291
+ resultSet.next()
292
+ resultSet.updateBigDecimal(1 , new java.math.BigDecimal (42 ))
293
+ assertEquals(resultSet.getBigDecimal(1 ), new java.math.BigDecimal (42 ))
250
294
}
251
295
252
296
test(" updateString should update the value" ) {
253
297
val resultSet = initializeResultSet()
254
298
resultSet.next()
255
299
resultSet.updateString(2 , " updated_name" )
256
- assert (resultSet.getString(2 ) == " updated_name" )
300
+ assertEquals (resultSet.getString(2 ), " updated_name" )
257
301
}
258
302
259
303
test(" updateDate should update the value" ) {
260
304
val resultSet = initializeResultSet()
261
305
resultSet.next()
262
306
val newDate = new Date (1622505600000L )
263
307
resultSet.updateDate(4 , newDate)
264
- assert (resultSet.getDate(4 ) == newDate)
308
+ assertEquals (resultSet.getDate(4 ), newDate)
265
309
}
266
310
267
311
test(" updateTime should update the value" ) {
268
312
val resultSet = initializeResultSet()
269
313
resultSet.next()
270
314
val newTime = new Time (1622505600000L )
271
315
resultSet.updateTime(4 , newTime)
272
- assert (resultSet.getTime(4 ) == newTime)
316
+ assertEquals (resultSet.getTime(4 ), newTime)
273
317
}
274
318
275
319
test(" updateTimestamp should update the value" ) {
276
320
val resultSet = initializeResultSet()
277
321
resultSet.next()
278
322
val newTimestamp = new Timestamp (1622505600000L )
279
323
resultSet.updateTimestamp(4 , newTimestamp)
280
- assert (resultSet.getTimestamp(4 ) == newTimestamp)
324
+ assertEquals (resultSet.getTimestamp(4 ), newTimestamp)
281
325
}
282
326
283
327
test(" updateObject should update the value" ) {
@@ -304,8 +348,24 @@ class MongoDbResultSetSuite extends BaseJdbcSuite {
304
348
305
349
test(" getConcurrency should throw SQLFeatureNotSupportedException" ) {
306
350
val resultSet = initializeResultSet()
307
- intercept[SQLFeatureNotSupportedException ] {
308
- resultSet.getConcurrency
309
- }
351
+ intercept[SQLFeatureNotSupportedException ] (resultSet.getConcurrency)
352
+ intercept[SQLFeatureNotSupportedException ] (resultSet.updateAsciiStream(99 , null , 1 ))
353
+ intercept[SQLFeatureNotSupportedException ] (resultSet.updateAsciiStream(" updateAsciiStream" , null , 1 ))
354
+ intercept[SQLFeatureNotSupportedException ] (resultSet.updateBinaryStream(99 , null , 1 ))
355
+ intercept[SQLFeatureNotSupportedException ] (resultSet.updateBinaryStream(" updateBinaryStream" , null , 1 ))
356
+ intercept[SQLFeatureNotSupportedException ] (resultSet.updateCharacterStream(99 , null , 1 ))
357
+ intercept[SQLFeatureNotSupportedException ] (resultSet.updateCharacterStream(" updateCharacterStream" , null , 1 ))
358
+
310
359
}
360
+
361
+ test(" null values for not implemented get methods" ) {
362
+ val resultSet = initializeResultSet()
363
+ assertEquals(resultSet.getAsciiStream(1 ), null )
364
+ assertEquals(resultSet.getUnicodeStream(1 ), null )
365
+ assertEquals(resultSet.getBinaryStream(1 ), null )
366
+ assertEquals(resultSet.getAsciiStream(" id" ), null )
367
+ assertEquals(resultSet.getUnicodeStream(" id" ), null )
368
+ assertEquals(resultSet.getBinaryStream(" id" ), null )
369
+ }
370
+
311
371
}
0 commit comments