|
17 | 17 | import com.buabook.kdb.exceptions.TableColumnAlreadyExistsException; |
18 | 18 | import com.buabook.kdb.exceptions.TableSchemaMismatchException; |
19 | 19 | import com.google.common.collect.ImmutableList; |
| 20 | +import com.google.common.collect.ImmutableMap; |
20 | 21 | import com.kx.c.Dict; |
21 | 22 | import com.kx.c.Flip; |
22 | 23 |
|
@@ -196,9 +197,11 @@ public void testAddRowMapAddsNewRow() { |
196 | 197 | @Test |
197 | 198 | public void testAddRowMapAddsConvertsListAndEnumTypesCorrectly() { |
198 | 199 | KdbTable table = new KdbTable("my-test-table"); |
199 | | - KdbDict newRow = new KdbDict() |
200 | | - .add("nested-list", ImmutableList.of(1, 2, 3)) |
201 | | - .add("enum", TestEnum.VALUE_1); |
| 200 | + |
| 201 | + Map<String, Object> newRow = ImmutableMap.<String, Object>builder() |
| 202 | + .put("nested-list", ImmutableList.of(1, 2, 3)) |
| 203 | + .put("enum", TestEnum.VALUE_1) |
| 204 | + .build(); |
202 | 205 |
|
203 | 206 | table.addRow(newRow); |
204 | 207 |
|
@@ -245,6 +248,16 @@ public void testAppendAppendsTableToEndOfTable() { |
245 | 248 | assertThat(table.getRowCount(), is(equalTo(6))); |
246 | 249 | } |
247 | 250 |
|
| 251 | + @Test |
| 252 | + public void testAppendAppendsToEmptyTable() { |
| 253 | + KdbTable empty = new KdbTable("my-test-table"); |
| 254 | + KdbTable toAppend = new KdbTable("my-test-table", getTable()); |
| 255 | + |
| 256 | + empty.append(toAppend); |
| 257 | + |
| 258 | + assertThat(empty.getRowCount(), is(equalTo(3))); |
| 259 | + } |
| 260 | + |
248 | 261 | // KdbTable.getTableName |
249 | 262 |
|
250 | 263 | @Test |
@@ -321,6 +334,69 @@ public void testChangeTableNameChangesTableName() { |
321 | 334 | assertThat(table.getTableName(), is(equalTo("some-other-table-name"))); |
322 | 335 | } |
323 | 336 |
|
| 337 | + // KdbTable.getRow |
| 338 | + |
| 339 | + @Test(expected=ArrayIndexOutOfBoundsException.class) |
| 340 | + public void testGetRowThrowsExceptionIfRowNumberIsNegative() { |
| 341 | + new KdbTable("my-table").getRow(-1); |
| 342 | + } |
| 343 | + |
| 344 | + @Test(expected=ArrayIndexOutOfBoundsException.class) |
| 345 | + public void testGetRowThrowsExceptionIfRowNumberGreaterThanRowCount() { |
| 346 | + new KdbTable("my-table", getTable()).getRow(10); |
| 347 | + } |
| 348 | + |
| 349 | + // KdbTable.fromObject |
| 350 | + |
| 351 | + @Test |
| 352 | + public void testFromObjectReturnsNullIfNullObject() { |
| 353 | + KdbTable fromFlip = KdbTable.fromObject(null); |
| 354 | + |
| 355 | + assertThat(fromFlip, is(nullValue())); |
| 356 | + } |
| 357 | + |
| 358 | + @Test |
| 359 | + public void testFromObjectReturnsNewObjectWithFlipData() { |
| 360 | + KdbTable fromFlip = KdbTable.fromObject(getTable()); |
| 361 | + |
| 362 | + assertThat(fromFlip.isEmpty(), is(equalTo(false))); |
| 363 | + assertThat(fromFlip.getRowCount(), is(equalTo(3))); |
| 364 | + assertThat(fromFlip.getTableName(), is(equalTo("table"))); |
| 365 | + } |
| 366 | + |
| 367 | + // KdbTable.iterator |
| 368 | + |
| 369 | + @Test |
| 370 | + public void testIteratorIteratesOverAllRowsOfTable() { |
| 371 | + KdbTable toIterate = new KdbTable("a-table", getTable()); |
| 372 | + |
| 373 | + int iterateCount = 0; |
| 374 | + |
| 375 | + for(KdbDict row : toIterate) { |
| 376 | + assertThat(row.getDataStore(), hasKey("key1")); |
| 377 | + assertThat(row.getDataStore(), hasKey("key2")); |
| 378 | + assertThat(row.getDataStore(), hasKey("key3")); |
| 379 | + |
| 380 | + iterateCount++; |
| 381 | + } |
| 382 | + |
| 383 | + assertThat(iterateCount, is(equalTo(toIterate.getRowCount()))); |
| 384 | + } |
| 385 | + |
| 386 | + // KdbTable.stream |
| 387 | + |
| 388 | + @Test |
| 389 | + public void testStreamIteratesOverAllRowsOfTable() { |
| 390 | + KdbTable toIterate = new KdbTable("a-table", getTable()); |
| 391 | + |
| 392 | + toIterate.stream() |
| 393 | + .forEach((row) -> { |
| 394 | + assertThat(row.getDataStore(), hasKey("key1")); |
| 395 | + assertThat(row.getDataStore(), hasKey("key2")); |
| 396 | + assertThat(row.getDataStore(), hasKey("key3")); |
| 397 | + }); |
| 398 | + } |
| 399 | + |
324 | 400 |
|
325 | 401 | private Flip getTable() { |
326 | 402 | String[] keys = { "key1", "key2", "key3" }; |
|
0 commit comments