Compare commits

...

11 Commits

72 changed files with 2151 additions and 1748 deletions

View File

@ -1,173 +0,0 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*@test
*@bug 8007520
*@summary Test those bridge methods to/from java.time date/time classes
* @key randomness
*/
import java.util.Random;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
public class JavatimeTest {
static final int NANOS_PER_SECOND = 1000000000;
public static void main(String[] args) throws Throwable {
int N = 10000;
long t1970 = new java.util.Date(70, 0, 01).getTime();
Random r = new Random();
for (int i = 0; i < N; i++) {
int days = r.nextInt(50) * 365 + r.nextInt(365);
long secs = t1970 + days * 86400 + r.nextInt(86400);
int nanos = r.nextInt(NANOS_PER_SECOND);
int nanos_ms = nanos / 1000000 * 1000000; // millis precision
long millis = secs * 1000 + r.nextInt(1000);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC);
LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC);
Instant inst = Instant.ofEpochSecond(secs, nanos);
Instant inst_ms = Instant.ofEpochSecond(secs, nanos_ms);
//System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
/////////// Timestamp ////////////////////////////////
Timestamp ta = new Timestamp(millis);
ta.setNanos(nanos);
if (!isEqual(ta.toLocalDateTime(), ta)) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
print(ta.toLocalDateTime(), ta);
throw new RuntimeException("FAILED: j.s.ts -> ldt");
}
if (!isEqual(ldt, Timestamp.valueOf(ldt))) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
print(ldt, Timestamp.valueOf(ldt));
throw new RuntimeException("FAILED: ldt -> j.s.ts");
}
Instant inst0 = ta.toInstant();
if (ta.getTime() != inst0.toEpochMilli() ||
ta.getNanos() != inst0.getNano() ||
!ta.equals(Timestamp.from(inst0))) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
throw new RuntimeException("FAILED: j.s.ts -> instant -> j.s.ts");
}
inst = Instant.ofEpochSecond(secs, nanos);
Timestamp ta0 = Timestamp.from(inst);
if (ta0.getTime() != inst.toEpochMilli() ||
ta0.getNanos() != inst.getNano() ||
!inst.equals(ta0.toInstant())) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
throw new RuntimeException("FAILED: instant -> timestamp -> instant");
}
////////// java.sql.Date /////////////////////////////
// j.s.d/t uses j.u.d.equals() !!!!!!!!
java.sql.Date jsd = new java.sql.Date(millis);
if (!isEqual(jsd.toLocalDate(), jsd)) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
print(jsd.toLocalDate(), jsd);
throw new RuntimeException("FAILED: j.s.d -> ld");
}
LocalDate ld = ldt.toLocalDate();
if (!isEqual(ld, java.sql.Date.valueOf(ld))) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
print(ld, java.sql.Date.valueOf(ld));
throw new RuntimeException("FAILED: ld -> j.s.d");
}
////////// java.sql.Time /////////////////////////////
java.sql.Time jst = new java.sql.Time(millis);
if (!isEqual(jst.toLocalTime(), jst)) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
print(jst.toLocalTime(), jst);
throw new RuntimeException("FAILED: j.s.t -> lt");
}
// millis precision
LocalTime lt = ldt_ms.toLocalTime();
if (!isEqual(lt, java.sql.Time.valueOf(lt))) {
System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt);
print(lt, java.sql.Time.valueOf(lt));
throw new RuntimeException("FAILED: lt -> j.s.t");
}
}
System.out.println("Passed!");
}
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
return zdt.getYear() == ts.getYear() + 1900 &&
zdt.getMonthValue() == ts.getMonth() + 1 &&
zdt.getDayOfMonth() == ts.getDate() &&
zdt.getHour() == ts.getHours() &&
zdt.getMinute() == ts.getMinutes() &&
zdt.getSecond() == ts.getSeconds() &&
zdt.getNano() == ts.getNanos();
}
private static void print(LocalDateTime ldt, Timestamp ts) {
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
System.out.printf("ldt:ts %d/%d, %d/%d, %d/%d, %d/%d, %d/%d, %d/%d, nano:[%d/%d]%n",
zdt.getYear(), ts.getYear() + 1900,
zdt.getMonthValue(), ts.getMonth() + 1,
zdt.getDayOfMonth(), ts.getDate(),
zdt.getHour(), ts.getHours(),
zdt.getMinute(), ts.getMinutes(),
zdt.getSecond(), ts.getSeconds(),
zdt.getNano(), ts.getNanos());
}
private static boolean isEqual(LocalDate ld, java.sql.Date d) {
return ld.getYear() == d.getYear() + 1900 &&
ld.getMonthValue() == d.getMonth() + 1 &&
ld.getDayOfMonth() == d.getDate();
}
private static void print(LocalDate ld, java.sql.Date d) {
System.out.printf("%d/%d, %d/%d, %d/%d%n",
ld.getYear(), d.getYear() + 1900,
ld.getMonthValue(), d.getMonth() + 1,
ld.getDayOfMonth(), d.getDate());
}
private static boolean isEqual(LocalTime lt, java.sql.Time t) {
return lt.getHour() == t.getHours() &&
lt.getMinute() == t.getMinutes() &&
lt.getSecond() == t.getSeconds();
}
private static void print(LocalTime lt, java.sql.Time t) {
System.out.printf("%d/%d, %d/%d, %d/%d%n",
lt.getHour(), t.getHours(),
lt.getMinute(), t.getMinutes(),
lt.getSecond(), t.getSeconds());
}
}

View File

@ -26,13 +26,8 @@ import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
/*
* @test
@ -42,29 +37,12 @@ import org.junit.jupiter.api.TestInstance;
* @summary Tests that a JDBC Driver that is a module can be loaded
* via the service-provider loading mechanism.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class DriverManagerModuleTests {
private final String LUCKYDOGDRIVER_URL = "jdbc:tennis:myDB";
private static final String STUBDRIVERURL = "jdbc:stub:myDB";
private static final String CONNECTION_CLASS_NAME = "com.luckydogtennis.StubConnection";
@BeforeAll
public static void setUpClass() throws Exception {
}
@AfterAll
public static void tearDownClass() throws Exception {
}
@BeforeEach
public void setUpMethod() throws Exception {
}
@AfterEach
public void tearDownMethod() throws Exception {
}
/**
* Validate JDBC drivers as modules will be accessible. One driver will be
* loaded and registered via the service-provider loading mechanism. The

View File

@ -30,8 +30,9 @@ import java.sql.CallableStatement;
import java.sql.SQLException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@ -54,7 +55,7 @@ public class CallableStatementTests extends BaseTest {
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, cstmt.enquoteLiteral(s));
@ -66,13 +67,13 @@ public class CallableStatementTests extends BaseTest {
*/
@Test
public void test01() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> cstmt.enquoteLiteral(null));
assertThrows(NullPointerException.class, () -> cstmt.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, cstmt.enquoteIdentifier(s, alwaysQuote));
@ -82,26 +83,26 @@ public class CallableStatementTests extends BaseTest {
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(SQLException.class, () -> cstmt.enquoteIdentifier(s, alwaysQuote));
assertThrows(SQLException.class, () -> cstmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> cstmt.enquoteIdentifier(null, alwaysQuote));
assertThrows(NullPointerException.class, () -> cstmt.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, cstmt.isSimpleIdentifier(s));
@ -113,14 +114,14 @@ public class CallableStatementTests extends BaseTest {
*/
@Test
public void test06() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> cstmt.isSimpleIdentifier(null));
assertThrows(NullPointerException.class, () -> cstmt.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, cstmt.enquoteNCharLiteral(s));
@ -132,6 +133,6 @@ public class CallableStatementTests extends BaseTest {
*/
@Test
public void test08() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> cstmt.enquoteNCharLiteral(null));
assertThrows(NullPointerException.class, () -> cstmt.enquoteNCharLiteral(null));
}
}

View File

@ -28,7 +28,6 @@ import util.StubConnection;
import java.sql.SQLException;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -48,7 +47,7 @@ public class ConnectionTests extends BaseTest {
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, conn.enquoteLiteral(s));
@ -60,13 +59,13 @@ public class ConnectionTests extends BaseTest {
*/
@Test
public void test01() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> conn.enquoteLiteral(null));
assertThrows(NullPointerException.class, () -> conn.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, conn.enquoteIdentifier(s, alwaysQuote));
@ -76,26 +75,26 @@ public class ConnectionTests extends BaseTest {
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(SQLException.class, () -> conn.enquoteIdentifier(s, alwaysQuote));
assertThrows(SQLException.class, () -> conn.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> conn.enquoteIdentifier(null, alwaysQuote));
assertThrows(NullPointerException.class, () -> conn.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, conn.isSimpleIdentifier(s));
@ -107,14 +106,14 @@ public class ConnectionTests extends BaseTest {
*/
@Test
public void test06() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> conn.isSimpleIdentifier(null));
assertThrows(NullPointerException.class, () -> conn.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, conn.enquoteNCharLiteral(s));
@ -126,6 +125,6 @@ public class ConnectionTests extends BaseTest {
*/
@Test
public void test08() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> conn.enquoteNCharLiteral(null));
assertThrows(NullPointerException.class, () -> conn.enquoteNCharLiteral(null));
}
}

View File

@ -24,11 +24,12 @@ package test.sql;
import java.sql.Date;
import java.time.LocalDate;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
@ -38,17 +39,17 @@ public class DateTests extends BaseTest {
/*
* Validate an IllegalArgumentException is thrown for an invalid Date string
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidDateValues")
public void test(String d) throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> Date.valueOf(d));
assertThrows(IllegalArgumentException.class, () -> Date.valueOf(d));
}
/*
* Test that a date created from a date string is equal to the value
* returned from toString()
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validDateValues")
public void test00(String d, String expectedD) {
Date d1 = Date.valueOf(d);
@ -214,7 +215,7 @@ public class DateTests extends BaseTest {
@Test
public void test15() throws Exception {
LocalDate ld = null;
Assertions.assertThrows(NullPointerException.class, () -> Date.valueOf(ld));
assertThrows(NullPointerException.class, () -> Date.valueOf(ld));
}
/*
@ -224,7 +225,7 @@ public class DateTests extends BaseTest {
@Test
public void test16() throws Exception {
Date d = Date.valueOf("1961-08-30");
Assertions.assertThrows(UnsupportedOperationException.class, d::toInstant);
assertThrows(UnsupportedOperationException.class, d::toInstant);
}
/*
@ -278,7 +279,7 @@ public class DateTests extends BaseTest {
@Test
public void test21() throws Exception {
Date d = Date.valueOf("1961-08-30");
Assertions.assertThrows(IllegalArgumentException.class, d::getHours);
assertThrows(IllegalArgumentException.class, d::getHours);
}
/*
@ -287,7 +288,7 @@ public class DateTests extends BaseTest {
@Test
public void test22() throws Exception {
Date d = Date.valueOf("1961-08-30");
Assertions.assertThrows(IllegalArgumentException.class, d::getMinutes);
assertThrows(IllegalArgumentException.class, d::getMinutes);
}
/*
@ -296,7 +297,7 @@ public class DateTests extends BaseTest {
@Test
public void test23() throws Exception {
Date d = Date.valueOf("1961-08-30");
Assertions.assertThrows(IllegalArgumentException.class, d::getSeconds);
assertThrows(IllegalArgumentException.class, d::getSeconds);
}
/*
@ -305,7 +306,7 @@ public class DateTests extends BaseTest {
@Test
public void test24() throws Exception {
Date d = Date.valueOf("1961-08-30");
Assertions.assertThrows(IllegalArgumentException.class, () -> d.setHours(8));
assertThrows(IllegalArgumentException.class, () -> d.setHours(8));
}
/*
@ -314,7 +315,7 @@ public class DateTests extends BaseTest {
@Test
public void test25() throws Exception {
Date d = Date.valueOf("1961-08-30");
Assertions.assertThrows(IllegalArgumentException.class, () -> d.setMinutes(0));
assertThrows(IllegalArgumentException.class, () -> d.setMinutes(0));
}
/*
@ -323,7 +324,7 @@ public class DateTests extends BaseTest {
@Test
public void test26() throws Exception {
Date d = Date.valueOf("1961-08-30");
Assertions.assertThrows(IllegalArgumentException.class, () -> d.setSeconds(0));
assertThrows(IllegalArgumentException.class, () -> d.setSeconds(0));
}
/*
@ -331,31 +332,31 @@ public class DateTests extends BaseTest {
* to validate that an IllegalArgumentException will be thrown from the
* valueOf method
*/
private Object[][] invalidDateValues() {
return new Object[][]{
{"20009-11-01"},
{"09-11-01"},
{"-11-01"},
{"2009-111-01"},
{"2009--01"},
{"2009-13-01"},
{"2009-11-011"},
{"2009-11-"},
{"2009-11-00"},
{"2009-11-33"},
{"--"},
{""},
{null},
{"-"},
{"2009"},
{"2009-01"},
{"---"},
{"2009-13--1"},
{"1900-1-0"},
{"2009-01-01 10:50:01"},
{"1996-12-10 12:26:19.1"},
{"10:50:01"}
};
private Stream<String> invalidDateValues() {
return Stream.of(
"20009-11-01",
"09-11-01",
"-11-01",
"2009-111-01",
"2009--01",
"2009-13-01",
"2009-11-011",
"2009-11-",
"2009-11-00",
"2009-11-33",
"--",
"",
null,
"-",
"2009",
"2009-01",
"---",
"2009-13--1",
"1900-1-0",
"2009-01-01 10:50:01",
"1996-12-10 12:26:19.1",
"10:50:01"
);
}
/*
@ -363,13 +364,12 @@ public class DateTests extends BaseTest {
* to validate that an IllegalArgumentException will not be thrown from the
* valueOf method and the corect value from toString() is returned
*/
private Object[][] validDateValues() {
return new Object[][]{
{"2009-08-30", "2009-08-30"},
{"2009-01-8", "2009-01-08"},
{"2009-1-01", "2009-01-01"},
{"2009-1-1", "2009-01-01"}
};
private Stream<Arguments> validDateValues() {
return Stream.of(
Arguments.of("2009-08-30", "2009-08-30"),
Arguments.of("2009-01-8", "2009-01-08"),
Arguments.of("2009-1-01", "2009-01-01"),
Arguments.of("2009-1-1", "2009-01-01")
);
}
}

View File

@ -39,18 +39,12 @@ import java.util.Collections;
import java.util.Properties;
import java.util.stream.Collectors;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import util.StubDriver;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class DriverManagerTests {
private final String StubDriverURL = "jdbc:tennis:boy";
@ -62,23 +56,11 @@ public class DriverManagerTests {
public DriverManagerTests() {
}
@BeforeAll
public static void setUpClass() throws Exception {
}
@AfterAll
public static void tearDownClass() throws Exception {
}
@BeforeEach
public void setUpMethod() throws Exception {
removeAllDrivers();
}
@AfterEach
public void tearDownMethod() throws Exception {
}
/**
* Utility method to remove all registered drivers
*/
@ -128,7 +110,7 @@ public class DriverManagerTests {
@Test
public void test1() throws Exception {
Driver d = null;
Assertions.assertThrows(NullPointerException.class,
assertThrows(NullPointerException.class,
() -> DriverManager.registerDriver(d));
}
@ -139,7 +121,7 @@ public class DriverManagerTests {
@Test
public void test2() throws Exception {
Driver d = null;
Assertions.assertThrows(NullPointerException.class, () ->
assertThrows(NullPointerException.class, () ->
DriverManager.registerDriver(d, null));
}
@ -158,7 +140,7 @@ public class DriverManagerTests {
*/
@Test
public void test4() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL));
assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL));
}
/**
@ -167,7 +149,7 @@ public class DriverManagerTests {
*/
@Test
public void test5() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL, new Properties()));
assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL, new Properties()));
}
/**
@ -176,7 +158,7 @@ public class DriverManagerTests {
*/
@Test
public void test6() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL, "LuckyDog", "tennisanyone"));
assertThrows(SQLException.class, () -> DriverManager.getConnection(InvalidURL, "LuckyDog", "tennisanyone"));
}
/**
@ -184,7 +166,7 @@ public class DriverManagerTests {
*/
@Test
public void test7() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getConnection(null));
assertThrows(SQLException.class, () -> DriverManager.getConnection(null));
}
/**
@ -192,7 +174,7 @@ public class DriverManagerTests {
*/
@Test
public void test8() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getConnection(null, new Properties()));
assertThrows(SQLException.class, () -> DriverManager.getConnection(null, new Properties()));
}
/**
@ -200,7 +182,7 @@ public class DriverManagerTests {
*/
@Test
public void test9() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getConnection(null, "LuckyDog", "tennisanyone"));
assertThrows(SQLException.class, () -> DriverManager.getConnection(null, "LuckyDog", "tennisanyone"));
}
/**
@ -209,7 +191,7 @@ public class DriverManagerTests {
*/
@Test
public void test10() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getDriver(InvalidURL));
assertThrows(SQLException.class, () -> DriverManager.getDriver(InvalidURL));
}
/**
@ -217,7 +199,7 @@ public class DriverManagerTests {
*/
@Test
public void test11() throws Exception {
Assertions.assertThrows(SQLException.class, () -> DriverManager.getDriver(null));
assertThrows(SQLException.class, () -> DriverManager.getDriver(null));
}
/**
@ -238,7 +220,7 @@ public class DriverManagerTests {
@Test
public void test13() throws Exception {
DriverManager.registerDriver(new StubDriver());
Assertions.assertThrows(SQLException.class, () -> DriverManager.getDriver(InvalidURL));
assertThrows(SQLException.class, () -> DriverManager.getDriver(InvalidURL));
}
/**

View File

@ -0,0 +1,184 @@
/*
* Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package test.sql;
/*
* @test
* @bug 8007520
* @summary Test those bridge methods to/from java.time date/time classes
* @key randomness
*/
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.FieldSource;
import java.util.List;
import java.util.Random;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class JavatimeTest {
private static final int NANOS_PER_SECOND = 1000000000;
private static final long t1970 = new java.util.Date(70, 0, 01).getTime();
private static final Random R = new Random();
// Data provider contains 10,000 randomized arguments
// which are used as the dates and times for the tests
private static final List<Arguments> DATE_TIME_ARGS = IntStream.range(0, 10_000)
.mapToObj(i -> {
int days = R.nextInt(50) * 365 + R.nextInt(365);
long secs = t1970 + days * 86400 + R.nextInt(86400);
int nanos = R.nextInt(NANOS_PER_SECOND);
int nanos_ms = nanos / 1000000 * 1000000; // millis precision
long millis = secs * 1000 + R.nextInt(1000);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC);
return Arguments.of(millis, nanos, ldt, secs, nanos_ms);
}).toList();
@ParameterizedTest(autoCloseArguments = false)
@FieldSource("DATE_TIME_ARGS")
void timestampTest(long millis, int nanos, LocalDateTime ldt, long secs) {
Timestamp ta = new Timestamp(millis);
ta.setNanos(nanos);
assertTrue(isEqual(ta.toLocalDateTime(), ta),
errMsg("j.s.ts -> ldt", millis, nanos, ldt, results(ta.toLocalDateTime(), ta)));
assertTrue(isEqual(ldt, Timestamp.valueOf(ldt)),
errMsg("ldt -> j.s.ts", millis, nanos, ldt, results(ldt, Timestamp.valueOf(ldt))));
Instant inst0 = ta.toInstant();
assertAll(errMsg("j.s.ts -> instant -> j.s.ts", millis, nanos, ldt),
() -> assertEquals(ta.getTime(), inst0.toEpochMilli()),
() -> assertEquals(ta.getNanos(), inst0.getNano()),
() -> assertEquals(ta, Timestamp.from(inst0))
);
Instant inst = Instant.ofEpochSecond(secs, nanos);
Timestamp ta0 = Timestamp.from(inst);
assertAll(errMsg("instant -> timestamp -> instant", millis, nanos, ldt),
() -> assertEquals(ta0.getTime(), inst.toEpochMilli()),
() -> assertEquals(ta0.getNanos(), inst.getNano()),
() -> assertEquals(inst, ta0.toInstant())
);
}
@ParameterizedTest(autoCloseArguments = false)
@FieldSource("DATE_TIME_ARGS")
void sqlDateTest(long millis, int nanos, LocalDateTime ldt) {
// j.s.d/t uses j.u.d.equals() !!!!!!!!
java.sql.Date jsd = new java.sql.Date(millis);
assertTrue(isEqual(jsd.toLocalDate(), jsd),
errMsg("j.s.d -> ld", millis, nanos, ldt, results(jsd.toLocalDate(), jsd)));
LocalDate ld = ldt.toLocalDate();
assertTrue(isEqual(ld, java.sql.Date.valueOf(ld)),
errMsg("ld -> j.s.d", millis, nanos, ldt, results(ld, java.sql.Date.valueOf(ld))));
}
@ParameterizedTest(autoCloseArguments = false)
@FieldSource("DATE_TIME_ARGS")
void sqlTimeTest(long millis, int nanos, LocalDateTime ldt, long secs, int nanos_ms) {
java.sql.Time jst = new java.sql.Time(millis);
assertTrue(isEqual(jst.toLocalTime(), jst),
errMsg("j.s.t -> lt", millis, nanos, ldt, results(jst.toLocalTime(), jst)));
// millis precision
LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC);
LocalTime lt = ldt_ms.toLocalTime();
assertTrue(isEqual(lt, java.sql.Time.valueOf(lt)),
errMsg("lt -> j.s.t", millis, nanos, ldt, results(lt, java.sql.Time.valueOf(lt))));
}
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
return zdt.getYear() == ts.getYear() + 1900 &&
zdt.getMonthValue() == ts.getMonth() + 1 &&
zdt.getDayOfMonth() == ts.getDate() &&
zdt.getHour() == ts.getHours() &&
zdt.getMinute() == ts.getMinutes() &&
zdt.getSecond() == ts.getSeconds() &&
zdt.getNano() == ts.getNanos();
}
private static String results(LocalDateTime ldt, Timestamp ts) {
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
return "ldt:ts %d/%d, %d/%d, %d/%d, %d/%d, %d/%d, %d/%d, nano:[%d/%d]%n".formatted(
zdt.getYear(), ts.getYear() + 1900,
zdt.getMonthValue(), ts.getMonth() + 1,
zdt.getDayOfMonth(), ts.getDate(),
zdt.getHour(), ts.getHours(),
zdt.getMinute(), ts.getMinutes(),
zdt.getSecond(), ts.getSeconds(),
zdt.getNano(), ts.getNanos());
}
private static boolean isEqual(LocalDate ld, java.sql.Date d) {
return ld.getYear() == d.getYear() + 1900 &&
ld.getMonthValue() == d.getMonth() + 1 &&
ld.getDayOfMonth() == d.getDate();
}
private static String results(LocalDate ld, java.sql.Date d) {
return "%d/%d, %d/%d, %d/%d%n".formatted(
ld.getYear(), d.getYear() + 1900,
ld.getMonthValue(), d.getMonth() + 1,
ld.getDayOfMonth(), d.getDate());
}
private static boolean isEqual(LocalTime lt, java.sql.Time t) {
return lt.getHour() == t.getHours() &&
lt.getMinute() == t.getMinutes() &&
lt.getSecond() == t.getSeconds();
}
private static String results(LocalTime lt, java.sql.Time t) {
return "%d/%d, %d/%d, %d/%d%n".formatted(
lt.getHour(), t.getHours(),
lt.getMinute(), t.getMinutes(),
lt.getSecond(), t.getSeconds());
}
private static String errMsg(String testCase, long millis, int nanos,
LocalDateTime ldt, String results) {
return "FAILED: %s%n INPUTS: ms: %16d ns: %10d ldt:[%s]%n ACTUAL: %s"
.formatted(testCase, millis, nanos, ldt, results);
}
private static String errMsg(String testCase, long millis, int nanos,
LocalDateTime ldt) {
return "FAILED: %s%n INPUTS: ms: %16d ns: %10d ldt:[%s]%n"
.formatted(testCase, millis, nanos, ldt);
}
}

View File

@ -30,8 +30,9 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@ -55,7 +56,7 @@ public class PreparedStatementTests extends BaseTest {
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, pstmt.enquoteLiteral(s));
@ -67,13 +68,13 @@ public class PreparedStatementTests extends BaseTest {
*/
@Test
public void test01() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> pstmt.enquoteLiteral(null));
assertThrows(NullPointerException.class, () -> pstmt.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, pstmt.enquoteIdentifier(s, alwaysQuote));
@ -83,26 +84,26 @@ public class PreparedStatementTests extends BaseTest {
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(SQLException.class, () -> pstmt.enquoteIdentifier(s, alwaysQuote));
assertThrows(SQLException.class, () -> pstmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> pstmt.enquoteIdentifier(null, alwaysQuote));
assertThrows(NullPointerException.class, () -> pstmt.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, pstmt.isSimpleIdentifier(s));
@ -114,14 +115,14 @@ public class PreparedStatementTests extends BaseTest {
*/
@Test
public void test06() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> pstmt.isSimpleIdentifier(null));
assertThrows(NullPointerException.class, () -> pstmt.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, pstmt.enquoteNCharLiteral(s));
@ -133,6 +134,6 @@ public class PreparedStatementTests extends BaseTest {
*/
@Test
public void test08() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> pstmt.enquoteNCharLiteral(null));
assertThrows(NullPointerException.class, () -> pstmt.enquoteNCharLiteral(null));
}
}

View File

@ -26,8 +26,9 @@ import java.sql.SQLException;
import java.sql.Statement;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@ -54,7 +55,7 @@ public class StatementTests extends BaseTest {
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedLiteralValues")
public void test00(String s, String expected) throws SQLException {
assertEquals(expected, stmt.enquoteLiteral(s));
@ -66,13 +67,13 @@ public class StatementTests extends BaseTest {
*/
@Test
public void test01() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> stmt.enquoteLiteral(null));
assertThrows(NullPointerException.class, () -> stmt.enquoteLiteral(null));
}
/*
* Validate that enquoteIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedIdentifierValues")
public void test02(String s, boolean alwaysQuote, String expected) throws SQLException {
assertEquals(expected, stmt.enquoteIdentifier(s, alwaysQuote));
@ -82,26 +83,26 @@ public class StatementTests extends BaseTest {
* Validate that a SQLException is thrown for values that are not valid
* for a SQL identifier
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidEnquotedIdentifierValues")
public void test03(String s, boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(SQLException.class, () -> stmt.enquoteIdentifier(s, alwaysQuote));
assertThrows(SQLException.class, () -> stmt.enquoteIdentifier(s, alwaysQuote));
}
/*
* Validate a NullPointerException is thrown is the string passed to
* enquoteIdentiifer is null
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test04(boolean alwaysQuote) throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> stmt.enquoteIdentifier(null, alwaysQuote));
assertThrows(NullPointerException.class, () -> stmt.enquoteIdentifier(null, alwaysQuote));
}
/*
* Validate that isSimpleIdentifier returns the expected value
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("simpleIdentifierValues")
public void test05(String s, boolean expected) throws SQLException {
assertEquals(expected, stmt.isSimpleIdentifier(s));
@ -113,14 +114,14 @@ public class StatementTests extends BaseTest {
*/
@Test
public void test06() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> stmt.isSimpleIdentifier(null));
assertThrows(NullPointerException.class, () -> stmt.isSimpleIdentifier(null));
}
/*
* Verify that enquoteLiteral creates a valid literal and converts every
* single quote to two single quotes
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validEnquotedNCharLiteralValues")
public void test07(String s, String expected) throws SQLException {
assertEquals(expected, stmt.enquoteNCharLiteral(s));
@ -132,6 +133,6 @@ public class StatementTests extends BaseTest {
*/
@Test
public void test08() throws SQLException {
Assertions.assertThrows(NullPointerException.class, () -> stmt.enquoteNCharLiteral(null));
assertThrows(NullPointerException.class, () -> stmt.enquoteNCharLiteral(null));
}
}

View File

@ -24,11 +24,12 @@ package test.sql;
import java.sql.Time;
import java.time.LocalTime;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
@ -41,7 +42,7 @@ public class TimeTests extends BaseTest {
@Test
public void test01() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, t::getYear);
assertThrows(IllegalArgumentException.class, t::getYear);
}
/*
@ -50,7 +51,7 @@ public class TimeTests extends BaseTest {
@Test
public void test02() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, t::getMonth);
assertThrows(IllegalArgumentException.class, t::getMonth);
}
/*
@ -59,7 +60,7 @@ public class TimeTests extends BaseTest {
@Test
public void test03() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, t::getDay);
assertThrows(IllegalArgumentException.class, t::getDay);
}
/**
@ -68,7 +69,7 @@ public class TimeTests extends BaseTest {
@Test
public void test04() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, t::getDate);
assertThrows(IllegalArgumentException.class, t::getDate);
}
/*
@ -77,7 +78,7 @@ public class TimeTests extends BaseTest {
@Test
public void test05() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, () -> t.setYear(8));
assertThrows(IllegalArgumentException.class, () -> t.setYear(8));
}
/*
@ -86,7 +87,7 @@ public class TimeTests extends BaseTest {
@Test
public void test06() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, () -> t.setMonth(8));
assertThrows(IllegalArgumentException.class, () -> t.setMonth(8));
}
/*
@ -95,7 +96,7 @@ public class TimeTests extends BaseTest {
@Test
public void test07() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, () -> t.setDate(30));
assertThrows(IllegalArgumentException.class, () -> t.setDate(30));
}
/*
@ -104,7 +105,7 @@ public class TimeTests extends BaseTest {
@Test
public void test08() {
Time t = Time.valueOf("08:30:59");
Assertions.assertThrows(IllegalArgumentException.class, t::getDate);
assertThrows(IllegalArgumentException.class, t::getDate);
}
/*
@ -135,7 +136,7 @@ public class TimeTests extends BaseTest {
@Test
public void test11() throws Exception {
LocalTime ld = null;
Assertions.assertThrows(NullPointerException.class, () -> Time.valueOf(ld));
assertThrows(NullPointerException.class, () -> Time.valueOf(ld));
}
/*
@ -145,7 +146,7 @@ public class TimeTests extends BaseTest {
@Test
public void test12() throws Exception {
Time t = new Time(System.currentTimeMillis());
Assertions.assertThrows(UnsupportedOperationException.class, t::toInstant);
assertThrows(UnsupportedOperationException.class, t::toInstant);
}
/*
@ -153,7 +154,7 @@ public class TimeTests extends BaseTest {
* toString() of the other and that the correct value is returned from
* toString()
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validTimeValues")
public void test13(String time, String expected) {
Time t1 = Time.valueOf(time);
@ -187,10 +188,10 @@ public class TimeTests extends BaseTest {
/*
* Validate an IllegalArgumentException is thrown for an invalid Time string
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidTimeValues")
public void test16(String time) throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> Time.valueOf(time));
assertThrows(IllegalArgumentException.class, () -> Time.valueOf(time));
}
/*
@ -304,28 +305,28 @@ public class TimeTests extends BaseTest {
* to validate that an IllegalArgumentException will be thrown from the
* valueOf method
*/
private Object[][] invalidTimeValues() {
return new Object[][]{
{"2009-11-01 10:50:01"},
{"1961-08-30 10:50:01.1"},
{"1961-08-30"},
{"00:00:00."},
{"10:50:0.1"},
{":00:00"},
{"00::00"},
{"00:00:"},
{"::"},
{" : : "},
{"0a:00:00"},
{"00:bb:00"},
{"00:01:cc"},
{"08:10:Batman"},
{"08:10:10:10"},
{"08:10"},
{"a:b:c"},
{null},
{"8:"}
};
private Stream<String> invalidTimeValues() {
return Stream.of(
"2009-11-01 10:50:01",
"1961-08-30 10:50:01.1",
"1961-08-30",
"00:00:00.",
"10:50:0.1",
":00:00",
"00::00",
"00:00:",
"::",
" : : ",
"0a:00:00",
"00:bb:00",
"00:01:cc",
"08:10:Batman",
"08:10:10:10",
"08:10",
"a:b:c",
null,
"8:"
);
}
/*
@ -334,18 +335,18 @@ public class TimeTests extends BaseTest {
* valueOf method. It also contains the expected return value from
* toString()
*/
private Object[][] validTimeValues() {
return new Object[][]{
{"10:50:01", "10:50:01"},
{"01:1:1", "01:01:01"},
{"01:01:1", "01:01:01"},
{"1:01:1", "01:01:01"},
{"2:02:02", "02:02:02"},
{"2:02:2", "02:02:02"},
{"10:50:1", "10:50:01"},
{"00:00:00", "00:00:00"},
{"08:30:59", "08:30:59"},
{"9:0:1", "09:00:01"}
};
private Stream<Arguments> validTimeValues() {
return Stream.of(
Arguments.of("10:50:01", "10:50:01"),
Arguments.of("01:1:1", "01:01:01"),
Arguments.of("01:01:1", "01:01:01"),
Arguments.of("1:01:1", "01:01:01"),
Arguments.of("2:02:02", "02:02:02"),
Arguments.of("2:02:2", "02:02:02"),
Arguments.of("10:50:1", "10:50:01"),
Arguments.of("00:00:00", "00:00:00"),
Arguments.of("08:30:59", "08:30:59"),
Arguments.of("9:0:1", "09:00:01")
);
}
}

View File

@ -30,13 +30,14 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
@ -68,10 +69,10 @@ public class TimestampTests extends BaseTest {
/*
* Validate an IllegalArgumentException is thrown for an invalid Timestamp
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidTimestampValues")
public void test(String ts) throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> Timestamp.valueOf(ts));
assertThrows(IllegalArgumentException.class, () -> Timestamp.valueOf(ts));
}
/*
@ -223,7 +224,7 @@ public class TimestampTests extends BaseTest {
* Validate that two Timestamps are equal when one is created from the
* toString() of the other
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validTimestampValues")
public void test13(String ts, String expectedTS) {
Timestamp ts1 = Timestamp.valueOf(ts);
@ -271,7 +272,7 @@ public class TimestampTests extends BaseTest {
@Test
public void test17() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
Assertions.assertThrows(NullPointerException.class, () -> ts1.before(null));
assertThrows(NullPointerException.class, () -> ts1.before(null));
}
/*
@ -324,7 +325,7 @@ public class TimestampTests extends BaseTest {
@Test
public void test22() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
Assertions.assertThrows(NullPointerException.class, () -> ts1.after(null));
assertThrows(NullPointerException.class, () -> ts1.after(null));
}
/*
@ -484,7 +485,7 @@ public class TimestampTests extends BaseTest {
@Test
public void test38() throws Exception {
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
Assertions.assertThrows(IllegalArgumentException.class, () -> ts1.setNanos(-1));
assertThrows(IllegalArgumentException.class, () -> ts1.setNanos(-1));
}
@ -495,7 +496,7 @@ public class TimestampTests extends BaseTest {
public void test39() throws Exception {
int nanos = 999999999;
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
Assertions.assertThrows(IllegalArgumentException.class, () -> ts1.setNanos(nanos + 1));
assertThrows(IllegalArgumentException.class, () -> ts1.setNanos(nanos + 1));
}
/*
@ -549,7 +550,7 @@ public class TimestampTests extends BaseTest {
@Test
public void test44() throws Exception {
LocalDateTime ldt = null;
Assertions.assertThrows(NullPointerException.class, () -> Timestamp.valueOf(ldt));
assertThrows(NullPointerException.class, () -> Timestamp.valueOf(ldt));
}
/*
@ -580,7 +581,7 @@ public class TimestampTests extends BaseTest {
@Test
public void test47() throws Exception {
Instant instant = null;
Assertions.assertThrows(NullPointerException.class, () -> Timestamp.from(instant));
assertThrows(NullPointerException.class, () -> Timestamp.from(instant));
}
// Added SQE tests
@ -633,7 +634,7 @@ public class TimestampTests extends BaseTest {
* Validate that two Timestamps are equal when one is created from the
* toString() of the other
*/
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validateNanos")
public void test51(String ts, int nanos) {
Timestamp ts1 = Timestamp.valueOf(ts);
@ -642,7 +643,7 @@ public class TimestampTests extends BaseTest {
"Error with Nanos");
}
@ParameterizedTest
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validTimestampLongValues")
public void test52(long value, String ts) {
Timestamp ts1 = new Timestamp(value);
@ -717,32 +718,32 @@ public class TimestampTests extends BaseTest {
* to validate that an IllegalArgumentException will be thrown from the
* valueOf method
*/
private Object[][] invalidTimestampValues() {
return new Object[][]{
{"2009-11-01-01 10:50:01"},
{"aaaa-11-01-01 10:50"},
{"aaaa-11-01 10:50"},
{"1961--30 00:00:00"},
{"--30 00:00:00"},
{"-- 00:00:00"},
{"1961-1- 00:00:00"},
{"2009-11-01"},
{"10:50:01"},
{"1961-a-30 00:00:00"},
{"1961-01-bb 00:00:00"},
{"1961-08-30 00:00:00."},
{"1961-08-30 :00:00"},
{"1961-08-30 00::00"},
{"1961-08-30 00:00:"},
{"1961-08-30 ::"},
{"1961-08-30 0a:00:00"},
{"1961-08-30 00:bb:00"},
{"1961-08-30 00:01:cc"},
{"1961-08-30 00:00:00.01a"},
{"1961-08-30 00:00:00.a"},
{"1996-12-10 12:26:19.1234567890"},
{null}
};
private Stream<String> invalidTimestampValues() {
return Stream.of(
"2009-11-01-01 10:50:01",
"aaaa-11-01-01 10:50",
"aaaa-11-01 10:50",
"1961--30 00:00:00",
"--30 00:00:00",
"-- 00:00:00",
"1961-1- 00:00:00",
"2009-11-01",
"10:50:01",
"1961-a-30 00:00:00",
"1961-01-bb 00:00:00",
"1961-08-30 00:00:00.",
"1961-08-30 :00:00",
"1961-08-30 00::00",
"1961-08-30 00:00:",
"1961-08-30 ::",
"1961-08-30 0a:00:00",
"1961-08-30 00:bb:00",
"1961-08-30 00:01:cc",
"1961-08-30 00:00:00.01a",
"1961-08-30 00:00:00.a",
"1996-12-10 12:26:19.1234567890",
null
);
}
/*
@ -750,65 +751,65 @@ public class TimestampTests extends BaseTest {
* to validate that an IllegalArgumentException will not be thrown from the
* valueOf method and the corect value from toString() is returned
*/
private Object[][] validTimestampValues() {
return new Object[][]{
{"1961-08-30 00:00:00", "1961-08-30 00:00:00.0"},
{"1961-08-30 11:22:33", "1961-08-30 11:22:33.0"},
{"1961-8-30 00:00:00", "1961-08-30 00:00:00.0"},
{"1966-08-1 00:00:00", "1966-08-01 00:00:00.0"},
{"1996-12-10 12:26:19.1", "1996-12-10 12:26:19.1"},
{"1996-12-10 12:26:19.12", "1996-12-10 12:26:19.12"},
{"1996-12-10 12:26:19.123", "1996-12-10 12:26:19.123"},
{"1996-12-10 12:26:19.1234", "1996-12-10 12:26:19.1234"},
{"1996-12-10 12:26:19.12345", "1996-12-10 12:26:19.12345"},
{"1996-12-10 12:26:19.123456", "1996-12-10 12:26:19.123456"},
{"1996-12-10 12:26:19.1234567", "1996-12-10 12:26:19.1234567"},
{"1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"},
{"1996-12-10 12:26:19.123456789", "1996-12-10 12:26:19.123456789"},
{"1996-12-10 12:26:19.000000001", "1996-12-10 12:26:19.000000001"},
{"1996-12-10 12:26:19.000000012", "1996-12-10 12:26:19.000000012"},
{"1996-12-10 12:26:19.000000123", "1996-12-10 12:26:19.000000123"},
{"1996-12-10 12:26:19.000001234", "1996-12-10 12:26:19.000001234"},
{"1996-12-10 12:26:19.000012345", "1996-12-10 12:26:19.000012345"},
{"1996-12-10 12:26:19.000123456", "1996-12-10 12:26:19.000123456"},
{"1996-12-10 12:26:19.001234567", "1996-12-10 12:26:19.001234567"},
{"1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"},
{"1996-12-10 12:26:19.0", "1996-12-10 12:26:19.0"},
{"1996-12-10 12:26:19.01230", "1996-12-10 12:26:19.0123"}
};
private Stream<Arguments> validTimestampValues() {
return Stream.of(
Arguments.of("1961-08-30 00:00:00", "1961-08-30 00:00:00.0"),
Arguments.of("1961-08-30 11:22:33", "1961-08-30 11:22:33.0"),
Arguments.of("1961-8-30 00:00:00", "1961-08-30 00:00:00.0"),
Arguments.of("1966-08-1 00:00:00", "1966-08-01 00:00:00.0"),
Arguments.of("1996-12-10 12:26:19.1", "1996-12-10 12:26:19.1"),
Arguments.of("1996-12-10 12:26:19.12", "1996-12-10 12:26:19.12"),
Arguments.of("1996-12-10 12:26:19.123", "1996-12-10 12:26:19.123"),
Arguments.of("1996-12-10 12:26:19.1234", "1996-12-10 12:26:19.1234"),
Arguments.of("1996-12-10 12:26:19.12345", "1996-12-10 12:26:19.12345"),
Arguments.of("1996-12-10 12:26:19.123456", "1996-12-10 12:26:19.123456"),
Arguments.of("1996-12-10 12:26:19.1234567", "1996-12-10 12:26:19.1234567"),
Arguments.of("1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"),
Arguments.of("1996-12-10 12:26:19.123456789", "1996-12-10 12:26:19.123456789"),
Arguments.of("1996-12-10 12:26:19.000000001", "1996-12-10 12:26:19.000000001"),
Arguments.of("1996-12-10 12:26:19.000000012", "1996-12-10 12:26:19.000000012"),
Arguments.of("1996-12-10 12:26:19.000000123", "1996-12-10 12:26:19.000000123"),
Arguments.of("1996-12-10 12:26:19.000001234", "1996-12-10 12:26:19.000001234"),
Arguments.of("1996-12-10 12:26:19.000012345", "1996-12-10 12:26:19.000012345"),
Arguments.of("1996-12-10 12:26:19.000123456", "1996-12-10 12:26:19.000123456"),
Arguments.of("1996-12-10 12:26:19.001234567", "1996-12-10 12:26:19.001234567"),
Arguments.of("1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"),
Arguments.of("1996-12-10 12:26:19.0", "1996-12-10 12:26:19.0"),
Arguments.of("1996-12-10 12:26:19.01230", "1996-12-10 12:26:19.0123")
);
}
private Object[][] validTimestampLongValues() {
return new Object[][]{
{1L, "1970-01-01 01:00:00.001"},
{-3600*1000L - 1, "1969-12-31 23:59:59.999"},
{-(20000L*365*24*60*60*1000), "18018-08-28 01:00:00.0"},
{Timestamp.valueOf("1961-08-30 11:22:33").getTime(), "1961-08-30 11:22:33.0"},
{Timestamp.valueOf("1961-08-30 11:22:33.54321000").getTime(), "1961-08-30 11:22:33.543"}, // nanoprecision lost
{new Timestamp(114, 10, 10, 10, 10, 10, 100000000).getTime(), "2014-11-10 10:10:10.1"},
{new Timestamp(0, 10, 10, 10, 10, 10, 100000).getTime(), "1900-11-10 10:10:10.0"}, // nanoprecision lost
{new Date(114, 10, 10).getTime(), "2014-11-10 00:00:00.0"},
{new Date(0, 10, 10).getTime(), "1900-11-10 00:00:00.0"},
{LocalDateTime.of(1960, 10, 10, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli(), "1960-10-10 19:10:10.0"},
private Stream<Arguments> validTimestampLongValues() {
return Stream.of(
Arguments.of(1L, "1970-01-01 01:00:00.001"),
Arguments.of(-3600*1000L - 1, "1969-12-31 23:59:59.999"),
Arguments.of(-(20000L*365*24*60*60*1000), "18018-08-28 01:00:00.0"),
Arguments.of(Timestamp.valueOf("1961-08-30 11:22:33").getTime(), "1961-08-30 11:22:33.0"),
Arguments.of(Timestamp.valueOf("1961-08-30 11:22:33.54321000").getTime(), "1961-08-30 11:22:33.543"), // nanoprecision lost
Arguments.of(new Timestamp(114, 10, 10, 10, 10, 10, 100000000).getTime(), "2014-11-10 10:10:10.1"),
Arguments.of(new Timestamp(0, 10, 10, 10, 10, 10, 100000).getTime(), "1900-11-10 10:10:10.0"), // nanoprecision lost
Arguments.of(new Date(114, 10, 10).getTime(), "2014-11-10 00:00:00.0"),
Arguments.of(new Date(0, 10, 10).getTime(), "1900-11-10 00:00:00.0"),
Arguments.of(LocalDateTime.of(1960, 10, 10, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli(), "1960-10-10 19:10:10.0"),
// millisecond timestamps wraps around at year 1, so Long.MIN_VALUE looks similar
// Long.MAX_VALUE, while actually representing 292278994 BCE
{Long.MIN_VALUE, "292278994-08-17 08:12:55.192"},
{Long.MAX_VALUE + 1, "292278994-08-17 08:12:55.192"},
{Long.MAX_VALUE, "292278994-08-17 08:12:55.807"},
{Long.MIN_VALUE - 1, "292278994-08-17 08:12:55.807"},
Arguments.of(Long.MIN_VALUE, "292278994-08-17 08:12:55.192"),
Arguments.of(Long.MAX_VALUE + 1, "292278994-08-17 08:12:55.192"),
Arguments.of(Long.MAX_VALUE, "292278994-08-17 08:12:55.807"),
Arguments.of(Long.MIN_VALUE - 1, "292278994-08-17 08:12:55.807"),
// wrap around point near 0001-01-01, test that we never get a negative year:
{-(1970L*365*24*60*60*1000), "0001-04-25 01:00:00.0"},
{-(1970L*365*24*60*60*1000 + 115*24*60*60*1000L), "0001-12-31 01:00:00.0"},
{-(1970L*365*24*60*60*1000 + 115*24*60*60*1000L - 23*60*60*1000L), "0001-01-01 00:00:00.0"},
Arguments.of(-(1970L*365*24*60*60*1000), "0001-04-25 01:00:00.0"),
Arguments.of(-(1970L*365*24*60*60*1000 + 115*24*60*60*1000L), "0001-12-31 01:00:00.0"),
Arguments.of(-(1970L*365*24*60*60*1000 + 115*24*60*60*1000L - 23*60*60*1000L), "0001-01-01 00:00:00.0"),
{LocalDateTime.of(0, 1, 1, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli() - 2*24*60*60*1000L, "0001-01-01 19:03:08.0"}, // 1 BCE
{LocalDateTime.of(0, 1, 1, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli() - 3*24*60*60*1000L, "0002-12-31 19:03:08.0"} // 2 BCE
};
Arguments.of(LocalDateTime.of(0, 1, 1, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli() - 2*24*60*60*1000L, "0001-01-01 19:03:08.0"), // 1 BCE
Arguments.of(LocalDateTime.of(0, 1, 1, 10, 10, 10, 50000).atZone(ZoneId.of("America/Los_Angeles"))
.toInstant().toEpochMilli() - 3*24*60*60*1000L, "0002-12-31 19:03:08.0") // 2 BCE
);
}
/*
@ -816,28 +817,28 @@ public class TimestampTests extends BaseTest {
* validate that the correct Nanos value is generated from the specified
* Timestamp
*/
private Object[][] validateNanos() {
return new Object[][]{
{"1961-08-30 00:00:00", 0},
{"1996-12-10 12:26:19.1", 100000000},
{"1996-12-10 12:26:19.12", 120000000},
{"1996-12-10 12:26:19.123", 123000000},
{"1996-12-10 12:26:19.1234", 123400000},
{"1996-12-10 12:26:19.12345", 123450000},
{"1996-12-10 12:26:19.123456", 123456000},
{"1996-12-10 12:26:19.1234567", 123456700},
{"1996-12-10 12:26:19.12345678", 123456780},
{"1996-12-10 12:26:19.123456789", 123456789},
{"1996-12-10 12:26:19.000000001", 1},
{"1996-12-10 12:26:19.000000012", 12},
{"1996-12-10 12:26:19.000000123", 123},
{"1996-12-10 12:26:19.000001234", 1234},
{"1996-12-10 12:26:19.000012345", 12345},
{"1996-12-10 12:26:19.000123456", 123456},
{"1996-12-10 12:26:19.001234567", 1234567},
{"1996-12-10 12:26:19.012345678", 12345678},
{"1996-12-10 12:26:19.0", 0},
{"1996-12-10 12:26:19.01230", 12300000}
};
private Stream<Arguments> validateNanos() {
return Stream.of(
Arguments.of("1961-08-30 00:00:00", 0),
Arguments.of("1996-12-10 12:26:19.1", 100000000),
Arguments.of("1996-12-10 12:26:19.12", 120000000),
Arguments.of("1996-12-10 12:26:19.123", 123000000),
Arguments.of("1996-12-10 12:26:19.1234", 123400000),
Arguments.of("1996-12-10 12:26:19.12345", 123450000),
Arguments.of("1996-12-10 12:26:19.123456", 123456000),
Arguments.of("1996-12-10 12:26:19.1234567", 123456700),
Arguments.of("1996-12-10 12:26:19.12345678", 123456780),
Arguments.of("1996-12-10 12:26:19.123456789", 123456789),
Arguments.of("1996-12-10 12:26:19.000000001", 1),
Arguments.of("1996-12-10 12:26:19.000000012", 12),
Arguments.of("1996-12-10 12:26:19.000000123", 123),
Arguments.of("1996-12-10 12:26:19.000001234", 1234),
Arguments.of("1996-12-10 12:26:19.000012345", 12345),
Arguments.of("1996-12-10 12:26:19.000123456", 123456),
Arguments.of("1996-12-10 12:26:19.001234567", 1234567),
Arguments.of("1996-12-10 12:26:19.012345678", 12345678),
Arguments.of("1996-12-10 12:26:19.0", 0),
Arguments.of("1996-12-10 12:26:19.01230", 12300000)
);
}
}

View File

@ -29,8 +29,10 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.JDBCType;
import java.sql.SQLException;
import java.util.stream.Stream;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.provider.Arguments;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class BaseTest {
@ -77,13 +79,8 @@ public class BaseTest {
/*
* DataProvider used to specify the standard JDBC Types
*/
protected Object[][] jdbcTypes() {
Object[][] o = new Object[JDBCType.values().length][1];
int pos = 0;
for (JDBCType c : JDBCType.values()) {
o[pos++][0] = c.getVendorTypeNumber();
}
return o;
protected Stream<Integer> jdbcTypes() {
return Stream.of(JDBCType.values()).map(JDBCType::getVendorTypeNumber);
}
/*
@ -91,14 +88,14 @@ public class BaseTest {
* that enquoteLiteral converts a string to a literal and every instance of
* a single quote will be converted into two single quotes in the literal.
*/
protected Object[][] validEnquotedLiteralValues() {
return new Object[][]{
{"Hello", "'Hello'"},
{"G'Day", "'G''Day'"},
{"'G''Day'", "'''G''''Day'''"},
{"I'''M", "'I''''''M'"},
{"The Dark Knight", "'The Dark Knight'"},
};
protected Stream<Arguments> validEnquotedLiteralValues() {
return Stream.of(
Arguments.of("Hello", "'Hello'"),
Arguments.of("G'Day", "'G''Day'"),
Arguments.of("'G''Day'", "'''G''''Day'''"),
Arguments.of("I'''M", "'I''''''M'"),
Arguments.of("The Dark Knight", "'The Dark Knight'")
);
}
/*
@ -106,35 +103,37 @@ public class BaseTest {
* that enqouteIdentifier returns a simple SQL Identifier or a
* quoted identifier
*/
protected Object[][] validEnquotedIdentifierValues() {
return new Object[][]{
{"b", false, "b"},
{"b", true, "\"b\""},
{MAX_LENGTH_IDENTIFIER, false, MAX_LENGTH_IDENTIFIER},
{MAX_LENGTH_IDENTIFIER, true, "\"" + MAX_LENGTH_IDENTIFIER + "\""},
{"Hello", false, "Hello"},
{"Hello", true, "\"Hello\""},
{"G'Day", false, "\"G'Day\""},
{"G'Day", true, "\"G'Day\""},
{"Bruce Wayne", false, "\"Bruce Wayne\""},
{"Bruce Wayne", true, "\"Bruce Wayne\""},
{"select", false, "\"select\""},
{"table", true, "\"table\""},
{"GoodDay$", false, "\"GoodDay$\""},
{"GoodDay$", true, "\"GoodDay$\""},};
protected Stream<Arguments> validEnquotedIdentifierValues() {
return Stream.of(
Arguments.of("b", false, "b"),
Arguments.of("b", true, "\"b\""),
Arguments.of(MAX_LENGTH_IDENTIFIER, false, MAX_LENGTH_IDENTIFIER),
Arguments.of(MAX_LENGTH_IDENTIFIER, true, "\"" + MAX_LENGTH_IDENTIFIER + "\""),
Arguments.of("Hello", false, "Hello"),
Arguments.of("Hello", true, "\"Hello\""),
Arguments.of("G'Day", false, "\"G'Day\""),
Arguments.of("G'Day", true, "\"G'Day\""),
Arguments.of("Bruce Wayne", false, "\"Bruce Wayne\""),
Arguments.of("Bruce Wayne", true, "\"Bruce Wayne\""),
Arguments.of("select", false, "\"select\""),
Arguments.of("table", true, "\"table\""),
Arguments.of("GoodDay$", false, "\"GoodDay$\""),
Arguments.of("GoodDay$", true, "\"GoodDay$\"")
);
}
/*
* DataProvider used to provide strings are invalid for enquoteIdentifier
* resulting in a SQLException being thrown
*/
protected Object[][] invalidEnquotedIdentifierValues() {
return new Object[][]{
{"Hel\"lo", false},
{"\"Hel\"lo\"", true},
{"Hello" + '\0', false},
{"", false},
{MAX_LENGTH_IDENTIFIER + 'a', false},};
protected Stream<Arguments> invalidEnquotedIdentifierValues() {
return Stream.of(
Arguments.of("Hel\"lo", false),
Arguments.of("\"Hel\"lo\"", true),
Arguments.of("Hello" + '\0', false),
Arguments.of("", false),
Arguments.of(MAX_LENGTH_IDENTIFIER + 'a', false)
);
}
/*
@ -142,21 +141,21 @@ public class BaseTest {
* that isSimpleIdentifier returns the correct value based on the
* identifier specified.
*/
protected Object[][] simpleIdentifierValues() {
return new Object[][]{
{"b", true},
{"Hello", true},
{"\"Gotham\"", false},
{"G'Day", false},
{"Bruce Wayne", false},
{"GoodDay$", false},
{"Dick_Grayson", true},
{"Batmobile1966", true},
{MAX_LENGTH_IDENTIFIER, true},
{MAX_LENGTH_IDENTIFIER + 'a', false},
{"", false},
{"select", false}
};
protected Stream<Arguments> simpleIdentifierValues() {
return Stream.of(
Arguments.of("b", true),
Arguments.of("Hello", true),
Arguments.of("\"Gotham\"", false),
Arguments.of("G'Day", false),
Arguments.of("Bruce Wayne", false),
Arguments.of("GoodDay$", false),
Arguments.of("Dick_Grayson", true),
Arguments.of("Batmobile1966", true),
Arguments.of(MAX_LENGTH_IDENTIFIER, true),
Arguments.of(MAX_LENGTH_IDENTIFIER + 'a', false),
Arguments.of("", false),
Arguments.of("select", false)
);
}
/*
@ -165,14 +164,14 @@ public class BaseTest {
* literal and every instance of
* a single quote will be converted into two single quotes in the literal.
*/
protected Object[][] validEnquotedNCharLiteralValues() {
return new Object[][]{
{"Hello", "N'Hello'"},
{"G'Day", "N'G''Day'"},
{"'G''Day'", "N'''G''''Day'''"},
{"I'''M", "N'I''''''M'"},
{"N'Hello'", "N'N''Hello'''"},
{"The Dark Knight", "N'The Dark Knight'"}
};
protected Stream<Arguments> validEnquotedNCharLiteralValues() {
return Stream.of(
Arguments.of("Hello", "N'Hello'"),
Arguments.of("G'Day", "N'G''Day'"),
Arguments.of("'G''Day'", "N'''G''''Day'''"),
Arguments.of("I'''M", "N'I''''''M'"),
Arguments.of("N'Hello'", "N'N''Hello'''"),
Arguments.of("The Dark Knight", "N'The Dark Knight'")
);
}
}

View File

@ -1,7 +1,7 @@
# JDBC unit tests uses TestNG
TestNG.dirs= .
# JDBC unit tests uses JUnit
JUnit.dirs= .
othervm.dirs= .
lib.dirs = /java/sql/testng
lib.dirs = /java/sql/junit
modules = java.sql.rowset/com.sun.rowset \
java.sql.rowset/com.sun.rowset.internal \
java.sql.rowset/com.sun.rowset.providers

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -40,14 +40,19 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Calendar;
import java.util.stream.Stream;
import javax.sql.RowSet;
import javax.sql.rowset.serial.SerialArray;
import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialClob;
import javax.sql.rowset.serial.SerialRef;
import static org.testng.Assert.*;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.StubArray;
import util.StubBaseRowSet;
import util.StubBlob;
@ -67,7 +72,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
/*
* Create a RowSetListener and validate that notifyCursorMoved is called
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0000(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
rs.addRowSetListener(rsl);
@ -78,7 +84,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
/*
* Create a RowSetListener and validate that notifyRowChanged is called
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0001(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
rs.addRowSetListener(rsl);
@ -89,7 +96,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
/*
* Create a RowSetListener and validate that notifyRowSetChanged is called
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0002(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
rs.addRowSetListener(rsl);
@ -101,7 +109,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Create multiple RowSetListeners and validate that notifyRowSetChanged
* is called on all listeners
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0003(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
TestRowSetListener rsl2 = new TestRowSetListener();
@ -116,7 +125,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Create multiple RowSetListeners and validate that notifyRowChanged
* is called on all listeners
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0004(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
TestRowSetListener rsl2 = new TestRowSetListener();
@ -131,7 +141,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Create multiple RowSetListeners and validate that notifyCursorMoved
* is called on all listeners
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0005(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
TestRowSetListener rsl2 = new TestRowSetListener();
@ -146,7 +157,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Create a RowSetListener and validate that notifyRowSetChanged,
* notifyRowChanged() and notifyCursorMoved are called
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0006(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
rs.addRowSetListener(rsl);
@ -163,7 +175,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Create multiple RowSetListeners and validate that notifyRowSetChanged,
* notifyRowChanged() and notifyCursorMoved are called on all listeners
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0007(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
TestRowSetListener rsl2 = new TestRowSetListener();
@ -185,7 +198,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* remove the listener, invoke notifyRowSetChanged again and verify the
* listner is not called
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0008(StubBaseRowSet rs) throws Exception {
TestRowSetListener rsl = new TestRowSetListener();
rs.addRowSetListener(rsl);
@ -202,7 +216,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Set the base parameters and validate that the value set is
* the correct type and value
*/
@Test(dataProvider = "testBaseParameters")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("testBaseParameters")
public void baseRowSetTest0009(int pos, Object o) throws Exception {
assertTrue(getParam(pos, o).getClass().isInstance(o));
assertTrue(o.equals(getParam(pos, o)));
@ -212,7 +227,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Set the complex parameters and validate that the value set is
* the correct type
*/
@Test(dataProvider = "testAdvancedParameters")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("testAdvancedParameters")
public void baseRowSetTest0010(int pos, Object o) throws Exception {
assertTrue(getParam(pos, o).getClass().isInstance(o));
}
@ -220,7 +236,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
/*
* Validate setNull specifying the supported type values
*/
@Test(dataProvider = "jdbcTypes")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("jdbcTypes")
public void baseRowSetTest0011(Integer type) throws Exception {
brs = new StubBaseRowSet();
brs.setNull(1, type);
@ -231,7 +248,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
* Validate setNull specifying the supported type values and that
* typeName is set internally
*/
@Test(dataProvider = "jdbcTypes")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("jdbcTypes")
public void baseRowSetTest0012(Integer type) throws Exception {
brs = new StubBaseRowSet();
brs.setNull(1, type, "SUPERHERO");
@ -274,7 +292,8 @@ public class BaseRowSetTests extends CommonRowSetTests {
/*
* Validate that initParams() initializes the parameters
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void baseRowSetTest0016(StubBaseRowSet rs) throws Exception {
rs.setInt(1, 1);
rs.initParams();
@ -285,8 +304,7 @@ public class BaseRowSetTests extends CommonRowSetTests {
/*
* DataProvider used to set parameters for basic types that are supported
*/
@DataProvider(name = "testBaseParameters")
private Object[][] testBaseParameters() throws SQLException {
private Stream<Arguments> testBaseParameters() throws SQLException {
Integer aInt = 1;
Long aLong = Long.MAX_VALUE;
Short aShort = Short.MIN_VALUE;
@ -320,34 +338,32 @@ public class BaseRowSetTests extends CommonRowSetTests {
brs.setObject(17, query, Types.CHAR);
brs.setObject(18, query, Types.CHAR, 0);
return new Object[][]{
{1, aInt},
{2, query},
{3, aLong},
{4, aBoolean},
{5, aShort},
{6, aDouble},
{7, bd},
{8, aFloat},
{9, aByte},
{10, aDate},
{11, aTime},
{12, aTimeStamp},
{13, aDate},
{14, aTime},
{15, aTimeStamp},
{16, query},
{17, query},
{18, query}
};
return Stream.of(
Arguments.of(1, aInt),
Arguments.of(2, query),
Arguments.of(3, aLong),
Arguments.of(4, aBoolean),
Arguments.of(5, aShort),
Arguments.of(6, aDouble),
Arguments.of(7, bd),
Arguments.of(8, aFloat),
Arguments.of(9, aByte),
Arguments.of(10, aDate),
Arguments.of(11, aTime),
Arguments.of(12, aTimeStamp),
Arguments.of(13, aDate),
Arguments.of(14, aTime),
Arguments.of(15, aTimeStamp),
Arguments.of(16, query),
Arguments.of(17, query),
Arguments.of(18, query)
);
}
/*
* DataProvider used to set advanced parameters for types that are supported
*/
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {
private Stream<Arguments> testAdvancedParameters() throws SQLException {
byte[] bytes = new byte[10];
Ref aRef = new SerialRef(new StubRef("INTEGER", query));
@ -367,17 +383,17 @@ public class BaseRowSetTests extends CommonRowSetTests {
brs.setUnicodeStream(8, is, query.length());
brs.setCharacterStream(9, rdr, query.length());
return new Object[][]{
{1, bytes},
{2, is},
{3, aRef},
{4, aArray},
{5, aBlob},
{6, aClob},
{7, is},
{8, is},
{9, rdr}
};
return Stream.of(
Arguments.of(1, bytes),
Arguments.of(2, is),
Arguments.of(3, aRef),
Arguments.of(4, aArray),
Arguments.of(5, aBlob),
Arguments.of(6, aClob),
Arguments.of(7, is),
Arguments.of(8, is),
Arguments.of(9, rdr)
);
}
/*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,11 +23,15 @@
package test.rowset;
import java.sql.SQLException;
import java.util.stream.Stream;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
import static org.testng.Assert.*;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
public class RowSetFactoryTests extends BaseTest {
@ -50,7 +54,8 @@ public class RowSetFactoryTests extends BaseTest {
* Validate that the RowSetFactory returned by RowSetProvider.newFactory()
* returns the correct RowSet implementations
*/
@Test(dataProvider = "RowSetValues", enabled = true)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("RowSetValues")
public void test(RowSetFactory rsf, String impl) throws SQLException {
validateRowSetImpl(rsf, impl);
}
@ -98,22 +103,20 @@ public class RowSetFactoryTests extends BaseTest {
* DataProvider used to provide the RowSetFactory and the RowSet
* implementation that should be returned
*/
@DataProvider(name = "RowSetValues")
private Object[][] RowSetValues() throws SQLException {
private Stream<Arguments> RowSetValues() throws SQLException {
RowSetFactory rsf = RowSetProvider.newFactory();
RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null);
return new Object[][]{
{rsf, DEFAULT_CACHEDROWSET_CLASSNAME},
{rsf, DEFAULT_FILTEREDROWSET_CLASSNAME},
{rsf, DEFAULT_JDBCROWSET_CLASSNAME},
{rsf, DEFAULT_JOINROWSET_CLASSNAME},
{rsf, DEFAULT_WEBROWSET_CLASSNAME},
{rsf1, STUB_CACHEDROWSET_CLASSNAME},
{rsf1, STUB_FILTEREDROWSET_CLASSNAME},
{rsf1, STUB_JDBCROWSET_CLASSNAME},
{rsf1, STUB_JOINROWSET_CLASSNAME},
{rsf1, STUB_WEBROWSET_CLASSNAME}
};
return Stream.of(
Arguments.of(rsf, DEFAULT_CACHEDROWSET_CLASSNAME),
Arguments.of(rsf, DEFAULT_FILTEREDROWSET_CLASSNAME),
Arguments.of(rsf, DEFAULT_JDBCROWSET_CLASSNAME),
Arguments.of(rsf, DEFAULT_JOINROWSET_CLASSNAME),
Arguments.of(rsf, DEFAULT_WEBROWSET_CLASSNAME),
Arguments.of(rsf1, STUB_CACHEDROWSET_CLASSNAME),
Arguments.of(rsf1, STUB_FILTEREDROWSET_CLASSNAME),
Arguments.of(rsf1, STUB_JDBCROWSET_CLASSNAME),
Arguments.of(rsf1, STUB_JOINROWSET_CLASSNAME),
Arguments.of(rsf1, STUB_WEBROWSET_CLASSNAME)
);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,19 @@ package test.rowset;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.sql.RowSetMetaData;
import javax.sql.rowset.RowSetMetaDataImpl;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import util.BaseTest;
public class RowSetMetaDataTests extends BaseTest {
@ -40,7 +47,7 @@ public class RowSetMetaDataTests extends BaseTest {
// Instance to be used within the tests
private RowSetMetaDataImpl rsmd;
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
rsmd = new RowSetMetaDataImpl();
rsmd.setColumnCount(MAX_COLUMNS);
@ -49,325 +56,325 @@ public class RowSetMetaDataTests extends BaseTest {
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test(Integer col) throws Exception {
rsmd.getCatalogName(col);
assertThrows(SQLException.class, () -> rsmd.getCatalogName(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test01(Integer col) throws Exception {
rsmd.getColumnClassName(col);
assertThrows(SQLException.class, () -> rsmd.getColumnClassName(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test02(Integer col) throws Exception {
rsmd.getColumnDisplaySize(col);
assertThrows(SQLException.class, () -> rsmd.getColumnDisplaySize(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test03(Integer col) throws Exception {
rsmd.getColumnLabel(col);
assertThrows(SQLException.class, () -> rsmd.getColumnLabel(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test04(Integer col) throws Exception {
rsmd.getColumnName(col);
assertThrows(SQLException.class, () -> rsmd.getColumnName(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test05(Integer col) throws Exception {
rsmd.getColumnType(col);
assertThrows(SQLException.class, () -> rsmd.getColumnType(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test06(Integer col) throws Exception {
rsmd.getColumnTypeName(col);
assertThrows(SQLException.class, () -> rsmd.getColumnTypeName(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test07(Integer col) throws Exception {
rsmd.getPrecision(col);
assertThrows(SQLException.class, () -> rsmd.getPrecision(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test08(Integer col) throws Exception {
rsmd.getScale(col);
assertThrows(SQLException.class, () -> rsmd.getScale(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test09(Integer col) throws Exception {
rsmd.getSchemaName(col);
assertThrows(SQLException.class, () -> rsmd.getSchemaName(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test10(Integer col) throws Exception {
rsmd.getTableName(col);
assertThrows(SQLException.class, () -> rsmd.getTableName(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test11(Integer col) throws Exception {
rsmd.isAutoIncrement(col);
assertThrows(SQLException.class, () -> rsmd.isAutoIncrement(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test12(Integer col) throws Exception {
rsmd.isCaseSensitive(col);
assertThrows(SQLException.class, () -> rsmd.isCaseSensitive(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test13(Integer col) throws Exception {
rsmd.isCurrency(col);
assertThrows(SQLException.class, () -> rsmd.isCurrency(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test14(Integer col) throws Exception {
rsmd.isDefinitelyWritable(col);
assertThrows(SQLException.class, () -> rsmd.isDefinitelyWritable(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test15(Integer col) throws Exception {
rsmd.isNullable(col);
assertThrows(SQLException.class, () -> rsmd.isNullable(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test16(Integer col) throws Exception {
rsmd.isReadOnly(col);
assertThrows(SQLException.class, () -> rsmd.isReadOnly(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test17(Integer col) throws Exception {
rsmd.isSearchable(col);
assertThrows(SQLException.class, () -> rsmd.isSearchable(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test18(Integer col) throws Exception {
rsmd.isSigned(col);
assertThrows(SQLException.class, () -> rsmd.isSigned(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test19(Integer col) throws Exception {
rsmd.isWritable(col);
assertThrows(SQLException.class, () -> rsmd.isWritable(col));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test20(Integer col) throws Exception {
rsmd.setAutoIncrement(col, true);
assertThrows(SQLException.class, () -> rsmd.setAutoIncrement(col, true));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test21(Integer col) throws Exception {
rsmd.setCaseSensitive(col, true);
assertThrows(SQLException.class, () -> rsmd.setCaseSensitive(col, true));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test22(Integer col) throws Exception {
rsmd.setCatalogName(col, null);
assertThrows(SQLException.class, () -> rsmd.setCatalogName(col, null));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test23(Integer col) throws Exception {
rsmd.setColumnDisplaySize(col, 5);
assertThrows(SQLException.class, () -> rsmd.setColumnDisplaySize(col, 5));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test24(Integer col) throws Exception {
rsmd.setColumnLabel(col, "label");
assertThrows(SQLException.class, () -> rsmd.setColumnLabel(col, "label"));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test25(Integer col) throws Exception {
rsmd.setColumnName(col, "F1");
assertThrows(SQLException.class, () -> rsmd.setColumnName(col, "F1"));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test26(Integer col) throws Exception {
rsmd.setColumnType(col, Types.CHAR);
assertThrows(SQLException.class, () -> rsmd.setColumnType(col, Types.CHAR));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test27(Integer col) throws Exception {
rsmd.setColumnTypeName(col, "F1");
assertThrows(SQLException.class, () -> rsmd.setColumnTypeName(col, "F1"));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test28(Integer col) throws Exception {
rsmd.setCurrency(col, true);
assertThrows(SQLException.class, () -> rsmd.setCurrency(col, true));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test29(Integer col) throws Exception {
rsmd.setNullable(col, ResultSetMetaData.columnNoNulls);
assertThrows(SQLException.class, () -> rsmd.setNullable(col, ResultSetMetaData.columnNoNulls));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test30(Integer col) throws Exception {
rsmd.setPrecision(col, 2);
assertThrows(SQLException.class, () -> rsmd.setPrecision(col, 2));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test31(Integer col) throws Exception {
rsmd.setScale(col, 2);
assertThrows(SQLException.class, () -> rsmd.setScale(col, 2));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test32(Integer col) throws Exception {
rsmd.setSchemaName(col, "Gotham");
assertThrows(SQLException.class, () -> rsmd.setSchemaName(col, "Gotham"));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test33(Integer col) throws Exception {
rsmd.setSearchable(col, false);
assertThrows(SQLException.class, () -> rsmd.setSearchable(col, false));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test34(Integer col) throws Exception {
rsmd.setSigned(col, false);
assertThrows(SQLException.class, () -> rsmd.setSigned(col, false));
}
/*
* Validate a SQLException is thrown for an invalid column index
*/
@Test(dataProvider = "invalidColumnRanges",
expectedExceptions = SQLException.class)
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("invalidColumnRanges")
public void test35(Integer col) throws Exception {
rsmd.setTableName(col, "SUPERHEROS");
assertThrows(SQLException.class, () -> rsmd.setTableName(col, "SUPERHEROS"));
}
/*
@ -375,7 +382,8 @@ public class RowSetMetaDataTests extends BaseTest {
* Note: Once setColumnClassName is added to RowSetMetaData, this
* method will need to change.
*/
@Test(dataProvider = "columnClassNames")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("columnClassNames")
public void test36(Integer type, String name) throws Exception {
rsmd.setColumnType(1, type);
assertTrue(rsmd.getColumnClassName(1).equals(name));
@ -385,7 +393,8 @@ public class RowSetMetaDataTests extends BaseTest {
* Validate that all of the methods are accessible and the correct value
* is returned for each column
*/
@Test(dataProvider = "columnRanges")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("columnRanges")
public void test37(Integer col) throws Exception {
rsmd.setAutoIncrement(col, true);
assertTrue(rsmd.isAutoIncrement(col));
@ -429,7 +438,8 @@ public class RowSetMetaDataTests extends BaseTest {
/*
* Validate that the proper values are accepted by setNullable
*/
@Test(dataProvider = "validSetNullableValues")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("validSetNullableValues")
public void test38(Integer val) throws Exception {
rsmd.setNullable(1, val);
}
@ -437,7 +447,8 @@ public class RowSetMetaDataTests extends BaseTest {
/*
* Validate that the correct type is returned for the column
*/
@Test(dataProvider = "jdbcTypes")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("jdbcTypes")
public void test39(Integer type) throws Exception {
rsmd.setColumnType(1, type);
assertTrue(type == rsmd.getColumnType(1));
@ -446,7 +457,8 @@ public class RowSetMetaDataTests extends BaseTest {
/*
* Validate that the correct value is returned from the isXXX methods
*/
@Test(dataProvider = "trueFalse")
@ParameterizedTest(autoCloseArguments = false)
@ValueSource(booleans = {true, false})
public void test40(Boolean b) throws Exception {
rsmd.setAutoIncrement(1, b);
rsmd.setCaseSensitive(1, b);
@ -483,73 +495,62 @@ public class RowSetMetaDataTests extends BaseTest {
* to validate that an IllegalArgumentException will be thrown from the
* valueOf method
*/
@DataProvider(name = "validSetNullableValues")
private Object[][] validSetNullableValues() {
return new Object[][]{
{ResultSetMetaData.columnNoNulls},
{ResultSetMetaData.columnNullable},
{ResultSetMetaData.columnNullableUnknown}
};
private Stream<Integer> validSetNullableValues() {
return Stream.of(
ResultSetMetaData.columnNoNulls,
ResultSetMetaData.columnNullable,
ResultSetMetaData.columnNullableUnknown
);
}
/*
* DataProvider used to provide column indexes that are out of range so that
* SQLException is thrown
*/
@DataProvider(name = "invalidColumnRanges")
private Object[][] invalidColumnRanges() {
return new Object[][]{
{-1},
{0},
{MAX_COLUMNS + 1}
};
private Stream<Integer> invalidColumnRanges() {
return Stream.of(
-1,
0,
MAX_COLUMNS + 1
);
}
/*
* DataProvider used to provide the valid column ranges for the
* RowSetMetaDataImpl object
*/
@DataProvider(name = "columnRanges")
private Object[][] columnRanges() {
Object[][] o = new Object[MAX_COLUMNS][1];
for (int i = 1; i <= MAX_COLUMNS; i++) {
o[i - 1][0] = i;
}
return o;
private Stream<Integer> columnRanges() {
return IntStream.rangeClosed(1, MAX_COLUMNS).boxed();
}
/*
* DataProvider used to specify the value to set via setColumnType and
* the expected value to be returned from getColumnClassName
*/
@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
return new Object[][]{
{Types.CHAR, "java.lang.String"},
{Types.NCHAR, "java.lang.String"},
{Types.VARCHAR, "java.lang.String"},
{Types.NVARCHAR, "java.lang.String"},
{Types.LONGVARCHAR, "java.lang.String"},
{Types.LONGNVARCHAR, "java.lang.String"},
{Types.NUMERIC, "java.math.BigDecimal"},
{Types.DECIMAL, "java.math.BigDecimal"},
{Types.BIT, "java.lang.Boolean"},
{Types.TINYINT, "java.lang.Byte"},
{Types.SMALLINT, "java.lang.Short"},
{Types.INTEGER, "java.lang.Integer"},
{Types.FLOAT, "java.lang.Double"},
{Types.DOUBLE, "java.lang.Double"},
{Types.BINARY, "byte[]"},
{Types.VARBINARY, "byte[]"},
{Types.LONGVARBINARY, "byte[]"},
{Types.DATE, "java.sql.Date"},
{Types.TIME, "java.sql.Time"},
{Types.TIMESTAMP, "java.sql.Timestamp"},
{Types.CLOB, "java.sql.Clob"},
{Types.BLOB, "java.sql.Blob"}
};
private Stream<Arguments> columnClassNames() {
return Stream.of(
Arguments.of(Types.CHAR, "java.lang.String"),
Arguments.of(Types.NCHAR, "java.lang.String"),
Arguments.of(Types.VARCHAR, "java.lang.String"),
Arguments.of(Types.NVARCHAR, "java.lang.String"),
Arguments.of(Types.LONGVARCHAR, "java.lang.String"),
Arguments.of(Types.LONGNVARCHAR, "java.lang.String"),
Arguments.of(Types.NUMERIC, "java.math.BigDecimal"),
Arguments.of(Types.DECIMAL, "java.math.BigDecimal"),
Arguments.of(Types.BIT, "java.lang.Boolean"),
Arguments.of(Types.TINYINT, "java.lang.Byte"),
Arguments.of(Types.SMALLINT, "java.lang.Short"),
Arguments.of(Types.INTEGER, "java.lang.Integer"),
Arguments.of(Types.FLOAT, "java.lang.Double"),
Arguments.of(Types.DOUBLE, "java.lang.Double"),
Arguments.of(Types.BINARY, "byte[]"),
Arguments.of(Types.VARBINARY, "byte[]"),
Arguments.of(Types.LONGVARBINARY, "byte[]"),
Arguments.of(Types.DATE, "java.sql.Date"),
Arguments.of(Types.TIME, "java.sql.Time"),
Arguments.of(Types.TIMESTAMP, "java.sql.Timestamp"),
Arguments.of(Types.CLOB, "java.sql.Clob"),
Arguments.of(Types.BLOB, "java.sql.Blob")
);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,14 +27,19 @@ import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.SQLException;
import java.util.stream.Stream;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
import static org.testng.Assert.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import util.BaseTest;
import util.StubRowSetFactory;
@ -57,7 +62,7 @@ public class RowSetProviderTests extends BaseTest {
* Save off the original property value for javax.sql.rowset.RowSetFactory,
* original classloader and define the path to the jars directory
*/
@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
origFactoryProperty = System.getProperty("javax.sql.rowset.RowSetFactory");
cl = Thread.currentThread().getContextClassLoader();
@ -68,7 +73,7 @@ public class RowSetProviderTests extends BaseTest {
/*
* Install the original javax.sql.rowset.RowSetFactory property value
*/
@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
if (origFactoryProperty != null) {
System.setProperty("javax.sql.rowset.RowSetFactory",
@ -80,7 +85,7 @@ public class RowSetProviderTests extends BaseTest {
* Clear the javax.sql.rowset.RowSetFactory property value and
* reset the classloader to its original value
*/
@AfterMethod
@AfterEach
public void tearDownMethod() throws Exception {
System.clearProperty("javax.sql.rowset.RowSetFactory");
Thread.currentThread().setContextClassLoader(cl);
@ -89,7 +94,8 @@ public class RowSetProviderTests extends BaseTest {
/*
* Validate that the correct RowSetFactory is returned by newFactory().
*/
@Test(dataProvider = "RowSetFactoryValues")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("RowSetFactoryValues")
public void test(RowSetFactory rsf, String impl) throws SQLException {
validateProvider(rsf, impl);
}
@ -109,7 +115,7 @@ public class RowSetProviderTests extends BaseTest {
* Validate that the correct RowSetFactory is returned by newFactory()
* when specified by the javax.sql.rowset.RowSetFactory property.
*/
@Test(enabled = true)
@Test
public void test02() throws SQLException {
System.setProperty("javax.sql.rowset.RowSetFactory", STUB_FACTORY_CLASSNAME);
validateProvider(RowSetProvider.newFactory(), STUB_FACTORY_CLASSNAME);
@ -120,11 +126,13 @@ public class RowSetProviderTests extends BaseTest {
* when specified RowSetFactory specified by the
* javax.sql.rowset.RowSetFactory property is not valid.
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test03() throws SQLException {
System.setProperty("javax.sql.rowset.RowSetFactory",
"invalid.RowSetFactoryImpl");
RowSetFactory rsf = RowSetProvider.newFactory();
assertThrows(SQLException.class, () -> {
System.setProperty("javax.sql.rowset.RowSetFactory",
"invalid.RowSetFactoryImpl");
RowSetFactory rsf = RowSetProvider.newFactory();
});
}
/*
@ -144,13 +152,15 @@ public class RowSetProviderTests extends BaseTest {
* Validate that a SQLException is thrown by newFactory() if the default
* RowSetFactory specified by the ServiceLoader API is not valid
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test05() throws Exception {
File f = new File(jarPath + "badFactory");
URLClassLoader loader = new URLClassLoader(new URL[]{
new URL(f.toURI().toString())}, getClass().getClassLoader());
Thread.currentThread().setContextClassLoader(loader);
RowSetProvider.newFactory();
assertThrows(SQLException.class, () -> {
File f = new File(jarPath + "badFactory");
URLClassLoader loader = new URLClassLoader(new URL[]{
new URL(f.toURI().toString())}, getClass().getClassLoader());
Thread.currentThread().setContextClassLoader(loader);
RowSetProvider.newFactory();
});
}
/*
@ -174,16 +184,15 @@ public class RowSetProviderTests extends BaseTest {
* DataProvider used to provide a RowSetFactory and the expected
* RowSetFactory implementation that should be returned
*/
@DataProvider(name = "RowSetFactoryValues")
private Object[][] RowSetFactoryValues() throws SQLException {
private Stream<Arguments> RowSetFactoryValues() throws SQLException {
RowSetFactory rsf = RowSetProvider.newFactory();
RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null);
RowSetFactory rsf2 = RowSetProvider.newFactory(DEFFAULT_FACTORY_CLASSNAME, null);
return new Object[][]{
{rsf, NO_VALADATE_IMPL},
{rsf, DEFFAULT_FACTORY_CLASSNAME},
{rsf1, STUB_FACTORY_CLASSNAME},
{rsf2, DEFFAULT_FACTORY_CLASSNAME}
};
return Stream.of(
Arguments.of(rsf, NO_VALADATE_IMPL),
Arguments.of(rsf, DEFFAULT_FACTORY_CLASSNAME),
Arguments.of(rsf1, STUB_FACTORY_CLASSNAME),
Arguments.of(rsf2, DEFFAULT_FACTORY_CLASSNAME)
);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,8 +24,10 @@ package test.rowset;
import java.sql.SQLException;
import javax.sql.rowset.RowSetWarning;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class RowSetWarningTests extends BaseTest {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,16 +25,17 @@ package test.rowset;
import java.util.Locale;
import java.sql.SQLException;
import javax.sql.rowset.RowSetProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
/**
* @test
* @bug 8294989
* @summary Check that the resource bundle can be accessed
* @throws SQLException if an unexpected error occurs
* @run testng/othervm
* @run junit/othervm
*/
public class ValidateResourceBundleAccess{
// Expected JDBCResourceBundle message, jdbcrowsetimpl.invalstate
@ -43,8 +44,8 @@ public class ValidateResourceBundleAccess{
private static final String RSREADERERROR = "Internal Error in RowSetReader: no connection or command";
// Checking against English messages, set to US Locale
@BeforeClass
public void setEnglishEnvironment() {
@BeforeAll
public static void setEnglishEnvironment() {
Locale.setDefault(Locale.US);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,24 +26,30 @@ import java.sql.SQLException;
import javax.sql.RowSet;
import javax.sql.rowset.FilteredRowSet;
import javax.sql.rowset.Predicate;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterEach;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import test.rowset.webrowset.CommonWebRowSetTests;
public class FilteredRowSetTests extends CommonWebRowSetTests {
private FilteredRowSet frs;
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
frs = createCoffeeHousesRowSet();
}
@AfterMethod
@AfterEach
public void tearDownMethod() throws Exception {
frs.close();
}
@ -83,7 +89,7 @@ public class FilteredRowSetTests extends CommonWebRowSetTests {
10023, 10040, 10042, 10024, 10039, 10041, 10035, 10037, 10034
};
frs.setFilter(new PrimaryKeyFilter(10000, 10999, 1));
assertEquals(getPrimaryKeys(frs), expectedKeys);
assertArrayEquals(expectedKeys, getPrimaryKeys(frs));
}
/*
@ -96,7 +102,7 @@ public class FilteredRowSetTests extends CommonWebRowSetTests {
10023, 10040, 10042, 10024, 10039, 10041, 10035, 10037, 10034
};
frs.setFilter(new PrimaryKeyFilter(10000, 10999, "STORE_ID"));
assertEquals(getPrimaryKeys(frs), expectedKeys);
assertArrayEquals(expectedKeys, getPrimaryKeys(frs));
}
@ -111,7 +117,7 @@ public class FilteredRowSetTests extends CommonWebRowSetTests {
};
String[] cityArray = {"SF", "LA"};
frs.setFilter(new CityFilter(cityArray, 2));
assertEquals(getPrimaryKeys(frs), expectedKeys);
assertArrayEquals(expectedKeys, getPrimaryKeys(frs));
}
/*
@ -125,14 +131,16 @@ public class FilteredRowSetTests extends CommonWebRowSetTests {
};
String[] cityArray = {"SF", "LA"};
frs.setFilter(new CityFilter(cityArray, "CITY"));
assertEquals(getPrimaryKeys(frs), expectedKeys);
assertArrayEquals(expectedKeys, getPrimaryKeys(frs));
}
// Tests that are common but need to be disabled due to an implementation bug
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0043(RowSet rs) throws Exception {
// Need to fix bug in FilteredRowSets
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,9 @@ import java.sql.SQLException;
import javax.sql.rowset.JdbcRowSet;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubDriver;
@ -41,7 +43,7 @@ public class JdbcRowSetDriverManagerTest extends BaseTest {
* Validate that JDBCRowSetImpl can connect to a JDBC driver that is
* register by DriverManager.
*/
@Test(enabled = true)
@Test
public void test0000() throws SQLException {
DriverManager.registerDriver(new StubDriver());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,16 +26,22 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import javax.sql.RowSet;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.JoinRowSet;
import javax.sql.rowset.RowSetMetaDataImpl;
import javax.sql.rowset.WebRowSet;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import test.rowset.webrowset.CommonWebRowSetTests;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
public class JoinRowSetTests extends CommonWebRowSetTests {
private final String SUPPLIERS_TABLE = "SUPPLIERS";
@ -150,8 +156,7 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
/*
* DataProvider used to set parameters for basic types that are supported
*/
@DataProvider(name = "createCachedRowSetsToUse")
private Object[][] createCachedRowSetsToUse() throws SQLException {
private Stream<Arguments> createCachedRowSetsToUse() throws SQLException {
CachedRowSet crs = rsf.createCachedRowSet();
initCoffeesMetaData(crs);
createCoffeesRows(crs);
@ -162,9 +167,7 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
createSuppiersRows(crs1);
// Make sure you are not on the insertRow
crs1.moveToCurrentRow();
return new Object[][]{
{crs, crs1}
};
return Stream.of(Arguments.of(crs, crs1));
}
/*
@ -178,13 +181,14 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
results.add(jrs.getInt("COF_ID"));
}
}
assertEquals(results.toArray(), EXPECTED);
assertArrayEquals(EXPECTED, results.toArray());
}
/*
* Join two CachedRowSets specifying a column name to join against
*/
@Test(dataProvider = "createCachedRowSetsToUse")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("createCachedRowSetsToUse")
public void joinRowSetTests0000(CachedRowSet crs, CachedRowSet crs1)
throws Exception {
@ -200,7 +204,8 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
/*
* Join two CachedRowSets specifying a column index to join against
*/
@Test(dataProvider = "createCachedRowSetsToUse")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("createCachedRowSetsToUse")
public void joinRowSetTests0001(CachedRowSet crs, CachedRowSet crs1)
throws Exception {
@ -216,7 +221,8 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
/*
* Join two CachedRowSets specifying a column name to join against
*/
@Test(dataProvider = "createCachedRowSetsToUse")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("createCachedRowSetsToUse")
public void joinRowSetTests0002(CachedRowSet crs, CachedRowSet crs1)
throws Exception {
@ -233,7 +239,8 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
/*
* Join two CachedRowSets specifying a column index to join against
*/
@Test(dataProvider = "createCachedRowSetsToUse")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("createCachedRowSetsToUse")
public void joinRowSetTests0003(CachedRowSet crs, CachedRowSet crs1)
throws Exception {
@ -251,7 +258,8 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
/*
* Join two CachedRowSets specifying a column name to join against
*/
@Test(dataProvider = "createCachedRowSetsToUse")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("createCachedRowSetsToUse")
public void joinRowSetTests0005(CachedRowSet crs, CachedRowSet crs1)
throws Exception {
@ -269,7 +277,8 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
/*
* Join two CachedRowSets specifying a column index to join against
*/
@Test(dataProvider = "createCachedRowSetsToUse")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("createCachedRowSetsToUse")
public void joinRowSetTests0006(CachedRowSet crs, CachedRowSet crs1)
throws Exception {
@ -286,39 +295,56 @@ public class JoinRowSetTests extends CommonWebRowSetTests {
}
// Disabled tests due to bugs in JoinRowSet
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0004(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0005(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0008(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0026(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0027(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0053(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0054(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void commonCachedRowSetTest0055(CachedRowSet rs) throws Exception {
}
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0009(WebRowSet wrs1) throws Exception {
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,9 +33,11 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.sql.rowset.serial.SQLInputImpl;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubArray;
import util.StubBlob;
@ -54,7 +56,7 @@ public class SQLInputImplTests extends BaseTest {
private SuperHero hero;
private final String sqlType = "SUPERHERO";
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
map = new HashMap<>();
impl = new TestSQLDataImpl("TestSQLData");
@ -68,18 +70,22 @@ public class SQLInputImplTests extends BaseTest {
* Validate that a SQLException is thrown if the attribute value is
* null
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test() throws Exception {
SQLInputImpl x = new SQLInputImpl(null, map);
assertThrows(SQLException.class, () -> {
SQLInputImpl x = new SQLInputImpl(null, map);
});
}
/*
* Validate that a SQLException is thrown if the map value is
* null
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test02() throws Exception {
SQLInputImpl x = new SQLInputImpl(typeValues, null);
assertThrows(SQLException.class, () -> {
SQLInputImpl x = new SQLInputImpl(typeValues, null);
});
}
/*
@ -124,7 +130,7 @@ public class SQLInputImplTests extends BaseTest {
/*
* Validate a Array can be read
*/
@Test(enabled = true)
@Test
public void test06() throws Exception {
Object[] coffees = new Object[]{"Espresso", "Colombian", "French Roast",
"Cappuccino"};
@ -139,7 +145,7 @@ public class SQLInputImplTests extends BaseTest {
/*
* Validate a Blob can be read
*/
@Test(enabled = true)
@Test
public void test07() throws Exception {
Blob b = new StubBlob();
Object[] values = {b};
@ -153,7 +159,7 @@ public class SQLInputImplTests extends BaseTest {
/*
* Validate a Clob can be read
*/
@Test(enabled = true)
@Test
public void test08() throws Exception {
Clob c = new StubClob();
Object[] values = {c};
@ -166,7 +172,7 @@ public class SQLInputImplTests extends BaseTest {
/*
* Validate a Ref can be read
*/
@Test(enabled = true)
@Test
public void test09() throws Exception {
Ref ref = new StubRef(sqlType, hero);
Object[] values = {ref};
@ -179,7 +185,7 @@ public class SQLInputImplTests extends BaseTest {
/*
* Validate a URL can be read
*/
@Test(enabled = true)
@Test
public void test10() throws Exception {
URL u = new URL("http://www.oracle.com/");
Object[] values = {u};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -41,9 +41,11 @@ import javax.sql.rowset.serial.SerialClob;
import javax.sql.rowset.serial.SerialDatalink;
import javax.sql.rowset.serial.SerialRef;
import javax.sql.rowset.serial.SerialStruct;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubArray;
import util.StubBlob;
@ -64,7 +66,7 @@ public class SQLOutputImplTests extends BaseTest {
private SuperHero hero;
private SQLOutputImpl outImpl;
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
results = new Vector();
impl = new TestSQLDataImpl("TestSQLData");
@ -78,18 +80,22 @@ public class SQLOutputImplTests extends BaseTest {
* Validate that a SQLException is thrown if the attribute value is
* null
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test() throws Exception {
SQLOutputImpl x = new SQLOutputImpl(null, map);
assertThrows(SQLException.class, () -> {
SQLOutputImpl x = new SQLOutputImpl(null, map);
});
}
/*
* Validate that a SQLException is thrown if the map value is
* null
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test02() throws Exception {
SQLOutputImpl x = new SQLOutputImpl(results, null);
assertThrows(SQLException.class, () -> {
SQLOutputImpl x = new SQLOutputImpl(results, null);
});
}
/*
@ -109,7 +115,7 @@ public class SQLOutputImplTests extends BaseTest {
/*
* Validate a Array can be written and returned
*/
@Test(enabled = true)
@Test
public void test04() throws Exception {
Object[] coffees = new Object[]{"Espresso", "Colombian", "French Roast",
"Cappuccino"};
@ -123,7 +129,7 @@ public class SQLOutputImplTests extends BaseTest {
/*
* Validate a Blob can be written and returned
*/
@Test(enabled = true)
@Test
public void test05() throws Exception {
Blob b = new StubBlob();
outImpl.writeBlob(b);
@ -136,7 +142,7 @@ public class SQLOutputImplTests extends BaseTest {
/*
* Validate a Clob can be written and returned
*/
@Test(enabled = true)
@Test
public void test06() throws Exception {
Clob c = new StubClob();
outImpl.writeClob(c);
@ -148,7 +154,7 @@ public class SQLOutputImplTests extends BaseTest {
/*
* Validate a Ref can be written and returned
*/
@Test(enabled = true)
@Test
public void test07() throws Exception {
Ref ref = new StubRef(sqlType, hero);
outImpl.writeRef(ref);
@ -159,7 +165,7 @@ public class SQLOutputImplTests extends BaseTest {
/*
* Validate a Struct can be written and returned
*/
@Test(enabled = true)
@Test
public void test08() throws Exception {
Object[] attributes = new Object[]{"Bruce", "Wayne", 1939,
"Batman"};
@ -173,7 +179,7 @@ public class SQLOutputImplTests extends BaseTest {
/*
* Validate a DataLink can be written and returned
*/
@Test(enabled = true)
@Test
public void test09() throws Exception {
URL u = new URL("http://www.oracle.com/");
outImpl.writeURL(u);
@ -186,7 +192,7 @@ public class SQLOutputImplTests extends BaseTest {
/*
* Validate an Object implementing SQLData can be written and returned
*/
@Test(enabled = true)
@Test
public void test10() throws Exception {
Object[] attributes = new Object[]{"Bruce", "Wayne", 1939,
"Batman"};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,9 +29,11 @@ import java.util.HashMap;
import java.util.Map;
import javax.sql.rowset.serial.SerialArray;
import javax.sql.rowset.serial.SerialException;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubArray;
@ -42,7 +44,7 @@ public class SerialArrayTests extends BaseTest {
private Array a;
private Map<String, Class<?>> map;
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
coffees = new Object[]{"Espresso", "Colombian", "French Roast",
"Cappuccino"};
@ -61,111 +63,133 @@ public class SerialArrayTests extends BaseTest {
/*
* Validate a SQLException is thrown if the map is null
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test02() throws Exception {
SerialArray sa = new SerialArray(a, null);
assertThrows(SQLException.class, () -> {
SerialArray sa = new SerialArray(a, null);
});
}
/*
* Validate a SerialException is thrown when getResultSet() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test03() throws Exception {
SerialArray sa = new SerialArray(a);
sa.getResultSet();
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.getResultSet();
});
}
/*
* Validate a SerialException is thrown when getResultSet() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test04() throws Exception {
SerialArray sa = new SerialArray(a);
sa.getResultSet(null);
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.getResultSet(null);
});
}
/*
* Validate a SerialException is thrown when getResultSet() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test05() throws Exception {
SerialArray sa = new SerialArray(a);
sa.getResultSet(1, 1);
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.getResultSet(1, 1);
});
}
/*
* Validate a SerialException is thrown when getResultSet() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test06() throws Exception {
SerialArray sa = new SerialArray(a);
sa.getResultSet(1, 1, null);
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.getResultSet(1, 1, null);
});
}
/*
* Validate a SerialException is thrown when getArray() is invoked after
* free() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test07() throws Exception {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray();
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray();
});
}
/*
* Validate a SerialException is thrown when getArray() is invoked after
* free() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test08() throws Exception {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray(map);
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray(map);
});
}
/*
* Validate a SerialException is thrown when getArray() is invoked after
* free() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test09() throws Exception {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray(1, 1, map);
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray(1, 1, map);
});
}
/*
* Validate a SerialException is thrown when getArray() is invoked after
* free() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test10() throws Exception {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray(1, 1);
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getArray(1, 1);
});
}
/*
* Validate a SerialException is thrown when getBaseType() is invoked after
* free() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test11() throws Exception {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getBaseType();
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getBaseType();
});
}
/*
* Validate a SerialException is thrown when getBaseTypeName() is invoked after
* free() is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test12() throws Exception {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getBaseTypeName();
assertThrows(SerialException.class, () -> {
SerialArray sa = new SerialArray(a);
sa.free();
sa.getBaseTypeName();
});
}
/*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,10 @@ import java.io.OutputStream;
import java.util.Arrays;
import javax.sql.rowset.serial.SerialBlob;
import javax.sql.rowset.serial.SerialException;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubBlob;
@ -50,110 +52,130 @@ public class SerialBlobTests extends BaseTest {
* Validate calling getBinaryStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test01() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.getBinaryStream();
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.getBinaryStream();
});
}
/*
* Validate calling getBinaryStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test02() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.getBinaryStream(1, 5);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.getBinaryStream(1, 5);
});
}
/*
* Validate calling getBytes() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test03() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.getBytes(1, 1);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.getBytes(1, 1);
});
}
/*
* Validate calling getLength() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test04() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.length();
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.length();
});
}
/*
* Validate calling position() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test05() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.position(new byte[5], 1);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.position(new byte[5], 1);
});
}
/*
* Validate calling position() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test06() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.position(new StubBlob(), 1);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.position(new StubBlob(), 1);
});
}
/*
* Validate calling free() after calling setBinaryStream() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test07() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.setBinaryStream(5);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.setBinaryStream(5);
});
}
/*
* Validate calling free() after calling setBytes() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test08() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.setBytes(1, new byte[5]);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.setBytes(1, new byte[5]);
});
}
/*
* Validate calling setBytes() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test09() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.setBytes(1, new byte[10], 0, 5);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.setBytes(1, new byte[10], 0, 5);
});
}
/*
* Validate calling truncate() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test10() throws Exception {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.truncate(1);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(new StubBlob());
sb.free();
sb.truncate(1);
});
}
/*
@ -173,56 +195,68 @@ public class SerialBlobTests extends BaseTest {
/*
* Validate a SerialException is thrown if pos < 0 for getBinaryStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test12() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(-1, 3);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(-1, 3);
});
}
/*
* Validate a SerialException is thrown if pos = 0 for getBinaryStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test13() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(0, 3);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(0, 3);
});
}
/*
* Validate a SerialException is thrown if len > the length of the stream
* for getBinaryStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test14() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(0, 3);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(0, 3);
});
}
/*
* Validate a SerialException is thrown if length < 1
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test15() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(1, 0);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(1, 0);
});
}
/*
* Validate a SerialException is thrown if length > byte array length
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test16() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(1, 6);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(1, 6);
});
}
/*
* Validate a SerialException is thrown if pos > byte array length
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test17() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(bytes.length + 2, 6);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
InputStream is = sb.getBinaryStream(bytes.length + 2, 6);
});
}
/*
@ -241,12 +275,14 @@ public class SerialBlobTests extends BaseTest {
/*
* Test clone after free has been called that the clone is not accessible
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test19() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
sb.free();
SerialBlob sb2 = (SerialBlob) sb.clone();
InputStream is = sb2.getBinaryStream(1, 3);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
sb.free();
SerialBlob sb2 = (SerialBlob) sb.clone();
InputStream is = sb2.getBinaryStream(1, 3);
});
}
/*
@ -264,10 +300,12 @@ public class SerialBlobTests extends BaseTest {
* Validate a SerialException is thrown if byte[] is used to
* create the SeriablBlob and setBinaryStream is called
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test21() throws Exception {
SerialBlob sb = new SerialBlob(bytes);
sb.setBinaryStream(3);
assertThrows(SerialException.class, () -> {
SerialBlob sb = new SerialBlob(bytes);
sb.setBinaryStream(3);
});
}
/*
@ -281,7 +319,7 @@ public class SerialBlobTests extends BaseTest {
byte[] expected = new byte[]{1, 7, 8, 9, 5};
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(2, diff);
assertEquals(written, diff.length);
assertEquals(diff.length, written);
assertTrue(
Arrays.equals(sb.getBytes(1, (int) sb.length()),
expected),
@ -300,7 +338,7 @@ public class SerialBlobTests extends BaseTest {
byte[] expected = new byte[]{1, 8, 9, 0, 5};
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(2, diff, 1, bytesToWrite);
assertEquals(written, bytesToWrite);
assertEquals(bytesToWrite, written);
assertTrue(
Arrays.equals(sb.getBytes(1, (int) sb.length()),
expected),
@ -355,7 +393,7 @@ public class SerialBlobTests extends BaseTest {
byte[] pattern = new byte[]{3, 4};
SerialBlob sb = new SerialBlob(bytes);
long pos = sb.position(pattern, 1);
assertEquals(pos, expectedPos);
assertEquals(expectedPos, pos);
}
/*
@ -368,7 +406,7 @@ public class SerialBlobTests extends BaseTest {
byte[] pattern = new byte[]{3, 4, 5};
SerialBlob sb = new SerialBlob(bytes);
long pos = sb.position(pattern, 2);
assertEquals(pos, expectedPos);
assertEquals(expectedPos, pos);
}
/*
@ -381,7 +419,7 @@ public class SerialBlobTests extends BaseTest {
byte[] pattern = new byte[]{4, 6};
SerialBlob sb = new SerialBlob(new StubBlob());
long pos = sb.position(pattern, 1);
assertEquals(pos, expectedPos);
assertEquals(expectedPos, pos);
}
/*
@ -394,7 +432,7 @@ public class SerialBlobTests extends BaseTest {
byte[] pattern = new byte[]{6, 8};
SerialBlob sb = new SerialBlob(new StubBlob());
long pos = sb.position(pattern, 2);
assertEquals(pos, expectedPos);
assertEquals(expectedPos, pos);
}
/*
@ -411,8 +449,8 @@ public class SerialBlobTests extends BaseTest {
byte[] expected = new byte[]{1, 2, 3, 4, 7};
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(writePos, diff, 0, bytesToWrite);
assertEquals(written, bytesToWrite);
assertEquals(sb.getBytes(1, (int) sb.length()), expected);
assertEquals(bytesToWrite, written);
assertArrayEquals(expected, sb.getBytes(1, (int) sb.length()));
}
/*
@ -428,8 +466,8 @@ public class SerialBlobTests extends BaseTest {
byte[] expected = new byte[]{1, 2, 3, 4, 8, 9};
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(writePos, diff, 1, bytesToWrite);
assertEquals(written, bytesToWrite);
assertEquals(sb.getBytes(1, (int) sb.length()), expected);
assertEquals(bytesToWrite, written);
assertArrayEquals(expected, sb.getBytes(1, (int) sb.length()));
}
/*
@ -445,29 +483,33 @@ public class SerialBlobTests extends BaseTest {
byte[] expected = new byte[]{1, 2, 3, 4, 5, 8, 9, 0};
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(writePos, diff, 1, bytesToWrite);
assertEquals(written, bytesToWrite);
assertEquals(sb.getBytes(1, (int) sb.length()), expected);
assertEquals(bytesToWrite, written);
assertArrayEquals(expected, sb.getBytes(1, (int) sb.length()));
}
/*
* Validate a SerialException is thrown if length < 0 for setBytes
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test34() throws Exception {
int length = -1;
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(1, new byte[]{1}, 1, length);
assertThrows(SerialException.class, () -> {
int length = -1;
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(1, new byte[]{1}, 1, length);
});
}
/*
* Validate a SerialException is thrown if length + offset >
* Integer.MAX_VALUE for setBytes
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test35() throws Exception {
int offset = 1;
int length = Integer.MAX_VALUE;
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(1, new byte[]{1, 2, 3}, offset, length);
assertThrows(SerialException.class, () -> {
int offset = 1;
int length = Integer.MAX_VALUE;
SerialBlob sb = new SerialBlob(bytes);
int written = sb.setBytes(1, new byte[]{1, 2, 3}, offset, length);
});
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,11 @@ import java.io.Reader;
import java.io.Writer;
import javax.sql.rowset.serial.SerialClob;
import javax.sql.rowset.serial.SerialException;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubClob;
@ -56,192 +59,228 @@ public class SerialClobTests extends BaseTest {
* Validate calling getCharacterStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test01() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getCharacterStream();
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getCharacterStream();
});
}
/*
* Validate calling getCharacterStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test02() throws Exception {
SerialClob sc = new SerialClob(chars);
sc.free();
sc.getCharacterStream();
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(chars);
sc.free();
sc.getCharacterStream();
});
}
/*
* Validate calling getCharacterStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test03() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getCharacterStream(1, 5);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getCharacterStream(1, 5);
});
}
/*
* Validate calling getSubString() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test04() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getSubString(1, 1);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getSubString(1, 1);
});
}
/*
* Validate calling truncate() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test05() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.truncate(1);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.truncate(1);
});
}
/*
* Validate calling getAsciiStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test06() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getAsciiStream();
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.getAsciiStream();
});
}
/*
* Validate calling length() after calling free() throws an SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test07() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.length();
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.length();
});
}
/*
* Validate calling position() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test08() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.position("hello", 1);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.position("hello", 1);
});
}
/*
* Validate calling position() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test09() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.position(new StubClob(), 1);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.position(new StubClob(), 1);
});
}
/*
* Validate calling setAsciiStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test10() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setAsciiStream(5);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setAsciiStream(5);
});
}
/*
* Validate calling setCharacterStream() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test11() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setCharacterStream(5);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setCharacterStream(5);
});
}
/*
* Validate calling setString() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test12() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setString(1, "hello");
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setString(1, "hello");
});
}
/*
* Validate calling setString() after calling free() throws an
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test13() throws Exception {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setString(1, "hello", 0, 5);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(new StubClob());
sc.free();
sc.setString(1, "hello", 0, 5);
});
}
/*
* Test that SerialException is thrown if pos < 0 on a call to
* getCharacterStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test14() throws Exception {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(-1, 5);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(-1, 5);
});
}
/*
* Test that SerialException is thrown if pos = 0 on a call to
* getCharacterStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test15() throws Exception {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(0, 5);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(0, 5);
});
}
/*
* Test that SerialException is thrown if pos = 0 on a call to
* getCharacterStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test16() throws Exception {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(1, 100);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(1, 100);
});
}
/*
* Test that SerialException is thrown if length = 0 on a call to
* getCharacterStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test17() throws Exception {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(1, 0);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(1, 0);
});
}
/*
* Test that SerialException is thrown if pos > length on a call to
* getCharacterStream
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test18() throws Exception {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(100, 5);
assertThrows(SerialException.class, () -> {
SerialClob sc = new SerialClob(chars);
sc.getCharacterStream(100, 5);
});
}
/*
@ -401,7 +440,7 @@ public class SerialClobTests extends BaseTest {
String expected = "Hello, I am the Batman!";
SerialClob sc = new SerialClob(val.toCharArray());
int written = sc.setString(13, val1);
assertEquals(val1.length(), written);
assertEquals(written, val1.length());
assertTrue(expected.equals(sc.getSubString(1, (int) sc.length())));
}
@ -420,8 +459,8 @@ public class SerialClobTests extends BaseTest {
String expected = "Hi, I am the Joker!!!!!";
SerialClob sc = new SerialClob(val.toCharArray());
int written = sc.setString(writePos, val1, offset, expectedWritten);
assertEquals(written, expectedWritten);
assertEquals(sc.getSubString(1, (int) sc.length()), expected);
assertEquals(expectedWritten, written);
assertEquals(expected, sc.getSubString(1, (int) sc.length()));
}
/*
@ -478,7 +517,8 @@ public class SerialClobTests extends BaseTest {
* Check that getCharacterStream() returns a Reader and that the char[] that
* was specified to create the SerialClob can be returned via the Reader
*/
@Test(enabled = false)
@Test
@Disabled
public void test37() throws Exception {
SerialClob sc = new SerialClob(chars);
String expected = "ello w";
@ -504,12 +544,14 @@ public class SerialClobTests extends BaseTest {
* Check calling setString() with offset > val1.length() throws a
* SerialException
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test39() throws Exception {
String val1 = "hello";
int offset = val1.length() + 1;
SerialClob sc = new SerialClob(chars);
sc.setString(1, val1, offset, 0);
assertThrows(SerialException.class, () -> {
String val1 = "hello";
int offset = val1.length() + 1;
SerialClob sc = new SerialClob(chars);
sc.setString(1, val1, offset, 0);
});
}
/*
@ -526,8 +568,8 @@ public class SerialClobTests extends BaseTest {
String expected = "Hello, I am the Joker, who are you?!";
SerialClob sc = new SerialClob(val.toCharArray());
int written = sc.setString(writePos, val1, offset, expectedWritten);
assertEquals(written, expectedWritten);
assertEquals(sc.getSubString(1, (int) sc.length()), expected);
assertEquals(expectedWritten, written);
assertEquals(expected, sc.getSubString(1, (int) sc.length()));
}
/*
@ -544,29 +586,33 @@ public class SerialClobTests extends BaseTest {
String expected = "Hi, I am the Joker!";
SerialClob sc = new SerialClob(val.toCharArray());
int written = sc.setString(writePos, val1, offset, expectedWritten);
assertEquals(written, expectedWritten);
assertEquals(sc.getSubString(1, (int) sc.length()), expected);
assertEquals(expectedWritten, written);
assertEquals(expected, sc.getSubString(1, (int) sc.length()));
}
/*
* Validate a SerialException is thrown if length < 0 for setString
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test42() throws Exception {
int length = -1;
SerialClob sc = new SerialClob(chars);
int written = sc.setString(1, "hello", 1, length);
assertThrows(SerialException.class, () -> {
int length = -1;
SerialClob sc = new SerialClob(chars);
int written = sc.setString(1, "hello", 1, length);
});
}
/*
* Validate a SerialException is thrown if length + offset >
* Integer.MAX_VALUE for setString
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test43() throws Exception {
int offset = 1;
int length = Integer.MAX_VALUE;
SerialClob sc = new SerialClob(chars);
int written = sc.setString(1, "hello", offset, length);
assertThrows(SerialException.class, () -> {
int offset = 1;
int length = Integer.MAX_VALUE;
SerialClob sc = new SerialClob(chars);
int written = sc.setString(1, "hello", offset, length);
});
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,11 @@ package test.rowset.serial;
import java.net.URL;
import javax.sql.rowset.serial.SerialDatalink;
import javax.sql.rowset.serial.SerialException;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SerialDataLinkTests extends BaseTest {
@ -36,7 +38,7 @@ public class SerialDataLinkTests extends BaseTest {
private URL u1;
private SerialDatalink dl;
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
u = new URL("http://www.oracle.com/");
u1 = new URL("http://www.usatoday.com/");
@ -46,9 +48,11 @@ public class SerialDataLinkTests extends BaseTest {
/*
* Validate that a SerialException is thrown if the URL is null
*/
@Test(expectedExceptions = SerialException.class)
@Test
public void test() throws Exception {
SerialDatalink dl1 = new SerialDatalink(null);
assertThrows(SerialException.class, () -> {
SerialDatalink dl1 = new SerialDatalink(null);
});
}
/*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,8 +24,10 @@ package test.rowset.serial;
import java.sql.SQLException;
import javax.sql.rowset.serial.SerialException;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SerialExceptionTests extends BaseTest {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,11 @@ import java.util.Arrays;
import javax.sql.rowset.RowSetMetaDataImpl;
import javax.sql.rowset.serial.SerialException;
import javax.sql.rowset.serial.SerialJavaObject;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SerialJavaObjectTests extends BaseTest {
@ -37,18 +40,23 @@ public class SerialJavaObjectTests extends BaseTest {
* Validate that an NPE is thrown when null is specified to create
* the SerialJavaObject
*/
@Test(expectedExceptions = NullPointerException.class)
@Test
public void test() throws Exception {
SerialJavaObject sjo = new SerialJavaObject(null);
assertThrows(NullPointerException.class, () -> {
SerialJavaObject sjo = new SerialJavaObject(null);
});
}
/*
* Validate that a SerialException is thrown when the object specified
* contains public static fields
*/
@Test(expectedExceptions = SerialException.class, enabled = false)
@Test
@Disabled
public void test01() throws Exception {
SerialJavaObject sjo = new SerialJavaObject(new RowSetMetaDataImpl());
assertThrows(SerialException.class, () -> {
SerialJavaObject sjo = new SerialJavaObject(new RowSetMetaDataImpl());
});
}
/*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,9 +27,12 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.sql.rowset.serial.SerialRef;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubRef;
import util.SuperHero;
@ -41,7 +44,7 @@ public class SerialRefTests extends BaseTest {
private final String sqlType = "SUPERHERO";
private SuperHero hero;
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
map.put(sqlType, Class.forName("util.SuperHero"));
hero = new SuperHero(sqlType, "Bruce", "Wayne", 1939, "Batman");
@ -51,18 +54,22 @@ public class SerialRefTests extends BaseTest {
/*
* Validate that a SQLException() is thrown if the Ref is null
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test01() throws Exception {
SerialRef sr = new SerialRef(null);
assertThrows(SQLException.class, () -> {
SerialRef sr = new SerialRef(null);
});
}
/*
* Validate that a SQLException() is thrown if the typeName is null in the
* Ref used to create the SerialRef
*/
@Test(expectedExceptions = SQLException.class)
@Test
public void test02() throws Exception {
SerialRef sr = new SerialRef(new StubRef(null, hero));
assertThrows(SQLException.class, () -> {
SerialRef sr = new SerialRef(new StubRef(null, hero));
});
}
/*
@ -72,7 +79,7 @@ public class SerialRefTests extends BaseTest {
@Test
public void test03() throws Exception {
SerialRef sr = new SerialRef(ref);
assertEquals(sr.getBaseTypeName(), sqlType);
assertEquals(sqlType, sr.getBaseTypeName());
}
/*
@ -87,7 +94,8 @@ public class SerialRefTests extends BaseTest {
/*
* Validate that getObject() returns the same object used to create the Ref
*/
@Test(enabled = false)
@Test
@Disabled
public void test05() throws Exception {
SerialRef sr = new SerialRef(ref);
assertTrue(hero.equals(sr.getObject(map)));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,9 +27,11 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.sql.rowset.serial.SerialStruct;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubStruct;
import util.SuperHero;
@ -42,7 +44,7 @@ public class SerialStructTests extends BaseTest {
private final String sqlType = "SUPERHERO";
private SuperHero hero;
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
attributes = new Object[]{"Bruce", "Wayne", 1939,
"Batman"};
@ -58,7 +60,7 @@ public class SerialStructTests extends BaseTest {
@Test
public void test01() throws Exception {
SerialStruct ss = new SerialStruct(struct, map);
assertEquals(ss.getSQLTypeName(), sqlType);
assertEquals(sqlType, ss.getSQLTypeName());
}
/*
@ -68,7 +70,7 @@ public class SerialStructTests extends BaseTest {
@Test
public void test02() throws Exception {
SerialStruct ss = new SerialStruct(hero, map);
assertEquals(ss.getSQLTypeName(), sqlType);
assertEquals(sqlType, ss.getSQLTypeName());
}
/*

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,8 +24,10 @@ package test.rowset.spi;
import java.sql.SQLException;
import javax.sql.rowset.spi.SyncFactoryException;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import util.BaseTest;
public class SyncFactoryExceptionTests extends BaseTest {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,9 +33,11 @@ import javax.naming.Context;
import javax.sql.rowset.spi.SyncFactory;
import javax.sql.rowset.spi.SyncFactoryException;
import javax.sql.rowset.spi.SyncProvider;
import static org.testng.Assert.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.PropertyStubProvider;
import util.StubSyncProvider;
import util.StubContext;
@ -67,7 +69,7 @@ public class SyncFactoryTests {
ctx = new StubContext();
}
@BeforeMethod
@BeforeEach
public void setUpMethod() throws Exception {
// Make sure the provider provider that is registered is removed
// before each run
@ -120,17 +122,21 @@ public class SyncFactoryTests {
/*
* Validate that a SyncFactoryException is thrown if the ProviderID is null
*/
@Test(expectedExceptions = SyncFactoryException.class)
@Test
public void test03() throws SyncFactoryException {
SyncProvider p = SyncFactory.getInstance(null);
assertThrows(SyncFactoryException.class, () -> {
SyncProvider p = SyncFactory.getInstance(null);
});
}
/*
* Validate that a SyncFactoryException is thrown if the Logger is null
*/
@Test(expectedExceptions = SyncFactoryException.class,enabled=true)
@Test
public void test04() throws SyncFactoryException {
Logger l = SyncFactory.getLogger();
assertThrows(SyncFactoryException.class, () -> {
Logger l = SyncFactory.getLogger();
});
}
/*
@ -179,15 +185,15 @@ public class SyncFactoryTests {
* Validate that setJNDIContext throws a SyncFactoryException if the
* context is null
*/
@Test(expectedExceptions = SyncFactoryException.class, enabled=true)
@Test
public void test08() throws Exception {
SyncFactory.setJNDIContext(null);
assertThrows(SyncFactoryException.class, () -> SyncFactory.setJNDIContext(null));
}
/*
* Validate that setJNDIContext succeeds
*/
@Test(enabled=true)
@Test
public void test09() throws Exception {
SyncFactory.setJNDIContext(ctx);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,11 +27,12 @@ import java.sql.SQLException;
import javax.sql.rowset.spi.SyncProviderException;
import javax.sql.rowset.spi.SyncResolver;
import static org.testng.Assert.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import util.BaseTest;
import util.StubSyncResolver;
@ -40,16 +41,16 @@ public class SyncProviderExceptionTests extends BaseTest {
// Used by SyncProviderException::getSyncResolver tests
private SyncResolver resolver;
@BeforeClass
@BeforeAll
public static void setUpClass() throws Exception {
System.out.println(System.getProperty("java.naming.factory.initial"));
}
@AfterClass
@AfterAll
public static void tearDownClass() throws Exception {
}
@BeforeMethod
@BeforeEach
public void setupTest() {
resolver = new SyncProviderException().getSyncResolver();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,11 +35,15 @@ import java.math.BigDecimal;
import java.sql.ResultSet;
import java.util.Arrays;
import javax.sql.rowset.WebRowSet;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertEqualsNoOrder;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import test.rowset.cachedrowset.CommonCachedRowSetTests;
public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
@ -131,10 +135,11 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
/*
* Validate the expected Rows are contained within the RowSet
*/
@Test(dataProvider = "rowsetUsingCoffees")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowsetUsingCoffees")
public void WebRowSetTest0000(WebRowSet wrs) throws Exception {
assertEquals(getPrimaryKeys(wrs), COFFEES_PRIMARY_KEYS);
assertEquals(wrs.size(), COFFEES_ROWS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs));
assertEquals(COFFEES_ROWS, wrs.size());
wrs.close();
}
@ -142,14 +147,15 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* Validate the expected Rows are contained within the RowSet
* populated by readXML(Reader)
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0001(WebRowSet wrs1) throws Exception {
try (FileReader fr = new FileReader(COFFEE_ROWS_XML)) {
wrs1.readXml(fr);
}
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertEquals(wrs1.size(), COFFEES_ROWS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
assertEquals(COFFEES_ROWS, wrs1.size());
wrs1.close();
}
@ -158,13 +164,14 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* Validate the expected Rows are contained within the RowSet
* populated by readXML(InputStream)
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0002(WebRowSet wrs1) throws Exception {
try (FileInputStream fis = new FileInputStream(COFFEE_ROWS_XML)) {
wrs1.readXml(fis);
}
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertEquals(wrs1.size(), COFFEES_ROWS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
assertEquals(COFFEES_ROWS, wrs1.size());
wrs1.close();
}
@ -173,12 +180,13 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* back via readXML(InputStream) and validate the primary keys
* are the same
*/
@Test(dataProvider = "rowsetUsingCoffees")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowsetUsingCoffees")
public void WebRowSetTest0003(WebRowSet wrs) throws Exception {
ByteArrayOutputStream baos = writeWebRowSetWithOutputStream(wrs);
try (WebRowSet wrs1 = readWebRowSetWithOInputStream(baos)) {
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertEquals(wrs1.size(), COFFEES_ROWS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
assertEquals(COFFEES_ROWS, wrs1.size());
}
}
@ -187,14 +195,15 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* back via readXML(InputStream) and validate the primary keys
* are the same
*/
@Test(dataProvider = "rowsetUsingCoffees")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowsetUsingCoffees")
public void WebRowSetTest0004(WebRowSet wrs) throws Exception {
ResultSet rs = wrs;
rs.beforeFirst();
ByteArrayOutputStream baos = writeWebRowSetWithOutputStream(rs);
try (WebRowSet wrs1 = readWebRowSetWithOInputStream(baos)) {
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertEquals(wrs1.size(), COFFEES_ROWS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
assertEquals(COFFEES_ROWS, wrs1.size());
}
}
@ -203,12 +212,13 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* back via readXML(Reader) and validate the primary keys
* are the same
*/
@Test(dataProvider = "rowsetUsingCoffees")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowsetUsingCoffees")
public void WebRowSetTest0005(WebRowSet wrs) throws Exception {
ByteArrayOutputStream baos = writeWebRowSetWithOutputStreamWithWriter(wrs);
try (WebRowSet wrs1 = readWebRowSetWithOInputStreamWithReader(baos)) {
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertEquals(wrs1.size(), COFFEES_ROWS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
assertEquals(COFFEES_ROWS, wrs1.size());
}
}
@ -217,14 +227,15 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* back via readXML(Reader) and validate the primary keys
* are the same
*/
@Test(dataProvider = "rowsetUsingCoffees")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowsetUsingCoffees")
public void WebRowSetTest0006(WebRowSet wrs) throws Exception {
ResultSet rs = wrs;
rs.beforeFirst();
ByteArrayOutputStream baos = writeWebRowSetWithOutputStreamWithWriter(rs);
try (WebRowSet wrs1 = readWebRowSetWithOInputStreamWithReader(baos)) {
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertEquals(wrs1.size(), COFFEES_ROWS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
assertEquals(COFFEES_ROWS, wrs1.size());
}
}
@ -232,11 +243,13 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* Validate the expected Rows are contained within the RowSet
* after deleting the specified rows
*/
@Test(dataProvider = "rowsetUsingCoffees", enabled = false)
@Disabled
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowsetUsingCoffees")
public void WebRowSetTest0007(WebRowSet wrs) throws Exception {
assertEquals(getPrimaryKeys(wrs), COFFEES_PRIMARY_KEYS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs));
int[] rowsToDelete = {2, 4};
assertEquals(getPrimaryKeys(wrs), COFFEES_PRIMARY_KEYS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs));
for (int row : rowsToDelete) {
assertTrue(deleteRowByPrimaryKey(wrs, row, 1));
}
@ -262,12 +275,13 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* that was populated by reading an xml file with all rows
* marked as a currentRow
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0008(WebRowSet wrs1) throws Exception {
FileInputStream fis = new FileInputStream(COFFEE_ROWS_XML);
wrs1.readXml(fis);
assertTrue(wrs1.size() == COFFEES_ROWS);
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
// Validate that the rows are not marked as deleted, inserted or updated
wrs1.beforeFirst();
while (wrs1.next()) {
@ -284,14 +298,15 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* Also validate that they are or are not visible based on the
* setShowDeleted value
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0009(WebRowSet wrs1) throws Exception {
int[] rowsToDelete = {2, 4};
Object[] expectedRows = {1, 3, 5};
FileInputStream fis = new FileInputStream(DELETED_COFFEE_ROWS_XML);
wrs1.readXml(fis);
assertTrue(wrs1.size() == COFFEES_ROWS);
assertEquals(getPrimaryKeys(wrs1), expectedRows);
assertArrayEquals(expectedRows, getPrimaryKeys(wrs1));
// With setShowDeleted(false) which is the default,
// the deleted row should not be visible
for (int row : rowsToDelete) {
@ -302,7 +317,7 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
for (int row : rowsToDelete) {
assertTrue(findRowByPrimaryKey(wrs1, row, 1));
}
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
wrs1.close();
}
@ -311,12 +326,13 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* Validate that the correct row in the WebRowSet that had been created
* from an xml file is marked as updated and contains the correct values
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0010(WebRowSet wrs1) throws Exception {
FileInputStream fis = new FileInputStream(UPDATED_COFFEE_ROWS_XML);
wrs1.readXml(fis);
assertTrue(wrs1.size() == COFFEES_ROWS);
assertEquals(getPrimaryKeys(wrs1), COFFEES_PRIMARY_KEYS);
assertArrayEquals(COFFEES_PRIMARY_KEYS, getPrimaryKeys(wrs1));
wrs1.beforeFirst();
while (wrs1.next()) {
if (wrs1.getInt(1) == 3) {
@ -337,7 +353,8 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
* Validate the correct row is marked as inserted in a WebRowSet
* that is read from an xml file
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0011(WebRowSet wrs1) throws Exception {
int expectedSize = COFFEES_ROWS + 2;
int addedRowPK = 15;
@ -348,7 +365,10 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
FileInputStream fis = new FileInputStream(INSERTED_COFFEE_ROWS_XML);
wrs1.readXml(fis);
assertTrue(wrs1.size() == expectedSize);
assertEqualsNoOrder(getPrimaryKeys(wrs1), expected);
var actual = getPrimaryKeys(wrs1);
Arrays.sort(actual);
Arrays.sort(expected);
assertArrayEquals(expected, actual);
wrs1.beforeFirst();
while (wrs1.next()) {
if (wrs1.getInt(1) == 15 || wrs1.getInt(1) == 20) {
@ -367,7 +387,8 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
/*
* Read an xml file which contains a row that was inserted and updated
*/
@Test(dataProvider = "rowSetType")
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("rowSetType")
public void WebRowSetTest0012(WebRowSet wrs1) throws Exception {
int expectedSize = COFFEES_ROWS + 1;
int addedRowPK = 100;
@ -376,7 +397,7 @@ public abstract class CommonWebRowSetTests extends CommonCachedRowSetTests {
FileInputStream fis = new FileInputStream(UPDATED_INSERTED_COFFEE_ROWS_XML);
wrs1.readXml(fis);
assertTrue(wrs1.size() == expectedSize);
assertEquals(getPrimaryKeys(wrs1), expected);
assertArrayEquals(expected, getPrimaryKeys(wrs1));
wrs1.beforeFirst();
while (wrs1.next()) {
if (wrs1.getInt(1) == addedRowPK) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it