|
15 | 15 | import org.testng.Assert; |
16 | 16 | import org.testng.annotations.DataProvider; |
17 | 17 | import org.testng.annotations.Test; |
| 18 | +import wiremock.org.eclipse.jetty.util.log.Log; |
18 | 19 |
|
| 20 | +import java.math.BigDecimal; |
| 21 | +import java.net.Inet4Address; |
| 22 | +import java.net.Inet6Address; |
19 | 23 | import java.nio.charset.StandardCharsets; |
20 | 24 | import java.sql.Array; |
21 | 25 | import java.sql.Connection; |
22 | 26 | import java.sql.DatabaseMetaData; |
| 27 | +import java.sql.Date; |
23 | 28 | import java.sql.JDBCType; |
24 | 29 | import java.sql.PreparedStatement; |
25 | 30 | import java.sql.ResultSet; |
|
28 | 33 | import java.sql.Statement; |
29 | 34 | import java.sql.Struct; |
30 | 35 | import java.sql.Timestamp; |
| 36 | +import java.time.LocalDate; |
31 | 37 | import java.time.LocalDateTime; |
32 | 38 | import java.time.ZoneId; |
33 | 39 | import java.time.temporal.TemporalAccessor; |
|
36 | 42 | import java.util.List; |
37 | 43 | import java.util.Properties; |
38 | 44 | import java.util.UUID; |
| 45 | +import java.util.function.BiConsumer; |
| 46 | +import java.util.function.BiFunction; |
| 47 | +import java.util.function.Function; |
| 48 | +import java.util.function.Supplier; |
39 | 49 |
|
40 | 50 | import static org.testng.Assert.assertEquals; |
41 | 51 | import static org.testng.Assert.assertFalse; |
@@ -434,6 +444,70 @@ public void testCreateArray() throws SQLException { |
434 | 444 | } |
435 | 445 | } |
436 | 446 |
|
| 447 | + @Test(groups = {"integration"}) |
| 448 | + public void testCreateArrayDifferentTypes() throws Exception { |
| 449 | + try (Connection conn = getJdbcConnection()) { |
| 450 | + |
| 451 | + BiConsumer<String, Object[]> verification = (type, arr) -> { |
| 452 | + Array array; |
| 453 | + try { |
| 454 | + array = conn.createArrayOf(type, arr); |
| 455 | + Object[] wrappedArray = (Object[]) array.getArray(); |
| 456 | + assertEquals(wrappedArray.length, arr.length); |
| 457 | + assertEquals(wrappedArray, arr); |
| 458 | + } catch (SQLException e) { |
| 459 | + fail("Failed to create array of type " + type + " with " + Arrays.toString(arr), e); |
| 460 | + throw new RuntimeException(e); |
| 461 | + } |
| 462 | + }; |
| 463 | + |
| 464 | + |
| 465 | + verification.accept("Int8", new Byte[] {1, 2, 3}); |
| 466 | + verification.accept("Int16", new Short[] {Short.MIN_VALUE, -1, 0, 1, Short.MAX_VALUE}); |
| 467 | + verification.accept("Int32", new Integer[] {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE}); |
| 468 | + verification.accept("Int64", new Long[] {Long.MIN_VALUE, -1L, 0L, 1L, Long.MAX_VALUE}); |
| 469 | + verification.accept("UInt8", new Byte[] {0, 1, Byte.MAX_VALUE}); |
| 470 | + verification.accept("UInt16", new Short[] {0, 1, Short.MAX_VALUE}); |
| 471 | + verification.accept("UInt32", new Long[] {0L, 1L, (long)Integer.MAX_VALUE}); |
| 472 | + verification.accept("UInt64", new Long[] {0L, 1L, Long.MAX_VALUE}); |
| 473 | + verification.accept("Float32", new Float[] {-1.0F, 0.0F, 1.0F}); |
| 474 | + verification.accept("Float64", new Double[] {-1.0D, 0.0D, 1.0D}); |
| 475 | + verification.accept("Date", new Date[] { |
| 476 | + Date.valueOf(LocalDate.now()), |
| 477 | + Date.valueOf(LocalDate.of(2022, 1, 1)), |
| 478 | + Date.valueOf(LocalDate.of(2021, 12, 31)) |
| 479 | + }); |
| 480 | + verification.accept("DateTime", new Timestamp[] { |
| 481 | + Timestamp.valueOf(LocalDateTime.now()), |
| 482 | + Timestamp.valueOf(LocalDateTime.of(2022, 1, 1, 0, 0, 0)), |
| 483 | + Timestamp.valueOf(LocalDateTime.of(2021, 12, 31, 23, 59, 59)) |
| 484 | + }); |
| 485 | + verification.accept("Decimal(10, 2)", new BigDecimal[] { |
| 486 | + new BigDecimal("123.45"), |
| 487 | + new BigDecimal("-12345.67"), |
| 488 | + new BigDecimal("0.00") |
| 489 | + }); |
| 490 | + verification.accept("String", new String[] { |
| 491 | + "", |
| 492 | + "Hello", |
| 493 | + " hello " |
| 494 | + }); |
| 495 | + verification.accept("FixedString(5)", new String[] { |
| 496 | + "12345", |
| 497 | + "abcde", |
| 498 | + " 123" |
| 499 | + }); |
| 500 | + verification.accept("IPv4", new Inet4Address[] { |
| 501 | + (Inet4Address) Inet4Address.getByName("127.0.0.1"), |
| 502 | + (Inet4Address) Inet4Address.getByName("192.168.0.1"), |
| 503 | + }); |
| 504 | + verification.accept("IPv6", new Inet6Address[] { |
| 505 | + (Inet6Address) Inet6Address.getByName("::1"), |
| 506 | + (Inet6Address) Inet6Address.getByName("2001:db8::1"), |
| 507 | + }); |
| 508 | + } |
| 509 | + } |
| 510 | + |
437 | 511 | @Test(groups = { "integration" }) |
438 | 512 | public void testCreateStruct() throws SQLException { |
439 | 513 | try (Connection conn = this.getJdbcConnection()) { |
|
0 commit comments