From 2930ff3f1bbaced8f96332b95a290a4dc0ccea33 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 29 Mar 2019 11:17:37 -0700 Subject: [PATCH 01/12] Tests | Support multi-platform testing with exclusion tags and fix skipping test behavior --- pom.xml | 17 +- .../jdbc/AlwaysEncrypted/AESetup.java | 12 - .../CallableStatementTest.java | 12 +- .../JDBCEncryptionDecryptionTest.java | 3 + .../AlwaysEncrypted/PrecisionScaleTest.java | 3 + .../RegressionAlwaysEncryptedTest.java | 3 + .../microsoft/sqlserver/jdbc/JDBC43Test.java | 10 +- .../sqlserver/jdbc/SQLServerDriverTest.java | 1 - .../jdbc/SSLCertificateValidation.java | 1 - .../microsoft/sqlserver/jdbc/TimeoutTest.java | 6 +- .../microsoft/sqlserver/jdbc/UtilTest.java | 1 - .../jdbc/bulkCopy/BulkCopyAllTypesTest.java | 3 + .../jdbc/bulkCopy/BulkCopyCSVTest.java | 2 + .../bulkCopy/BulkCopyColumnMappingTest.java | 4 + .../jdbc/bulkCopy/BulkCopyConnectionTest.java | 4 + .../BulkCopyISQLServerBulkRecordTest.java | 2 + .../bulkCopy/BulkCopyResultSetCursorTest.java | 2 + .../jdbc/bulkCopy/BulkCopyRowSetTest.java | 5 + .../jdbc/bulkCopy/BulkCopyTimeoutTest.java | 2 + .../ISQLServerBulkRecordIssuesTest.java | 3 + .../microsoft/sqlserver/jdbc/bvt/BvtTest.java | 17 +- .../callablestatement/CallableMixedTest.java | 2 + .../CallableStatementTest.java | 2 + .../jdbc/connection/ConnectionDriverTest.java | 21 +- .../connection/ConnectionWrapper43Test.java | 1 - .../jdbc/connection/DBMetadataTest.java | 2 + .../jdbc/connection/DriverVersionTest.java | 1 - .../connection/NativeMSSQLDataSourceTest.java | 5 +- .../jdbc/connection/PoolingTest.java | 6 +- .../RequestBoundaryMethodsTest.java | 2 + .../jdbc/connection/SSLProtocolTest.java | 1 - .../jdbc/connection/TimeoutTest.java | 4 + .../jdbc/connection/WarningTest.java | 1 - .../DatabaseMetaDataForeignKeyTest.java | 2 + .../DatabaseMetaDataTest.java | 17 +- .../jdbc/datatypes/BigIntegerTest.java | 10 +- .../datatypes/BulkCopyWithSqlVariantTest.java | 2 + .../jdbc/datatypes/DataTypesTest.java | 23 +- .../jdbc/datatypes/DateAndTimeTypeTest.java | 8 +- .../SQLServerSpatialDatatypeTest.java | 25 + .../datatypes/SQLVariantResultSetTest.java | 40 ++ .../sqlserver/jdbc/datatypes/SparseTest.java | 5 +- .../jdbc/datatypes/TVPWithSqlVariantTest.java | 2 + .../jdbc/exception/ErrorStateTest.java | 10 +- .../jdbc/exception/ExceptionTest.java | 2 + .../sqlserver/jdbc/fips/FipsEnvTest.java | 171 ------ .../sqlserver/jdbc/fips/FipsTest.java | 1 - .../sqlserver/jdbc/osgi/DataFactoryTest.java | 2 +- .../ParameterMetaDataTest.java | 5 + .../ParameterMetaDataWhiteSpaceTest.java | 2 + .../BatchExecutionWithBulkCopyTest.java | 4 +- .../BatchExecutionWithNullTest.java | 10 +- .../preparedStatement/RegressionTest.java | 3 + .../jdbc/preparedStatement/SetObjectTest.java | 2 + .../resultset/DataClassificationTest.java | 2 + .../jdbc/resultset/ResultSetTest.java | 4 + .../sqlserver/jdbc/tvp/TVPAllTypesTest.java | 2 + .../sqlserver/jdbc/tvp/TVPIssuesTest.java | 2 + .../sqlserver/jdbc/tvp/TVPNumericTest.java | 3 +- .../jdbc/tvp/TVPResultSetCursorTest.java | 2 + .../sqlserver/jdbc/tvp/TVPSchemaTest.java | 2 + .../sqlserver/jdbc/tvp/TVPTypesTest.java | 2 + .../jdbc/unit/SQLServerErrorTest.java | 2 + .../sqlserver/jdbc/unit/SavepointTest.java | 4 + .../sqlserver/jdbc/unit/UTF8SupportTest.java | 2 + .../jdbc/unit/lobs/LobsStreamingTest.java | 2 + .../sqlserver/jdbc/unit/lobs/LobsTest.java | 2 + .../jdbc/unit/serial/DTOSerialTest.java | 2 + .../statement/BatchExecuteWithErrorsTest.java | 495 +++++++++--------- .../unit/statement/BatchExecutionTest.java | 13 +- .../jdbc/unit/statement/BatchTriggerTest.java | 2 + .../unit/statement/CallableMixedTest.java | 3 +- .../jdbc/unit/statement/LimitEscapeTest.java | 5 +- .../jdbc/unit/statement/MergeTest.java | 3 +- .../statement/NamedParamMultiPartTest.java | 2 + .../jdbc/unit/statement/PQImpsTest.java | 2 + .../unit/statement/PreparedStatementTest.java | 4 + .../jdbc/unit/statement/RegressionTest.java | 21 +- .../statement/StatementCancellationTest.java | 2 + .../jdbc/unit/statement/StatementTest.java | 111 ++-- .../jdbc/unit/statement/WrapperTest.java | 1 - 81 files changed, 537 insertions(+), 667 deletions(-) delete mode 100644 src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java diff --git a/pom.xml b/pom.xml index 69a849779..f1b3b770f 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,17 @@ + + xSQLv14 UTF-8 - 1.2.0 1.6.3 @@ -235,7 +244,8 @@ ${skipTestTag} - ${testGroup} + + ${excludeGroups}, xJDBC42 @@ -305,7 +315,8 @@ ${skipTestTag} - ${testGroup} + + ${excludeGroups} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index e4ead7fd5..9ca0eeeb4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.BufferedReader; import java.io.File; @@ -35,12 +34,10 @@ import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatementColumnEncryptionSetting; -import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Constants; -import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; import microsoft.sql.DateTimeOffset; @@ -74,10 +71,6 @@ public class AESetup extends AbstractTest { */ @BeforeAll public static void setUpConnection() throws TestAbortedException, Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - AETestConnectionString = connectionString + ";sendTimeAsDateTime=false"; readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name"); try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString); @@ -108,10 +101,6 @@ public static void setUpConnection() throws TestAbortedException, Exception { */ @AfterAll public static void dropAll() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { dropTables(stmt); dropCEK(stmt); @@ -131,7 +120,6 @@ private static void readFromFile(String inputFile, String lookupValue) throws IO filePath = TestUtils.getCurrentClassPath(); try { File f = new File(filePath + inputFile); - assumeTrue(f.exists(), TestResource.getResource("R_noKeyStore")); try (BufferedReader buffer = new BufferedReader(new FileReader(f))) { String readLine = ""; String[] linecontents; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index e39c228b7..3282f60a6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.math.BigDecimal; import java.sql.Date; @@ -19,6 +18,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -34,7 +34,6 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; -import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; import microsoft.sql.DateTimeOffset; @@ -45,6 +44,8 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xSQLv12") +@Tag("xAzureSQLDW") public class CallableStatementTest extends AESetup { private static String multiStatementsProcedure = RandomUtil.getIdentifier("multiStatementsProcedure"); @@ -88,10 +89,6 @@ public class CallableStatementTest extends AESetup { */ @BeforeAll public static void initCallableStatementTest() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - dropTables(); numericValues = createNumericValues(nullable); @@ -118,9 +115,6 @@ public static void initCallableStatementTest() throws Exception { @AfterAll public static void dropAll() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } dropTables(); dropProcedures(); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 99a4da078..dcd7b8893 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -12,6 +12,7 @@ import java.sql.Statement; import java.util.LinkedList; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -34,6 +35,8 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xSQLv12") +@Tag("xAzureSQLDW") public class JDBCEncryptionDecryptionTest extends AESetup { private boolean nullable = false; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 804d236a9..d8625e5de 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -16,6 +16,7 @@ import java.util.Date; import java.util.TimeZone; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -36,6 +37,8 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xSQLv12") +@Tag("xAzureSQLDW") public class PrecisionScaleTest extends AESetup { private static java.util.Date date = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java index de5eff03d..97832953b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -13,6 +13,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -24,6 +25,8 @@ @RunWith(JUnitPlatform.class) +@Tag("xSQLv12") +@Tag("xAzureSQLDW") public class RegressionAlwaysEncryptedTest extends AESetup { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java index df3bf4df3..2395d59ad 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java @@ -4,8 +4,6 @@ */ package com.microsoft.sqlserver.jdbc; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - import java.sql.JDBCType; import java.sql.SQLException; import java.sql.ShardingKey; @@ -24,7 +22,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class JDBC43Test extends AbstractTest { ShardingKey superShardingKey = null; ShardingKey shardingKey = null; @@ -39,7 +36,6 @@ public class JDBC43Test extends AbstractTest { */ @Test public void connectionBuilderTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); SQLServerDataSource ds = new SQLServerDataSource(); try { superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); @@ -71,7 +67,6 @@ public void connectionBuilderTest() throws TestAbortedException, SQLException { */ @Test public void xaConnectionBuilderTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); SQLServerXADataSource ds = new SQLServerXADataSource(); try { superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); @@ -102,7 +97,6 @@ public void xaConnectionBuilderTest() throws TestAbortedException, SQLException */ @Test public void connectionPoolDataSourceTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); ConnectionPoolDataSource ds = new SQLServerConnectionPoolDataSource(); try { superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); @@ -131,8 +125,8 @@ public void connectionPoolDataSourceTest() throws TestAbortedException, SQLExcep * @since 1.9 */ @Test + @Tag("xJDBC42") public void setShardingKeyIfValidTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); try (SQLServerConnection connection43 = (SQLServerConnection43) getConnection()) { try { connection43.setShardingKeyIfValid(shardingKey, 10); @@ -155,8 +149,8 @@ public void setShardingKeyIfValidTest() throws TestAbortedException, SQLExceptio * @since 1.9 */ @Test + @Tag("xJDBC42") public void setShardingKeyTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); try (SQLServerConnection connection43 = (SQLServerConnection43) getConnection()) { try { connection43.setShardingKey(shardingKey); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java index 337ab3154..b50f5533a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java @@ -27,7 +27,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class SQLServerDriverTest extends AbstractTest { String randomServer = RandomUtil.getIdentifier("Server"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java b/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java index 5e0548938..5411792a4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java @@ -18,7 +18,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class SSLCertificateValidation { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java index 74cbf0912..3788a6039 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java @@ -10,7 +10,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.PreparedStatement; @@ -32,7 +31,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class TimeoutTest extends AbstractTest { private static final int TIMEOUT_SECONDS = 2; private static final String WAIT_FOR_ONE_MINUTE_SQL = "WAITFOR DELAY '00:01:00'"; @@ -57,16 +55,16 @@ public void after() throws InterruptedException { } @Test + @Tag("xAzureSQLDW") public void testBasicQueryTimeout() { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_issueAzureDW")); assertThrows(SQLTimeoutException.class, () -> { runQuery(WAIT_FOR_ONE_MINUTE_SQL, TIMEOUT_SECONDS); }); } @Test + @Tag("xAzureSQLDW") public void testQueryTimeoutValid() { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_issueAzureDW")); long start = System.currentTimeMillis(); assertThrows(SQLTimeoutException.class, () -> { runQuery(WAIT_FOR_ONE_MINUTE_SQL, TIMEOUT_SECONDS); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java index 2caaf0b45..103e5e8eb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java @@ -20,7 +20,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class UtilTest { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java index 4aa221785..d121e5f05 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -35,8 +36,10 @@ public class BulkCopyAllTypesTest extends AbstractTest { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testTVPResultSet() throws SQLException { if (isSqlAzureDW()) { + //TODO : Fix this test to run with Azure DW testBulkCopyResultSet(false, null, null); testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } else { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java index 6fba3512a..8fc19604e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -49,6 +50,7 @@ */ @RunWith(JUnitPlatform.class) @DisplayName("Test bulkCopy with CSV") +@Tag("xAzureSQLDW") public class BulkCopyCSVTest extends AbstractTest { static String inputFile = "BulkCopyCSVTestInput.csv"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java index 6a0ec4b1a..b90b773ba 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java @@ -14,6 +14,7 @@ import java.text.MessageFormat; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -38,6 +39,7 @@ public class BulkCopyColumnMappingTest extends BulkCopyTestSetUp { @Test @DisplayName("BulkCopy:test no explicit column mapping") + @Tag("xAzureSQLDW") public void testNoExplicitCM() throws SQLException { try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement()) { DBTable destTable = null; @@ -60,6 +62,7 @@ public void testNoExplicitCM() throws SQLException { @Test @DisplayName("BulkCopy:test explicit column mapping") + @Tag("xAzureSQLDW") public void testExplicitCM() throws SQLException { try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement()) { DBTable destTable = null; @@ -146,6 +149,7 @@ public void testUnicodeCM() throws SQLException { @Test @DisplayName("BulkCopy:test repetitive column mapping") + @Tag("xAzureSQLDW") public void testRepetitiveCM() throws SQLException { try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement()) { DBTable sourceTable1 = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java index b4b485d14..875240b35 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; import org.junit.platform.runner.JUnitPlatform; @@ -41,6 +42,7 @@ public class BulkCopyConnectionTest extends BulkCopyTestSetUp { * @return */ @TestFactory + @Tag("xAzureSQLDW") public Stream generateBulkCopyConstructorTest() { List testData = createTestDatatestBulkCopyConstructor(); // had to avoid using lambdas as we need to test against java7 @@ -64,6 +66,7 @@ public void execute() { * @return */ @TestFactory + @Tag("xAzureSQLDW") public Stream generateBulkCopyOptionsTest() { List testData = createTestDatatestBulkCopyOption(); return testData.stream().map(new Function() { @@ -151,6 +154,7 @@ public void execute() throws SQLException { */ @Test @DisplayName("BulkCopy:test null SQLServerBulkCopyOptions") + @Tag("xAzureSQLDW") public void testEmptyBulkCopyOptions() { BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString); bulkWrapper.setUsingConnection((0 == Constants.RANDOM.nextInt(2)) ? true : false, ds); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java index 1741c9c73..465a25d5b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java @@ -14,6 +14,7 @@ import java.util.Set; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -33,6 +34,7 @@ */ @RunWith(JUnitPlatform.class) @DisplayName("Test ISQLServerBulkRecord") +@Tag("xAzureSQLDW") public class BulkCopyISQLServerBulkRecordTest extends AbstractTest { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java index 1b6c18a24..d8ec1c5b2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java @@ -17,6 +17,7 @@ import java.util.TimeZone; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,6 +32,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class BulkCopyResultSetCursorTest extends AbstractTest { static BigDecimal[] expectedBigDecimals = {new BigDecimal("12345.12345"), new BigDecimal("125.123"), diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java index d8ee803dd..4d27f2128 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java @@ -16,7 +16,10 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.RandomData; @@ -26,6 +29,8 @@ import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +@RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class BulkCopyRowSetTest extends AbstractTest { private static String tableName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("BulkCopyFloatTest")); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java index 2c716eeed..7df164a13 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -36,6 +37,7 @@ public class BulkCopyTimeoutTest extends BulkCopyTestSetUp { */ @Test @DisplayName("BulkCopy:test zero timeout") + @Tag("xAzureSQLDW") public void testZeroTimeOut() throws SQLException { testBulkCopyWithTimeout(0); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java index 3a6f89002..c2b690687 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -81,6 +82,7 @@ public void testVarchar() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testSmalldatetime() throws Exception { variation = "testSmalldatetime"; BulkData bData = new BulkData(variation); @@ -109,6 +111,7 @@ public void testSmalldatetime() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testSmalldatetimeOutofRange() throws Exception { variation = "testSmalldatetimeOutofRange"; BulkData bData = new BulkData(variation); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java index 3825ec542..acb8e3df3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java @@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.math.BigDecimal; import java.sql.DatabaseMetaData; @@ -17,7 +16,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -34,8 +32,6 @@ @RunWith(JUnitPlatform.class) -@DisplayName("BVT Test") -@Tag("AzureDWTest") public class BvtTest extends AbstractTest { private static String driverNamePattern = "Microsoft JDBC Driver \\d.\\d for SQL Server"; static DBTable table1; @@ -47,7 +43,6 @@ public class BvtTest extends AbstractTest { * @throws SQLException */ @Test - @DisplayName("test connection") public void testConnection() throws SQLException { try (DBConnection conn = new DBConnection(connectionString)) {} } @@ -147,8 +142,8 @@ public void testStmtForwardOnlyReadOnly() throws SQLException, ClassNotFoundExce * @throws ClassNotFoundException */ @Test + @Tag("xAzureSQLDW") public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFoundException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_INSENSITIVE_CONCUR_READ_ONLY); DBResultSet rs = stmt.selectAll(table1)) { @@ -168,8 +163,8 @@ public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFou * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testStmtScrollSensitiveReadOnly() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY); DBResultSet rs = stmt.selectAll(table1)) { @@ -191,8 +186,8 @@ public void testStmtScrollSensitiveReadOnly() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testStmtForwardOnlyUpdateable() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_UPDATABLE); DBResultSet rs = stmt.selectAll(table1)) { @@ -219,8 +214,8 @@ public void testStmtForwardOnlyUpdateable() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testStmtScrollSensitiveUpdatable() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE); DBResultSet rs = stmt.selectAll(table1)) { @@ -243,8 +238,8 @@ public void testStmtScrollSensitiveUpdatable() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testStmtSSScrollDynamicOptimisticCC() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_DYNAMIC_CONCUR_OPTIMISTIC); DBResultSet rs = stmt.selectAll(table1)) { @@ -416,8 +411,8 @@ public void testResultSetAndCloseStmt() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testResultSetSelectMethod() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString + ";selectMethod=cursor;"); DBStatement stmt = conn.createStatement(); DBResultSet rs = stmt.selectAll(table1)) { rs.verify(table1); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java index d93fe8cc6..8a5403c9a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -20,6 +21,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class CallableMixedTest extends AbstractTest { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 33a87dd74..d4536d89f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -32,6 +33,7 @@ * Test CallableStatement */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class CallableStatementTest extends AbstractTest { private static String tableNameGUID = RandomUtil.getIdentifier("uniqueidentifier_Table"); private static String outputProcedureNameGUID = RandomUtil.getIdentifier("uniqueidentifier_SP"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java index 5d749ba78..1b3e6edd8 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java @@ -7,16 +7,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.sql.Connection; -import java.sql.DriverPropertyInfo; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.text.MessageFormat; -import java.util.Properties; import java.util.UUID; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; @@ -37,7 +34,6 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; -import com.microsoft.sqlserver.jdbc.SQLServerDriver; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; @@ -46,7 +42,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class ConnectionDriverTest extends AbstractTest { // If no retry is done, the function should at least exit in 5 seconds static int threshHoldForNoRetryInMilliseconds = 5000; @@ -118,9 +113,9 @@ public void connectionErrorOccurred(ConnectionEvent event) { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testConnectionEvents() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource(); mds.setURL(connectionString); PooledConnection pooledConnection = mds.getPooledConnection(); @@ -152,9 +147,9 @@ public void testConnectionEvents() throws SQLException { } @Test + @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testConnectionPoolGetTwice() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource(); mds.setURL(connectionString); PooledConnection pooledConnection = mds.getPooledConnection(); @@ -183,9 +178,9 @@ public void testConnectionPoolGetTwice() throws SQLException { } @Test + @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testConnectionClosed() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - SQLServerDataSource mds = new SQLServerDataSource(); mds.setURL(connectionString); try (Connection con = mds.getConnection(); @@ -260,9 +255,9 @@ public void testNegativeTimeout() throws Exception { } @Test + @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testDeadConnection() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - String tableName = RandomUtil.getIdentifier("ConnectionTestTable"); try (Connection conn = PrepUtil.getConnection(connectionString + ";responseBuffering=adaptive"); Statement stmt = conn.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java index 9f2e0fd89..3434e1999 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java @@ -27,7 +27,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class ConnectionWrapper43Test extends AbstractTest { static Connection connection = null; double javaVersion = Double.parseDouble(System.getProperty("java.specification.version")); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java index c9bffb8a4..5bd8df1c2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java @@ -10,6 +10,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -22,6 +23,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class DBMetadataTest extends AbstractTest { @Test public void testDatabaseMetaData() throws SQLException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java index adc87936d..46d301dd9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java @@ -28,7 +28,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class DriverVersionTest extends AbstractTest { Random rand = new Random(); int major = rand.nextInt(256); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java index 646dbd602..218eb194d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java @@ -35,7 +35,6 @@ public class NativeMSSQLDataSourceTest extends AbstractTest { @Test - @Tag("AzureDWTest") public void testNativeMSSQLDataSource() throws SQLException { SQLServerXADataSource ds = new SQLServerXADataSource(); ds.setLastUpdateCount(true); @@ -43,7 +42,6 @@ public void testNativeMSSQLDataSource() throws SQLException { } @Test - @Tag("AzureDWTest") public void testSerialization() throws IOException { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutput objectOutput = new ObjectOutputStream(outputStream)) { @@ -56,7 +54,6 @@ public void testSerialization() throws IOException { } @Test - @Tag("AzureDWTest") public void testDSNormal() throws ClassNotFoundException, IOException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); ds.setURL(connectionString); @@ -66,6 +63,7 @@ public void testDSNormal() throws ClassNotFoundException, IOException, SQLExcept } @Test + @Tag("xAzureSQLDW") public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); System.setProperty("java.net.preferIPv6Addresses", Boolean.TRUE.toString()); @@ -79,7 +77,6 @@ public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLEx } @Test - @Tag("AzureDWTest") public void testInterfaceWrapping() throws ClassNotFoundException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); assertEquals(true, ds.isWrapperFor(Class.forName(Constants.MSSQL_JDBC_PACKAGE + ".ISQLServerDataSource"))); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java index 03eeb5c83..762fa4afa 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java @@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.PreparedStatement; @@ -42,14 +41,15 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class PoolingTest extends AbstractTest { static String tempTableName = RandomUtil.getIdentifier("#poolingtest"); static String tableName = RandomUtil.getIdentifier("PoolingTestTable"); @Test + @Tag("xAzureSQLDB") + @Tag("xAzureSQLDW") + @Tag("xAzureSQLMI") public void testPooling() throws SQLException { - assumeTrue(!isSqlAzure(), TestResource.getResource("R_skipAzure")); SQLServerXADataSource XADataSource1 = new SQLServerXADataSource(); XADataSource1.setURL(connectionString); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java index 46a65d587..b77221569 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.concurrent.CountDownLatch; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -36,6 +37,7 @@ * A class for testing Request Boundary Methods. */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class RequestBoundaryMethodsTest extends AbstractTest { static String tableName = RandomUtil.getIdentifier("RequestBoundaryTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java index 6962a171f..caa5d9e86 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java @@ -28,7 +28,6 @@ * Tests new connection property sslProtocol */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class SSLProtocolTest extends AbstractTest { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java index 7e8ecc45f..f89fc6ff5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java @@ -98,6 +98,7 @@ public void testFOInstanceResolution2() throws SQLException { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testQueryTimeout() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); @@ -134,6 +135,7 @@ public void testQueryTimeout() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testCancelQueryTimeout() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); @@ -170,6 +172,7 @@ public void testCancelQueryTimeout() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testCancelQueryTimeoutOnStatement() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); @@ -208,6 +211,7 @@ public void testCancelQueryTimeoutOnStatement() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testSocketTimeout() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java index ae296f71a..b87d67670 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java @@ -25,7 +25,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class WarningTest extends AbstractTest { @Test public void testWarnings() throws SQLException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java index 5012813fa..bf5492eb1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -32,6 +33,7 @@ * Test class for testing DatabaseMetaData with foreign keys. */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class DatabaseMetaDataForeignKeyTest extends AbstractTest { private static String table1 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_table_1"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java index f7253fe56..556c4b936 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java @@ -12,7 +12,6 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.BufferedInputStream; import java.io.File; @@ -54,7 +53,6 @@ public class DatabaseMetaDataTest extends AbstractTest { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testDatabaseMetaDataWrapper() throws SQLException { try (Connection con = getConnection()) { DatabaseMetaData databaseMetaData = con.getMetaData(); @@ -77,15 +75,12 @@ public void testDatabaseMetaDataWrapper() throws SQLException { * IOExcption */ @Test - @Tag("AzureDWTest") public void testDriverVersion() throws SQLException, IOException { String manifestFile = TestUtils.getCurrentClassPath() + "META-INF/MANIFEST.MF"; manifestFile = manifestFile.replace("test-classes", "classes"); File f = new File(manifestFile); - assumeTrue(f.exists(), TestResource.getResource("R_manifestNotFound")); - try (InputStream in = new BufferedInputStream(new FileInputStream(f))) { Manifest manifest = new Manifest(in); Attributes attributes = manifest.getMainAttributes(); @@ -118,7 +113,6 @@ public void testDriverVersion() throws SQLException, IOException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetURL() throws SQLException { try (Connection conn = getConnection()) { DatabaseMetaData databaseMetaData = conn.getMetaData(); @@ -136,6 +130,7 @@ public void testGetURL() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testDBUserLogin() throws SQLException { try (Connection conn = getConnection()) { DatabaseMetaData databaseMetaData = conn.getMetaData(); @@ -172,7 +167,6 @@ public void testDBUserLogin() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testDBSchema() throws SQLException { try (Connection conn = getConnection(); ResultSet rs = conn.getMetaData().getSchemas()) { @@ -193,6 +187,7 @@ public void testDBSchema() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testDBSchemasForDashedCatalogName() throws SQLException { UUID id = UUID.randomUUID(); String testCatalog = "dash-catalog" + id; @@ -245,6 +240,7 @@ public void testDBSchemasForDashedCatalogName() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testDBSchemasForDashedCatalogNameWithPattern() throws SQLException { UUID id = UUID.randomUUID(); String testCatalog = "dash-catalog" + id; @@ -291,7 +287,6 @@ public void testDBSchemasForDashedCatalogNameWithPattern() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") /* * try (ResultSet rsCatalog = connection.getMetaData().getCatalogs(); ResultSet rs = connection.getMetaData() * .getTables(rsCatalog.getString("TABLE_CAT"), null, "%", new String[] {"TABLE"})) { @@ -331,7 +326,6 @@ public void testDBTables() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetDBColumn() throws SQLException { try (Connection conn = getConnection()) { @@ -380,6 +374,7 @@ public void testGetDBColumn() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testGetColumnPrivileges() throws SQLException { try (Connection conn = getConnection()) { @@ -421,7 +416,6 @@ public void testGetColumnPrivileges() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetFunctionsWithWrongParams() throws SQLException { try (Connection conn = getConnection()) { conn.getMetaData().getFunctions("", null, "xp_%"); @@ -435,7 +429,6 @@ public void testGetFunctionsWithWrongParams() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetFunctions() throws SQLException { try (Connection conn = getConnection(); ResultSet rs = conn.getMetaData().getFunctions(null, null, "xp_%")) { @@ -461,7 +454,6 @@ public void testGetFunctions() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetFunctionColumns() throws SQLException { try (Connection conn = getConnection()) { @@ -499,6 +491,7 @@ public void testGetFunctionColumns() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testPreparedStatementMetadataCaching() throws SQLException { try (Connection connection = getConnection()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java index 413e29ded..5a5b32dd4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -23,6 +24,7 @@ * This test is for testing the setObject methods for the data type mappings in JDBC for java.math.BigInteger */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class BigIntegerTest extends AbstractTest { enum TestType { @@ -100,7 +102,7 @@ public void testBigInteger() throws Exception { } } - static void testSetObject(String tableName, BigInteger obj, int id, PreparedStatement pstmt, + private void testSetObject(String tableName, BigInteger obj, int id, PreparedStatement pstmt, TestType testType) throws SQLException { if (TestType.SETOBJECT_WITHTYPE == testType) { callSetObjectWithType(obj, pstmt); @@ -172,7 +174,7 @@ static void testSetObject(String tableName, BigInteger obj, int id, PreparedStat } } - static void callSetObjectWithType(BigInteger obj, PreparedStatement pstmt) throws SQLException { + private void callSetObjectWithType(BigInteger obj, PreparedStatement pstmt) throws SQLException { pstmt.setObject(1, obj, java.sql.Types.VARCHAR); pstmt.setObject(2, obj, java.sql.Types.BIGINT); pstmt.setObject(3, obj, java.sql.Types.FLOAT); @@ -199,7 +201,7 @@ static void callSetObjectWithType(BigInteger obj, PreparedStatement pstmt) throw pstmt.setObject(9, obj, java.sql.Types.LONGVARCHAR); } - static void callSetObjectWithoutType(BigInteger obj, PreparedStatement pstmt) throws SQLException { + private void callSetObjectWithoutType(BigInteger obj, PreparedStatement pstmt) throws SQLException { /* * Cannot send a long value to a column of type int/smallint (even if the long value is small enough to fit in * those types) @@ -231,7 +233,7 @@ static void callSetObjectWithoutType(BigInteger obj, PreparedStatement pstmt) th pstmt.setObject(9, obj); } - static void callSetNull(BigInteger obj, PreparedStatement pstmt) throws SQLException { + private void callSetNull(BigInteger obj, PreparedStatement pstmt) throws SQLException { pstmt.setNull(1, java.sql.Types.VARCHAR); pstmt.setNull(2, java.sql.Types.BIGINT); pstmt.setNull(3, java.sql.Types.FLOAT); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java index 9a2eda3a1..92412529c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java @@ -14,6 +14,7 @@ import java.sql.Statement; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,6 +32,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class BulkCopyWithSqlVariantTest extends AbstractTest { static String tableName = RandomUtil.getIdentifier("sqlVariantTestSrcTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java index 323405599..97d40d666 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.math.BigDecimal; import java.sql.CallableStatement; @@ -18,15 +17,14 @@ import java.sql.Time; import java.sql.Timestamp; import java.text.DateFormatSymbols; -import java.text.MessageFormat; import java.time.Instant; import java.util.Calendar; import java.util.EnumSet; -import java.util.GregorianCalendar; import java.util.Locale; import java.util.SimpleTimeZone; import java.util.TimeZone; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -204,8 +202,6 @@ void verifyRSGetters(Connection conn) throws Exception { } void verifyRSUpdaters(Connection conn) throws Exception { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - try (Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { TestUtils.dropTableIfExists(escapedTableName, stmt); @@ -224,8 +220,6 @@ void verifyRSUpdaters(Connection conn) throws Exception { } void verifySetters(Connection conn) throws Exception { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - try (Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { TestUtils.dropTableIfExists(escapedTableName, stmt); stmt.executeUpdate("CREATE TABLE " + escapedTableName + " (col1 " + sqlTypeExpression @@ -1071,6 +1065,7 @@ public void testResultSetGetters() throws Exception { } @Test + @Tag("xAzureSQLDW") public void testResultSetUpdaters() throws Exception { try (Connection conn = getConnection()) { for (TestValue value : TestValue.values()) @@ -1079,6 +1074,7 @@ public void testResultSetUpdaters() throws Exception { } @Test + @Tag("xAzureSQLDW") public void testSetters() throws Exception { try (Connection conn = PrepUtil.getConnection(connectionString + ";sendTimeAsDateTime=true")) { for (TestValue value : TestValue.values()) @@ -1153,12 +1149,10 @@ public void testSendTimestampAsTimeAsDatetime() throws Exception { * double-rounding of fractional seconds */ @Test + @Tag("xAzureSQLDW") public void testDoubleRounding() throws Exception { try (Connection conn = getConnection()) { - // create a table with a datetimeoffset column and insert a value in it - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - String sql; try (Statement stmt = conn.createStatement()) { // SQL Azure requires each table to have a clustered index, so change col1 to the primary key @@ -1230,9 +1224,6 @@ public void testWithJapaneseImperialCalendar() throws Exception { */ Locale japaneseImperialLocale = new Locale("ja", "JP", "JP"); Calendar japaneseImperialCalendar = Calendar.getInstance(japaneseImperialLocale); - MessageFormat cal = new MessageFormat(TestResource.getResource("R_noJRESupport")); - Object[] msgsArgs = {japaneseImperialLocale.toString()}; - assumeTrue(GregorianCalendar.class.isInstance(japaneseImperialCalendar), cal.format(msgsArgs)); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(japaneseImperialLocale); @@ -1562,12 +1553,11 @@ public void testTimestampToDateTime() throws Exception { } @Test + @Tag("xAzureSQLDW") public void testUpdateMisc() throws Exception { try (SQLServerConnection conn = (SQLServerConnection) PrepUtil .getConnection(connectionString + ";sendTimeAsDatetime=true")) { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - try (Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { TestUtils.dropTableIfExists(escapedTableName, stmt); @@ -1678,9 +1668,8 @@ public void testUpdateMisc() throws Exception { * last millisecond digit. */ @Test + @Tag("xAzureSQLDW") public void testDateTimeInsertUpdate() throws Exception { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); - try (Connection conn = getConnection(); Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) conn diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java index f341789e1..b8f86b79a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.datatypes; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.Date; @@ -18,6 +17,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -30,11 +30,11 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class DateAndTimeTypeTest extends AbstractTest { private static final Date DATE_TO_TEST = new java.sql.Date(61494793200000L); @@ -194,10 +194,6 @@ private void createTVPs(String tvpName, String tvpType) throws SQLException { @BeforeEach public void testSetup() throws TestAbortedException, Exception { - try (DBConnection dbc = new DBConnection(connectionString)) { - assumeTrue(9 <= dbc.getServerVersion(), "Aborting test case as SQL Server version does not support TIME"); - } - // To get TIME & setTime working on Servers >= 2008, we must add 'sendTimeAsDatetime=false' // by default to the connection. See issue https://github.com/Microsoft/mssql-jdbc/issues/559 try (Connection connection = PrepUtil.getConnection(connectionString + ";sendTimeAsDatetime=false"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java index bf293d5db..94b4b169f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -187,6 +188,7 @@ public void testFullGlobeWkb() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testPointWkt() throws SQLException { beforeEachSetup(); String geoWKT = "POINT(3 40 5 6)"; @@ -197,6 +199,7 @@ public void testPointWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testLineStringWkt() throws SQLException { beforeEachSetup(); String geoWKT = "LINESTRING(1 0, 0 1, -1 0)"; @@ -207,6 +210,7 @@ public void testLineStringWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testPolygonWkt() throws SQLException { beforeEachSetup(); String geoWKT = "POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))"; @@ -217,6 +221,7 @@ public void testPolygonWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testMultiPointWkt() throws SQLException { beforeEachSetup(); String geoWKT = "MULTIPOINT((2 3), (7 8 9.5))"; @@ -227,6 +232,7 @@ public void testMultiPointWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testMultiLineStringWkt() throws SQLException { beforeEachSetup(); String geoWKT = "MULTILINESTRING((0 2, 1 1), (1 0, 1 1))"; @@ -237,6 +243,7 @@ public void testMultiLineStringWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testMultiPolygonWkt() throws SQLException { beforeEachSetup(); String geoWKT = "MULTIPOLYGON(((1 1, 1 2, 2 1, 1 1), (0 0, 0 3, 3 3, 3 0, 0 0 7)), ((9 9, 9 10, 10 9, 9 9)))"; @@ -247,6 +254,7 @@ public void testMultiPolygonWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testGeometryCollectionWkt() throws SQLException { String geoWKT; if (isDenaliOrLater) { @@ -266,6 +274,7 @@ public void testGeometryCollectionWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testCircularStringWkt() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -278,6 +287,7 @@ public void testCircularStringWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testCompoundCurveWkt() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -290,6 +300,7 @@ public void testCompoundCurveWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testCurvePolygonWkt() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -302,6 +313,7 @@ public void testCurvePolygonWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testFullGlobeWkt() throws SQLException { try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { if (isDenaliOrLater) { @@ -332,6 +344,7 @@ public void testFullGlobeWkt() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testIrregularCases() throws SQLException { beforeEachSetup(); @@ -445,6 +458,7 @@ public void testIllegalCases() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testAllTypes() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -596,6 +610,7 @@ public void testAllTypes() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testMixedAllTypes() throws SQLException { if (isDenaliOrLater) { beforeEachSetupSpatialDatatype(); @@ -752,6 +767,7 @@ public void testMixedAllTypes() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testDecimalRounding() throws SQLException { beforeEachSetup(); @@ -762,6 +778,7 @@ public void testDecimalRounding() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testParse() throws SQLException { beforeEachSetup(); @@ -802,6 +819,7 @@ public void testParse() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testPoint() throws SQLException { beforeEachSetup(); @@ -841,6 +859,7 @@ public void testPoint() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testSTAsText() throws SQLException { beforeEachSetup(); @@ -879,6 +898,7 @@ public void testSTAsText() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testSTAsBinary() throws SQLException { beforeEachSetup(); @@ -901,6 +921,8 @@ public void testSTAsBinary() throws SQLException { assertEquals(geogWKB, geogWKB2); } + @Test + @Tag("xAzureSQLDW") public void testCheckGeomMetaData() throws SQLException { beforeEachSetup(); @@ -925,6 +947,7 @@ public void testCheckGeomMetaData() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testCheckGeogMetaData() throws SQLException { beforeEachSetup(); @@ -965,6 +988,7 @@ public void testGetXGetY() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testNull() throws SQLException { if (isDenaliOrLater) { beforeEachSetupSpatialDatatype(); @@ -1034,6 +1058,7 @@ public void testNull() throws SQLException { } @Test + @Tag("xAzureSQLDW") public void testWrongtype() throws SQLException { beforeEachSetup(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java index d1615fb7e..a8b3ccf2a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -52,6 +53,7 @@ public class SQLVariantResultSetTest extends AbstractTest { * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readInt() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { @@ -72,6 +74,7 @@ public void readInt() throws SQLException, SecurityException, IOException { * */ @Test + @Tag("xAzureSQLDW") public void readMoney() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { Double value = 123.12; @@ -90,6 +93,7 @@ public void readMoney() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readSmallMoney() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { Double value = 123.12; @@ -108,6 +112,7 @@ public void readSmallMoney() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readGUID() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "1AE740A2-2272-4B0F-8086-3DDAC595BC11"; @@ -126,6 +131,7 @@ public void readGUID() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readDate() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08'"; @@ -144,6 +150,7 @@ public void readDate() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readTime() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "'12:26:27.123345'"; @@ -162,6 +169,7 @@ public void readTime() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readDateTime() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08 12:26:24'"; @@ -180,6 +188,7 @@ public void readDateTime() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readSmallDateTime() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08 12:26:24'"; @@ -198,6 +207,7 @@ public void readSmallDateTime() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readVarChar8000() throws SQLException { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 8000; i++) { @@ -219,6 +229,7 @@ public void readVarChar8000() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readFloat() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { float value = 5; @@ -237,6 +248,7 @@ public void readFloat() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readBigInt() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { long value = 5; @@ -255,6 +267,7 @@ public void readBigInt() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readSmallInt() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { short value = 5; @@ -273,6 +286,7 @@ public void readSmallInt() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readTinyInt() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { short value = 5; @@ -291,6 +305,7 @@ public void readTinyInt() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readBit() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { int value = 50000; @@ -309,6 +324,7 @@ public void readBit() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readReal() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { float value = 5; @@ -327,6 +343,7 @@ public void readReal() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readNChar() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "a"; @@ -347,6 +364,7 @@ public void readNChar() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readNVarChar() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "nvarchar"; @@ -367,6 +385,7 @@ public void readNVarChar() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readBinary20() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; @@ -387,6 +406,7 @@ public void readBinary20() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readVarBinary20() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; @@ -407,6 +427,7 @@ public void readVarBinary20() throws SQLException, SecurityException, IOExceptio * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readBinary512() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; @@ -427,6 +448,7 @@ public void readBinary512() throws SQLException, SecurityException, IOException * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readBinary8000() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; @@ -447,6 +469,7 @@ public void readBinary8000() throws SQLException, SecurityException, IOException * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readvarBinary8000() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; @@ -467,6 +490,7 @@ public void readvarBinary8000() throws SQLException, SecurityException, IOExcept * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void readSQLVariantProperty() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; @@ -487,6 +511,7 @@ public void readSQLVariantProperty() throws SQLException, SecurityException, IOE * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void insertVarChar8001() throws SQLException { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 8001; i++) { @@ -514,6 +539,7 @@ public void insertVarChar8001() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readNvarChar4000() throws SQLException { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 4000; i++) { @@ -538,6 +564,7 @@ public void readNvarChar4000() throws SQLException { * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void UpdateInt() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { @@ -567,6 +594,7 @@ public void UpdateInt() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void UpdateNChar() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { @@ -598,6 +626,7 @@ public void UpdateNChar() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag("xAzureSQLDW") public void updateBinary20() throws SQLException, SecurityException, IOException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { @@ -626,6 +655,7 @@ public void updateBinary20() throws SQLException, SecurityException, IOException * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void insertTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -662,6 +692,7 @@ public void insertTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void insertTestNull() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -688,6 +719,7 @@ public void insertTestNull() throws SQLException { * @throws ParseException */ @Test + @Tag("xAzureSQLDW") public void insertSetObject() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -714,6 +746,7 @@ public void insertSetObject() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void callableStatementOutputIntTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { int value = 5; @@ -744,6 +777,7 @@ public void callableStatementOutputIntTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void callableStatementOutputDateTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "2015-05-08"; @@ -775,6 +809,7 @@ public void callableStatementOutputDateTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void callableStatementOutputTimeTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String value = "12:26:27.123345"; @@ -806,6 +841,7 @@ public void callableStatementOutputTimeTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void callableStatementOutputBinaryTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { byte[] binary20 = RandomData.generateBinaryTypes("20", false, false); @@ -842,6 +878,7 @@ public void callableStatementOutputBinaryTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void callableStatementInputOutputIntTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { int col1Value = 5; @@ -873,6 +910,7 @@ public void callableStatementInputOutputIntTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void callableStatementInputOutputReturnIntTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { int col1Value = 5; @@ -907,6 +945,7 @@ public void callableStatementInputOutputReturnIntTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void callableStatementInputOutputReturnStringTest() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String col1Value = "aa"; @@ -943,6 +982,7 @@ public void callableStatementInputOutputReturnStringTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void readSeveralRows() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { short value1 = 5; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java index 69465311b..72feecbaf 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java @@ -1,18 +1,17 @@ package com.microsoft.sqlserver.jdbc.datatypes; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; @@ -24,9 +23,9 @@ public class SparseTest extends AbstractTest { final static String escapedTableName = AbstractSQLGenerator.escapeIdentifier(tableName); @Test + @Tag("xAzureSQLDW") public void testSparse() throws Exception { try (Connection conn = getConnection()) { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); try (Statement stmt = conn.createStatement()) { // Create the test table diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java index 3f9676dc1..433938afe 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -36,6 +37,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class TVPWithSqlVariantTest extends AbstractTest { private static SQLServerConnection conn = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java index e3eec336f..eaa534d59 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java @@ -42,7 +42,10 @@ public void testSQLStateLength2() throws Exception { stmt.execute("RAISERROR (13002, -1, " + state + ", N'Testing error');"); } catch (SQLException e) { assert (e.getSQLState().length() == 5); - assert (e.getSQLState().equalsIgnoreCase("S00" + state)); + if (isSqlAzureDW()) { + assert (e.getSQLState().equalsIgnoreCase("S0001")); + } else + assert (e.getSQLState().equalsIgnoreCase("S00" + state)); } } @@ -53,7 +56,10 @@ public void testSQLStateLength3() throws Exception { stmt.execute("RAISERROR (13003, -1, " + state + ", N'Testing error');"); } catch (SQLException e) { assert (e.getSQLState().length() == 5); - assert (e.getSQLState().equalsIgnoreCase("S0" + state)); + if (isSqlAzureDW()) { + assert (e.getSQLState().equalsIgnoreCase("S0001")); + } else + assert (e.getSQLState().equalsIgnoreCase("S0" + state)); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java index e9079509f..35d6cbc34 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java @@ -14,6 +14,7 @@ import java.text.MessageFormat; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -67,6 +68,7 @@ public void testBulkCSVFileRecordExceptionCause() throws Exception { * */ @Test + @Tag("xAzureSQLDW") public void testSocketTimeoutExceptionCause() throws Exception { try (SQLServerConnection conn = (SQLServerConnection) getConnection(); Statement stmt = conn.createStatement()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java deleted file mode 100644 index 50b2d212d..000000000 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made - * available under the terms of the MIT License. See the LICENSE file in the project root for more information. - */ -package com.microsoft.sqlserver.jdbc.fips; - -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -import java.security.Provider; -import java.security.Security; -import java.util.Enumeration; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -import com.microsoft.sqlserver.jdbc.TestResource; -import com.microsoft.sqlserver.jdbc.TestUtils; -import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.Constants; - - -/** - * Class which will useful for checking if FIPS env. set or not. - * - * @since 6.1.2 - */ -@RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") -public class FipsEnvTest extends AbstractTest { - - protected static Logger logger = Logger.getLogger("FipsEnvTest"); - - protected static Properties p = null; - - protected static final String ORACLE_JVM = "ORACLE_JVM"; - - protected static final String IBM_JVM = "IBM_JVM"; - - protected static final String SAP_JVM = "SAP_JVM"; - - protected static String currentJVM = ORACLE_JVM; - - /** - * Before class init method. - */ - @BeforeAll - public static void populateProperties() { - p = System.getProperties(); - - if (p.getProperty("java.vendor").startsWith("IBM")) { - currentJVM = IBM_JVM; - } - - if (p.getProperty("java.vendor").startsWith("SAP")) { - currentJVM = SAP_JVM; - } - } - - /** - * Test FIPS in Oracle Env. - * - * @since 6.1.2 - */ - @Test - public void testFIPSOnOracle() throws Exception { - assumeTrue(ORACLE_JVM.equals(currentJVM), TestResource.getResource("R_wrongEnv") + ORACLE_JVM); - - assumeTrue("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), - TestResource.getResource("R_fipsPropertyNotSet")); - - assertTrue(isFIPS("SunJSSE"), "FIPS " + TestResource.getResource("R_shouldBeEnabled")); - - // As JDK 1.7 is not supporting lambda for time being commenting. - /* - * assumingThat("NSSFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> - * assertTrue(isFIPS("SunJSSE"), TestResource.getResource("R_shouldBeEnabled")), () -> - * assertTrue(isFIPS("SunPKCS11-NSS"), "Testing"))); - * assumingThat("BCFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> - * assertTrue(isFIPS("SunJSSE"), TestResource.getResource("R_shouldBeEnabled")), () -> - * assertTrue(isFIPS("BCFIPS"), "Testing"))); - * assumingThat("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), ()-> assertTrue(isFIPS("SunJSSE"), - * TestResource.getResource("R_shouldBeEnabled"))); - */ - } - - /** - * Test FIPS in IBM Env. If JVM is not IBM test will not fail. It will simply skipped. - * - * @since 6.1.2 - */ - @Test - public void testFIPSOnIBM() throws Exception { - assumeTrue(IBM_JVM.equals(currentJVM), TestResource.getResource("R_wrongEnv") + IBM_JVM); - - assumeTrue("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), - TestResource.getResource("R_fipsPropertyNotSet")); - - assertTrue(isFIPS("IBMJCEFIP"), "FIPS " + TestResource.getResource("R_shouldBeEnabled")); - - // As JDK 1.7 is not supporting lambda for time being commenting. - /* - * assumingThat("NSSFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> - * assertTrue(isFIPS("IBMJCEFIP"), "FIPS should be Enabled."), () -> assertTrue(isFIPS("SunPKCS11-NSS"), - * "Testing"))); assumingThat("BCFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> - * assertAll("All FIPS", () -> assertTrue(isFIPS("IBMJCEFIPS"), "FIPS should be Enabled."), () -> - * assertTrue(isFIPS("BCFIPS"), "Testing"))); - * assumingThat("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), ()-> - * assertTrue(isFIPS("IBMJCEFIPS"), "FIPS Should be enabled")); - */ - } - - /** - * In case of FIPs enabled this test method will call {@link #isFIPS(String)} with appropriate FIPS provider. May be - * useful only for JDK 1.8 - */ - @Test - @Disabled - public void testFIPSEnv() { - assumeTrue(Constants.FIPS.equals(TestUtils.getConfiguredProperty(Constants.FIPS_ENV)), - TestResource.getResource("R_fipsPropertyNotSet")); - - // As JDK 1.7 is not supporting lambda for time being commenting. - /* - * assumingThat(System.getProperty("java.vendor").startsWith("IBM"), () -> assertTrue(isFIPS("IBMJCEFIP"), - * "FIPS should be Enabled.")); assumingThat(System.getProperty("java.vendor").startsWith("Oracle"), () -> - * assertTrue(isFIPS("SunJSSE"), "FIPS should be Enabled.")); - */ - } - - /** - * Just simple method to check if JVM is configured for FIPS or not. CAUTION: We observed that - * SSLContext.getDefault().getProvider fails because it could not find any algorithm. - * - * @param provider - * FIPS Provider - * @return boolean - * @throws Exception - */ - public static boolean isFIPS(String provider) throws Exception { - Provider jsse = Security.getProvider(provider); - if (logger.isLoggable(Level.FINE)) { - logger.fine(jsse.toString()); - logger.fine(jsse.getInfo()); - } - return jsse != null && jsse.getInfo().contains("FIPS"); - } - - @Test - @Disabled - public void printJVMInfo() { - Enumeration keys = p.keys(); - - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - String value = (String) p.get(key); - - if (logger.isLoggable(Level.FINE)) { - logger.fine(key + ": " + value); - } - } - } - -} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java index 2f4d49d3e..e27137b6e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java @@ -28,7 +28,6 @@ * Test class for testing FIPS property settings. */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class FipsTest extends AbstractTest { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java index c283b9d53..7e2c9ea34 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java @@ -56,7 +56,7 @@ public ServiceReference getServiceReference(String clazz) { } @Override - public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) { + public ServiceRegistration registerService(String[] classes, Object service, @SuppressWarnings("rawtypes") Dictionary properties) { MockServiceRegistration reg = new MockServiceRegistration(properties); sr = reg.getReference(); if (service instanceof DataSourceFactory) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java index 0db893ac4..8df0c2d65 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java @@ -13,6 +13,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -33,6 +34,7 @@ public class ParameterMetaDataTest extends AbstractTest { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testParameterMetaDataWrapper() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -75,6 +77,7 @@ public void testSQLServerExceptionNotWrapped() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testNameWithBraces() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -99,6 +102,7 @@ public void testNameWithBraces() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testParameterMetaData() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -135,6 +139,7 @@ public void testParameterMetaData() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testParameterMetaDataProc() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String query = "exec sp_help (" + AbstractSQLGenerator.escapeIdentifier(tableName) + ")"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java index bfe9b1f62..0184653b6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,6 +27,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class ParameterMetaDataWhiteSpaceTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("ParameterMetaDataWhiteSpaceTest"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java index c9752f961..260f21da4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -48,7 +47,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class BatchExecutionWithBulkCopyTest extends AbstractTest { static String tableName = RandomUtil.getIdentifier("BulkCopyParseTest"); @@ -650,8 +648,8 @@ public void testNonParameterizedQuery() throws Exception { } @Test + @Tag("xAzureSQLDW") public void testNonSupportedColumns() throws Exception { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_spatialDWNotSupported")); String valid = "insert into " + AbstractSQLGenerator.escapeIdentifier(unsupportedTableName) + " values (?, ?, ?, ?)"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java index 005311584..ae613175f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.preparedStatement; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.PreparedStatement; @@ -27,12 +26,11 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") +@Tag("xAzureSQLDW") public class BatchExecutionWithNullTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("batchNull"); @@ -104,11 +102,8 @@ public void testAddbatch2AEOnConnection() throws SQLException { } @BeforeEach + @Tag("xSQLv12") public void testSetup() throws TestAbortedException, Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - try (Connection connection = getConnection(); SQLServerStatement stmt = (SQLServerStatement) connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -116,7 +111,6 @@ public void testSetup() throws TestAbortedException, Exception { + " (id integer not null, name varchar(255), constraint " + AbstractSQLGenerator.escapeIdentifier(primaryKeyConstraintName) + " primary key (id))"; stmt.execute(sql1); - stmt.close(); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java index 8a0dee24c..aa0df5114 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java @@ -176,11 +176,13 @@ public void grantTest() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void batchWithLargeStringTest() throws Exception { batchWithLargeStringTestInternal("BatchInsert"); } @Test + @Tag("xAzureSQLDW") public void batchWithLargeStringTestUseBulkCopyAPI() throws Exception { batchWithLargeStringTestInternal("BulkCopy"); } @@ -286,6 +288,7 @@ private void batchWithLargeStringTestInternal(String mode) throws Exception { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void addBatchWithLargeStringTest() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName2), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java index 0d5ef434e..c22185bab 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java @@ -14,6 +14,7 @@ import java.time.OffsetDateTime; import java.time.OffsetTime; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,6 +27,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class SetObjectTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("SetObjectTestTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java index 2296941e0..e481f4950 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -22,6 +23,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class DataClassificationTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("DataClassification"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java index bdfd7ac7b..a69f68f20 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java @@ -53,6 +53,7 @@ public class ResultSetTest extends AbstractTest { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testJdbc41ResultSetMethods() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ( " + "col1 int, " @@ -301,6 +302,7 @@ public void testGetObjectAsLocalDateTime() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testGetObjectAsOffsetDateTime() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { final String testValue = "2018-01-02T11:22:33.123456700+12:34"; @@ -376,6 +378,7 @@ public void testGetterOnNull() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testGetSetHoldability() throws SQLException { int[] holdabilityOptions = {ResultSet.HOLD_CURSORS_OVER_COMMIT, ResultSet.CLOSE_CURSORS_AT_COMMIT}; @@ -401,6 +404,7 @@ public void testGetSetHoldability() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testResultSetMethods() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java index 4d3eeb0f6..9c9a07041 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java @@ -11,6 +11,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -32,6 +33,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class TVPAllTypesTest extends AbstractTest { private static String tvpName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java index a1a1cf57e..29f6e38c0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -30,6 +31,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class TVPIssuesTest extends AbstractTest { private static String tvp_varcharMax = RandomUtil.getIdentifier("TVPIssuesTest_varcharMax_TVP"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java index 57d261507..25f4d1f0e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java @@ -11,6 +11,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -24,6 +25,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class TVPNumericTest extends AbstractTest { static SQLServerDataTable tvp = null; @@ -129,5 +131,4 @@ public void terminateVariation() throws SQLException { tvp.clear(); } } - } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java index 37ad348f8..a2d822d50 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java @@ -17,6 +17,7 @@ import java.util.TimeZone; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -32,6 +33,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class TVPResultSetCursorTest extends AbstractTest { static BigDecimal[] expectedBigDecimals = {new BigDecimal("12345.12345"), new BigDecimal("125.123"), diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java index a4bf77ba9..5609f95f2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -29,6 +30,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class TVPSchemaTest extends AbstractTest { static SQLServerDataTable tvp = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java index de8440918..2fbb48c4c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java @@ -16,6 +16,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,6 +32,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class TVPTypesTest extends AbstractTest { static SQLServerDataTable tvp = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java index 8d21f523e..9ee7d74e4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java @@ -14,6 +14,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,6 +32,7 @@ public class SQLServerErrorTest extends AbstractTest { static int loginTimeOutInSeconds = 10; @Test + @Tag("xAzureSQLDW") public void testLoginFailedError() { SQLServerDataSource ds = new SQLServerDataSource(); ds.setURL(connectionString); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java index 22b7c2056..c4abd769e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java @@ -12,6 +12,7 @@ import java.sql.SQLException; import java.text.MessageFormat; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -34,6 +35,7 @@ public class SavepointTest extends AbstractTest { * Testing SavePoint with name. */ @Test + @Tag("xAzureSQLDW") public void testSavePointName() throws SQLException { try (Connection connection = getConnection()) { @@ -63,6 +65,7 @@ public void testSavePointName() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testSavePointId() throws SQLException { try (Connection connection = getConnection()) { @@ -92,6 +95,7 @@ public void testSavePointId() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testSavePointIsNamed() throws SQLException { try (Connection connection = getConnection()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java index 1aa6dbe30..b22bf9af6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -33,6 +34,7 @@ * A class for testing the UTF8 support changes. */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class UTF8SupportTest extends AbstractTest { private static Connection connection; private static String databaseName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java index f401eae45..16c86afa1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -29,6 +30,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class LobsStreamingTest extends AbstractTest { private static String tableName = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java index 7d8df1c5f..e674ae177 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.function.Executable; @@ -58,6 +59,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class LobsTest extends AbstractTest { static String tableName; static String escapedTableName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java index 4bbaff397..f984c424b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java @@ -14,6 +14,7 @@ import java.util.Date; import java.util.TimeZone; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -33,6 +34,7 @@ public class DTOSerialTest extends AbstractTest { private static String dateString; @Test + @Tag("xAzureSQLDW") public void testDSerial() throws Exception { sdf.setTimeZone(TimeZone.getTimeZone("Z")); dateString = sdf.format(new Date()); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java index ae577a255..521342802 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java @@ -8,7 +8,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.lang.reflect.Field; import java.sql.BatchUpdateException; @@ -38,7 +37,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class BatchExecuteWithErrorsTest extends AbstractTest { public static final Logger log = Logger.getLogger("BatchExecuteWithErrors"); @@ -73,18 +71,20 @@ public void Repro47239UseBulkCopyAPI() throws Exception { } /** - * Tests large methods, supported in 42 + * Tests large methods * * @throws Exception */ @Test @DisplayName("Regression test for using 'large' methods") + @Tag("xAzureSQLDW") public void Repro47239large() throws Exception { Repro47239largeInternal("BatchInsert"); } @Test @DisplayName("Regression test for using 'large' methods using bulk copy API") + @Tag("xAzureSQLDW") public void Repro47239largeUseBulkCopyAPI() throws Exception { Repro47239largeInternal("BulkCopy"); } @@ -93,8 +93,7 @@ private void Repro47239Internal(String mode) throws Exception { try (Connection con = getConnection()) { if (isSqlAzure()) { // SQL Azure will throw exception for "raiserror WITH LOG", so the following RAISERROR statements have - // not - // "with log" option + // not "with log" option warning = "RAISERROR ('raiserror level 4',4,1)"; error = "RAISERROR ('raiserror level 11',11,1)"; // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to @@ -120,20 +119,209 @@ private void Repro47239Internal(String mode) throws Exception { int[] expectedUpdateCounts; String actualExceptionText; - try (Connection conn = getConnection()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + if (mode.equalsIgnoreCase("bulkcopy")) { modifyConnectionForBulkCopyAPI((SQLServerConnection) conn); } - try (Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1))"); + + // Regular Statement batch update + expectedUpdateCounts = new int[] {1, -2, 1, -2, 1, -2}; + try (Statement batchStmt = conn.createStatement()) { + batchStmt.addBatch(insertStmt); + batchStmt.addBatch(warning); + batchStmt.addBatch(insertStmt); + batchStmt.addBatch(warning); + batchStmt.addBatch(insertStmt); + batchStmt.addBatch(warning); + try { + actualUpdateCounts = batchStmt.executeBatch(); + actualExceptionText = ""; + } catch (BatchUpdateException bue) { + actualUpdateCounts = bue.getUpdateCounts(); + actualExceptionText = bue.getMessage(); + if (log.isLoggable(Level.FINE)) { + log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); + } + } finally { + batchStmt.close(); + } + } + if (log.isLoggable(Level.FINE)) { + log.fine("UpdateCounts:"); + } + for (int updateCount : actualUpdateCounts) { + log.fine("" + updateCount + ","); + } + + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), + TestResource.getResource("R_testInterleaved")); + + expectedUpdateCounts = new int[] {-3, 1, 1, 1}; + stmt.addBatch(error); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + try { + actualUpdateCounts = stmt.executeBatch(); + actualExceptionText = ""; + } catch (BatchUpdateException bue) { + actualUpdateCounts = bue.getUpdateCounts(); + actualExceptionText = bue.getMessage(); + } + log.fine("UpdateCounts:"); + for (int updateCount : actualUpdateCounts) { + log.fine("" + updateCount + ","); + } + + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), + TestResource.getResource("R_errorFollowInserts")); + // 50280 + expectedUpdateCounts = new int[] {1, -3}; + stmt.addBatch(insertStmt); + stmt.addBatch(error16); + try { + actualUpdateCounts = stmt.executeBatch(); + actualExceptionText = ""; + } catch (BatchUpdateException bue) { + actualUpdateCounts = bue.getUpdateCounts(); + actualExceptionText = bue.getMessage(); + } + for (int updateCount : actualUpdateCounts) { + log.fine("" + updateCount + ","); + } + + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), + TestResource.getResource("R_errorFollow50280")); + + // Test "soft" errors + conn.setAutoCommit(false); + stmt.addBatch(select); + stmt.addBatch(insertStmt); + stmt.addBatch(select); + stmt.addBatch(insertStmt); + try { + stmt.executeBatch(); + // Soft error test: executeBatch unexpectedly succeeded + assertEquals(true, false, TestResource.getResource("R_shouldThrowException")); + } catch (BatchUpdateException bue) { + assertEquals("A result set was generated for update.", bue.getMessage(), + TestResource.getResource("R_unexpectedExceptionContent")); + assertEquals(Arrays.equals(bue.getUpdateCounts(), new int[] {-3, 1, -3, 1}), true, + TestResource.getResource("R_incorrectUpdateCount")); + } + conn.rollback(); + stmt.addBatch(dateConversionError); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + try { + stmt.executeBatch(); + } catch (BatchUpdateException bue) { + if (isSqlAzureDW()) { + assertThat(bue.getMessage(), + containsString(TestResource.getResource("R_syntaxErrorDateConvertDW"))); + } else { + assertThat(bue.getMessage(), containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); + } + } catch (SQLException e) { + assertThat(e.getMessage(), containsString(TestResource.getResource("R_dateConvertError"))); + } + conn.setAutoCommit(true); + + // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to + // cut the current connection by a statement inside a SQL batch. + // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the + // database, + // this simulation cannot be written entirely in TSQL (because it needs a new connection), + // and thus it cannot be put into a TSQL batch and it is useless here. + // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) + // errors" + // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best + // test coverage. + if (!isSqlAzure()) { + // Test Severe (connection-closing) errors + stmt.addBatch(error); + stmt.addBatch(insertStmt); + stmt.addBatch(warning); + stmt.addBatch(select); + stmt.addBatch(insertStmt); + stmt.addBatch(severe); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (Exception ignored) {} - stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1))"); + stmt.executeBatch(); + // Test fatal errors batch execution succeeded (should have failed) + assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); + } catch (BatchUpdateException bue) { + // Test fatal errors returned BatchUpdateException rather than SQLException + assertEquals(false, true, TestResource.getResource("R_unexpectedException") + bue.getMessage()); + + } catch (SQLException e) { + actualExceptionText = e.getMessage(); + + if (actualExceptionText.endsWith("reset")) { + assertTrue(actualExceptionText.equalsIgnoreCase("Connection reset"), + TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); + } else { + assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), + TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); + } + } + } + } finally { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + } + } + } + + private void Repro47239largeInternal(String mode) throws Exception { + // the DBConnection for detecting whether the server is SQL Azure or SQL Server. + try (Connection con = getConnection()) { + if (isSqlAzure()) { + // SQL Azure will throw exception for "raiserror WITH LOG", so the following RAISERROR statements have + // not + // "with log" option + warning = "RAISERROR ('raiserror level 4',4,1)"; + error = "RAISERROR ('raiserror level 11',11,1)"; + // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to + // cut the current connection by a statement inside a SQL batch. + // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the + // database, + // this simulation cannot be written entirely in TSQL (because it needs a new connection), + // and thus it cannot be put into a TSQL batch and it is useless here. + // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) + // errors" + // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best + // test coverage. + severe = "--Not executed when testing against SQL Azure"; // this is a dummy statement that never being + // executed on SQL Azure + } else { + warning = "RAISERROR ('raiserror level 4',4,1) WITH LOG"; + error = "RAISERROR ('raiserror level 11',11,1) WITH LOG"; + severe = "RAISERROR ('raiserror level 20',20,1) WITH LOG"; + } + con.close(); + long[] actualUpdateCounts; + long[] expectedUpdateCounts; + String actualExceptionText; + + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + + if (mode.equalsIgnoreCase("bulkcopy")) { + modifyConnectionForBulkCopyAPI((SQLServerConnection) conn); + } + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + stmt.executeLargeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1) primary key)"); // Regular Statement batch update - expectedUpdateCounts = new int[] {1, -2, 1, -2, 1, -2}; + expectedUpdateCounts = new long[] {1, -2, 1, -2, 1, -2}; try (Statement batchStmt = conn.createStatement()) { batchStmt.addBatch(insertStmt); batchStmt.addBatch(warning); @@ -142,62 +330,58 @@ private void Repro47239Internal(String mode) throws Exception { batchStmt.addBatch(insertStmt); batchStmt.addBatch(warning); try { - actualUpdateCounts = batchStmt.executeBatch(); + actualUpdateCounts = batchStmt.executeLargeBatch(); actualExceptionText = ""; } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getUpdateCounts(); + actualUpdateCounts = bue.getLargeUpdateCounts(); actualExceptionText = bue.getMessage(); - if (log.isLoggable(Level.FINE)) { - log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); - } - } finally { - batchStmt.close(); + log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); } } - if (log.isLoggable(Level.FINE)) { - log.fine("UpdateCounts:"); - } - for (int updateCount : actualUpdateCounts) { + + log.fine("UpdateCounts:"); + for (long updateCount : actualUpdateCounts) { log.fine("" + updateCount + ","); } - log.fine(""); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_testInterleaved")); - expectedUpdateCounts = new int[] {-3, 1, 1, 1}; + expectedUpdateCounts = new long[] {-3, 1, 1, 1}; stmt.addBatch(error); stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); try { - actualUpdateCounts = stmt.executeBatch(); + actualUpdateCounts = stmt.executeLargeBatch(); actualExceptionText = ""; } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getUpdateCounts(); + actualUpdateCounts = bue.getLargeUpdateCounts(); actualExceptionText = bue.getMessage(); } log.fine("UpdateCounts:"); - for (int updateCount : actualUpdateCounts) { + for (long updateCount : actualUpdateCounts) { log.fine("" + updateCount + ","); } - log.fine(""); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollowInserts")); + // 50280 - expectedUpdateCounts = new int[] {1, -3}; + expectedUpdateCounts = new long[] {1, -3}; stmt.addBatch(insertStmt); stmt.addBatch(error16); try { - actualUpdateCounts = stmt.executeBatch(); + actualUpdateCounts = stmt.executeLargeBatch(); actualExceptionText = ""; } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getUpdateCounts(); + actualUpdateCounts = bue.getLargeUpdateCounts(); actualExceptionText = bue.getMessage(); } - for (int updateCount : actualUpdateCounts) { + for (long updateCount : actualUpdateCounts) { log.fine("" + updateCount + ","); } - log.fine(""); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollow50280")); @@ -208,13 +392,15 @@ private void Repro47239Internal(String mode) throws Exception { stmt.addBatch(select); stmt.addBatch(insertStmt); try { - stmt.executeBatch(); - // Soft error test: executeBatch unexpectedly succeeded - assertEquals(true, false, TestResource.getResource("R_shouldThrowException")); + stmt.executeLargeBatch(); + // Soft error test: executeLargeBatch unexpectedly succeeded + assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); } catch (BatchUpdateException bue) { + // Soft error test: wrong error message in BatchUpdateException assertEquals("A result set was generated for update.", bue.getMessage(), TestResource.getResource("R_unexpectedExceptionContent")); - assertEquals(Arrays.equals(bue.getUpdateCounts(), new int[] {-3, 1, -3, 1}), true, + // Soft error test: wrong update counts in BatchUpdateException + assertEquals(Arrays.equals(bue.getLargeUpdateCounts(), new long[] {-3, 1, -3, 1}), true, TestResource.getResource("R_incorrectUpdateCount")); } conn.rollback(); @@ -225,23 +411,11 @@ private void Repro47239Internal(String mode) throws Exception { stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); try { - stmt.executeBatch(); + stmt.executeLargeBatch(); } catch (BatchUpdateException bue) { - if (isSqlAzureDW()) { - assertThat(bue.getMessage(), - containsString(TestResource.getResource("R_syntaxErrorDateConvertDW"))); - } else { - assertThat(bue.getMessage(), - containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); - } - // CTestLog.CompareStartsWith(bue.getMessage(), "Syntax error converting date", "Transaction - // rollback with conversion error threw wrong - // BatchUpdateException"); + assertThat(bue.getMessage(), containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); } catch (SQLException e) { assertThat(e.getMessage(), containsString(TestResource.getResource("R_dateConvertError"))); - // CTestLog.CompareStartsWith(e.getMessage(), "Conversion failed when converting date", "Transaction - // rollback with conversion error threw - // wrong SQLException"); } conn.setAutoCommit(true); @@ -254,27 +428,26 @@ private void Repro47239Internal(String mode) throws Exception { // and thus it cannot be put into a TSQL batch and it is useless here. // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) // errors" - // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best + // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have + // best // test coverage. if (!isSqlAzure()) { // Test Severe (connection-closing) errors stmt.addBatch(error); stmt.addBatch(insertStmt); stmt.addBatch(warning); - // TODO Removed until ResultSet refactoring task (45832) is complete. - // stmt.addBatch(select); // error: select not permitted in batch + stmt.addBatch(insertStmt); stmt.addBatch(severe); stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); try { - stmt.executeBatch(); + stmt.executeLargeBatch(); // Test fatal errors batch execution succeeded (should have failed) assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); } catch (BatchUpdateException bue) { // Test fatal errors returned BatchUpdateException rather than SQLException assertEquals(false, true, TestResource.getResource("R_unexpectedException") + bue.getMessage()); - } catch (SQLException e) { actualExceptionText = e.getMessage(); @@ -286,213 +459,13 @@ private void Repro47239Internal(String mode) throws Exception { assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); - } - } - } - } - } finally { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - stmt.executeUpdate("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName)); - } - } - } - private void Repro47239largeInternal(String mode) throws Exception { - assumeTrue("JDBC42".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - // the DBConnection for detecting whether the server is SQL Azure or SQL Server. - try (Connection con = getConnection()) { - if (isSqlAzure()) { - // SQL Azure will throw exception for "raiserror WITH LOG", so the following RAISERROR statements have - // not - // "with log" option - warning = "RAISERROR ('raiserror level 4',4,1)"; - error = "RAISERROR ('raiserror level 11',11,1)"; - // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to - // cut the current connection by a statement inside a SQL batch. - // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the - // database, - // this simulation cannot be written entirely in TSQL (because it needs a new connection), - // and thus it cannot be put into a TSQL batch and it is useless here. - // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) - // errors" - // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best - // test coverage. - severe = "--Not executed when testing against SQL Azure"; // this is a dummy statement that never being - // executed on SQL Azure - } else { - warning = "RAISERROR ('raiserror level 4',4,1) WITH LOG"; - error = "RAISERROR ('raiserror level 11',11,1) WITH LOG"; - severe = "RAISERROR ('raiserror level 20',20,1) WITH LOG"; - } - con.close(); - - long[] actualUpdateCounts; - long[] expectedUpdateCounts; - String actualExceptionText; - - try (Connection conn = getConnection()) { - if (mode.equalsIgnoreCase("bulkcopy")) { - modifyConnectionForBulkCopyAPI((SQLServerConnection) conn); - } - try (Statement stmt = conn.createStatement()) { - - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (Exception ignored) {} - try { - stmt.executeLargeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1) primary key)"); - } catch (Exception ignored) {} - // Regular Statement batch update - expectedUpdateCounts = new long[] {1, -2, 1, -2, 1, -2}; - try (Statement batchStmt = conn.createStatement()) { - batchStmt.addBatch(insertStmt); - batchStmt.addBatch(warning); - batchStmt.addBatch(insertStmt); - batchStmt.addBatch(warning); - batchStmt.addBatch(insertStmt); - batchStmt.addBatch(warning); - try { - actualUpdateCounts = batchStmt.executeLargeBatch(); - actualExceptionText = ""; - } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getLargeUpdateCounts(); - actualExceptionText = bue.getMessage(); - log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); - } - } - - log.fine("UpdateCounts:"); - for (long updateCount : actualUpdateCounts) { - log.fine("" + updateCount + ","); - } - log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), - TestResource.getResource("R_testInterleaved")); - - expectedUpdateCounts = new long[] {-3, 1, 1, 1}; - stmt.addBatch(error); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - try { - actualUpdateCounts = stmt.executeLargeBatch(); - actualExceptionText = ""; - } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getLargeUpdateCounts(); - actualExceptionText = bue.getMessage(); - } - log.fine("UpdateCounts:"); - for (long updateCount : actualUpdateCounts) { - log.fine("" + updateCount + ","); - } - log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), - TestResource.getResource("R_errorFollowInserts")); - - // 50280 - expectedUpdateCounts = new long[] {1, -3}; - stmt.addBatch(insertStmt); - stmt.addBatch(error16); - try { - actualUpdateCounts = stmt.executeLargeBatch(); - actualExceptionText = ""; - } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getLargeUpdateCounts(); - actualExceptionText = bue.getMessage(); - } - for (long updateCount : actualUpdateCounts) { - log.fine("" + updateCount + ","); - } - log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), - TestResource.getResource("R_errorFollow50280")); - - // Test "soft" errors - conn.setAutoCommit(false); - stmt.addBatch(select); - stmt.addBatch(insertStmt); - stmt.addBatch(select); - stmt.addBatch(insertStmt); - try { - stmt.executeLargeBatch(); - // Soft error test: executeLargeBatch unexpectedly succeeded - assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); - } catch (BatchUpdateException bue) { - // Soft error test: wrong error message in BatchUpdateException - assertEquals("A result set was generated for update.", bue.getMessage(), - TestResource.getResource("R_unexpectedExceptionContent")); - // Soft error test: wrong update counts in BatchUpdateException - assertEquals(Arrays.equals(bue.getLargeUpdateCounts(), new long[] {-3, 1, -3, 1}), true, - TestResource.getResource("R_incorrectUpdateCount")); - } - conn.rollback(); - - // Defect 128801: Rollback (with conversion error) should throw SQLException - stmt.addBatch(dateConversionError); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - try { - stmt.executeLargeBatch(); - } catch (BatchUpdateException bue) { - assertThat(bue.getMessage(), - containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); - } catch (SQLException e) { - assertThat(e.getMessage(), containsString(TestResource.getResource("R_dateConvertError"))); - } - - conn.setAutoCommit(true); - - // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to - // cut the current connection by a statement inside a SQL batch. - // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the - // database, - // this simulation cannot be written entirely in TSQL (because it needs a new connection), - // and thus it cannot be put into a TSQL batch and it is useless here. - // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) - // errors" - // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have - // best - // test coverage. - if (!isSqlAzure()) { - // Test Severe (connection-closing) errors - stmt.addBatch(error); - stmt.addBatch(insertStmt); - stmt.addBatch(warning); - - stmt.addBatch(insertStmt); - stmt.addBatch(severe); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - try { - stmt.executeLargeBatch(); - // Test fatal errors batch execution succeeded (should have failed) - assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); - } catch (BatchUpdateException bue) { - // Test fatal errors returned BatchUpdateException rather than SQLException - assertEquals(false, true, - TestResource.getResource("R_unexpectedException") + bue.getMessage()); - } catch (SQLException e) { - actualExceptionText = e.getMessage(); - - if (actualExceptionText.endsWith("reset")) { - assertTrue(actualExceptionText.equalsIgnoreCase("Connection reset"), - TestResource.getResource("R_unexpectedExceptionContent") + ": " - + actualExceptionText); - } else { - assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), - TestResource.getResource("R_unexpectedExceptionContent") + ": " - + actualExceptionText); - - } } } - - try { - stmt.executeLargeUpdate("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName)); - } catch (Exception ignored) {} + } + } finally { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java index d3de5182e..9bec966d6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.lang.reflect.Field; import java.sql.Connection; @@ -17,6 +16,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -29,7 +29,6 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -38,6 +37,8 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xSQLv12") +@Tag("xAzureSQLDW") public class BatchExecutionTest extends AbstractTest { static String ctstable1; @@ -233,10 +234,6 @@ public static void testSetup() throws TestAbortedException, Exception { ctstable1 = RandomUtil.getIdentifier("ctstable1"); ctstable2 = RandomUtil.getIdentifier("ctstable2"); - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - dropTable(); createTable(); } @@ -251,10 +248,6 @@ private static void dropTable() throws SQLException { @AfterAll public static void terminateVariation() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - dropTable(); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java index 62e300227..5645ccd0e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -33,6 +34,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class BatchTriggerTest extends AbstractTest { static String tableName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java index 8d8586ddb..d2df80af6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java @@ -13,6 +13,7 @@ import java.sql.Statement; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -29,6 +30,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class CallableMixedTest extends AbstractTest { String tableName = RandomUtil.getIdentifier("TFOO3"); String procName = RandomUtil.getIdentifier("SPFOO3"); @@ -39,7 +41,6 @@ public class CallableMixedTest extends AbstractTest { * @throws SQLException */ @Test - @DisplayName("Test CallableMix") public void datatypesTest() throws SQLException { try (Connection connection = getConnection(); Statement statement = connection.createStatement();) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java index ceff67cbc..ffba0d520 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java @@ -21,7 +21,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -38,6 +38,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class LimitEscapeTest extends AbstractTest { public static final Logger log = Logger.getLogger("LimitEscape"); private static Vector offsetQuery = new Vector<>(); @@ -270,7 +271,6 @@ public static void createAndPopulateTables(Connection conn) throws Exception { * @throws Exception */ @Test - @DisplayName("initAndVerifyQueries") public void initAndVerifyQueries() throws Exception { Query qry; try (Connection conn = getConnection()) { @@ -836,7 +836,6 @@ public void initAndVerifyQueries() throws Exception { * @throws Exception */ @Test - @DisplayName("verifyOffsetException") public void verifyOffsetException() throws Exception { offsetQuery.addElement("select * from " + AbstractSQLGenerator.escapeIdentifier(TestUtils.escapeSingleQuotes(table1)) + " {limit 2 offset 1}"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java index c55e09462..939edecfe 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,6 +32,7 @@ * Testing merge queries */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class MergeTest extends AbstractTest { static String cricketTeams = RandomUtil.getIdentifier("CricketTeams"); static String cricketTeamsUpdated = RandomUtil.getIdentifier("cricketTeamsUpdated"); @@ -68,7 +70,6 @@ public class MergeTest extends AbstractTest { * @throws Exception */ @Test - @DisplayName("Merge Test") public void runTest() throws Exception { try (DBConnection conn = new DBConnection(connectionString)) { if (conn.getServerVersion() >= 10) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java index c4127b2b5..aa370d955 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -30,6 +31,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class NamedParamMultiPartTest extends AbstractTest { private static final String dataPut = RandomUtil.getIdentifier("dataPut"); static String procedureName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java index 0bb0b2785..8e5ea2eff 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -36,6 +37,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class PQImpsTest extends AbstractTest { private static final int SQL_SERVER_2012_VERSION = 11; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java index 8220dad3c..bc09c32cd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java @@ -22,6 +22,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -67,6 +68,7 @@ private int executeSQLReturnFirstInt(SQLServerConnection conn, String sql) throw * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testBatchedUnprepare() throws SQLException { SQLServerConnection conOuter = null; @@ -145,6 +147,7 @@ public void testBatchedUnprepare() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testStatementPooling() throws Exception { testStatementPoolingInternal("batchInsert"); } @@ -159,6 +162,7 @@ public void testStatementPooling() throws Exception { * @throws IllegalArgumentException */ @Test + @Tag("xAzureSQLDW") public void testStatementPoolingUseBulkCopyAPI() throws Exception { testStatementPoolingInternal("BulkCopy"); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java index 2b140e109..1a8ce8e95 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.unit.statement; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.JDBCType; @@ -16,6 +15,7 @@ import java.sql.Types; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -40,6 +40,7 @@ public class RegressionTest extends AbstractTest { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testServerCursorPStmt() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { @@ -147,16 +148,13 @@ public void testSelectIntoUpdateCount() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testUpdateQuery() throws SQLException { - assumeTrue("JDBC41".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String sql; JDBCType[] targets = {JDBCType.INTEGER, JDBCType.SMALLINT}; int rows = 3; - tableName = RandomUtil.getIdentifier("[updateQuery]"); - + tableName = RandomUtil.getIdentifier("updateQuery"); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (" + "c1 int null," + "PK int NOT NULL PRIMARY KEY" + ")"); @@ -207,15 +205,12 @@ public void testUpdateQuery() throws SQLException { * @throws SQLException */ @Test + @Tag("xAzureSQLDW") public void testXmlQuery() throws SQLException { - assumeTrue("JDBC41".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - createTable(stmt); - tableName = RandomUtil.getIdentifier("try_SQLXML_Table"); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + createTable(stmt); String sql = "UPDATE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " SET [c2] = ?, [c3] = ?"; try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement(sql)) { @@ -235,7 +230,7 @@ public void testXmlQuery() throws SQLException { pstmt.setObject(2, null, Types.SQLXML); pstmt.executeUpdate(); } finally { - TestUtils.dropTableIfExists(tableName, stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java index e8dcb6dff..b4fe1f2b0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java @@ -10,6 +10,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -20,6 +21,7 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class StatementCancellationTest extends AbstractTest { private static final long DELAY_WAIT_MILLISECONDS = 10000; private static final long CANCEL_WAIT_MILLISECONDS = 5000; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index 63e174ab6..abb7fa10b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.StringReader; import java.math.BigDecimal; @@ -33,7 +32,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -63,6 +61,7 @@ public class StatementTest extends AbstractTest { public static final Logger log = Logger.getLogger("StatementTest"); @Nested + @Tag("xAzureSQLDW") public class TCAttentionHandling { private static final int NUM_TABLE_ROWS = 1000; private static final int MIN_TABLE_ROWS = 100; @@ -77,9 +76,7 @@ public void init() throws Exception { try (Connection con = getConnection()) { con.setAutoCommit(false); try (Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (SQLException e) {} + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 INT, col2 VARCHAR(" + TEST_STRING.length() + "))"); for (int i = 0; i < NUM_TABLE_ROWS; i++) @@ -93,9 +90,7 @@ public void init() throws Exception { @AfterEach public void terminate() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (SQLException e) {} + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } @@ -106,7 +101,6 @@ public void terminate() throws Exception { */ @Test public void testCancelBeforeExecute() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.cancel(); try (ResultSet rs = stmt @@ -114,7 +108,6 @@ public void testCancelBeforeExecute() throws Exception { int numSelectedRows = 0; while (rs.next()) ++numSelectedRows; - // Wrong number of rows returned assertEquals(NUM_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); } @@ -214,9 +207,6 @@ public void testQueryTimeout() throws Exception { */ @Test public void testCancelLongResponse() throws Exception { - assumeTrue("JDBC42".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - try (Connection con = getConnection(); Statement stmt = con .createStatement(SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) { ((SQLServerStatement) stmt).setResponseBuffering("adaptive"); @@ -252,8 +242,7 @@ public void testCancelLongResponse() throws Exception { assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertEquals(TestResource.getResource("R_queryCancelled"), - TestResource.getResource("R_unexpectedException")); + assertEquals(TestResource.getResource("R_queryCancelled"), e.getMessage()); } assertEquals(false, NUM_TABLE_ROWS * NUM_TABLE_ROWS == numSelectedRows, @@ -964,48 +953,8 @@ public void testConsecutiveQueries() throws Exception { } } - /** - * TestJDBCVersion.value < 42 getLargeMaxRows / setLargeMaxRows should throw exception for version before - * sqljdbc42 - * - * @throws Exception - */ @Test - public void testLargeMaxRowsJDBC41() throws Exception { - assumeTrue("JDBC41".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - - try (Connection con = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - - // testing exception for getLargeMaxRows method - try { - stmt.getLargeMaxRows(); - throw new SQLException(TestResource.getResource("R_unexpectedException")); - } catch (Exception e) { - fail(e.getMessage()); - } - - // testing exception for setLargeMaxRows method - try { - stmt.setLargeMaxRows(2015); - throw new SQLException(TestResource.getResource("R_unexpectedException")); - } catch (Exception e) { - fail(e.getMessage()); - } - } - } - - /** - * testLargeMaxRows on JDBCVersion = 42 or later - * - * @throws Exception - */ - @Test - public void testLargeMaxRowsJDBC42() throws Exception { - assumeTrue("JDBC42".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - + public void testLargeMaxRows() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { // Default value should return zero @@ -1026,10 +975,10 @@ public void testLargeMaxRowsJDBC42() throws Exception { stmt.setLargeMaxRows(newValue); throw new SQLException("setLargeMaxRows(): Long values should not be set"); } catch (Exception e) { - assertEquals( - ("calling setLargeMaxRows failed : java.lang.UnsupportedOperationException: " - + "The supported maximum row count for a result set is Integer.MAX_VALUE or less."), - (e.getMessage()), TestResource.getResource("R_unexpectedException")); + assertTrue( + e.getMessage().contains( + "The supported maximum row count for a result set is Integer.MAX_VALUE or less."), + TestResource.getResource("R_unexpectedException")); } // Set a negative value. If negative is accepted, throw exception @@ -1037,10 +986,10 @@ public void testLargeMaxRowsJDBC42() throws Exception { stmt.setLargeMaxRows(-2012L); throw new SQLException("setLargeMaxRows(): Negative value not allowed"); } catch (Exception e) { - assertEquals( - "calling setLargeMaxRows failed : com.microsoft.sqlserver.jdbc.SQLServerException: " - + "The maximum row count -2,012 for a result set must be non-negative.", - e.getMessage(), TestResource.getResource("R_unexpectedException")); + assertTrue( + e.getMessage() + .contains("The maximum row count -2,012 for a result set must be non-negative."), + TestResource.getResource("R_unexpectedException")); } } } @@ -1066,6 +1015,7 @@ public class TCStatementCallable { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testJdbc41CallableStatementMethods() throws Exception { // Prepare database setup @@ -1224,6 +1174,7 @@ public class TCStatementParam { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testStatementOutParamGetsTwice() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -1272,6 +1223,7 @@ public void testStatementOutParamGetsTwice() throws Exception { } @Test + @Tag("xAzureSQLDW") public void testStatementOutManyParamGetsTwiceRandomOrder() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.executeUpdate("CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procName) @@ -1305,6 +1257,7 @@ public void testStatementOutManyParamGetsTwiceRandomOrder() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testStatementOutParamGetsTwiceInOut() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.executeUpdate("CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procName) @@ -1334,6 +1287,7 @@ public void testStatementOutParamGetsTwiceInOut() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testResultSetParams() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { @@ -1369,6 +1323,7 @@ public void testResultSetParams() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testResultSetNullParams() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { @@ -1433,6 +1388,7 @@ public void testFailedToResumeTransaction() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testResultSetErrors() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { @@ -1463,19 +1419,19 @@ public void testResultSetErrors() throws Exception { * Verify proper handling of row errors in ResultSets. */ @Test - @Disabled - // TODO: We are commenting this out due to random AppVeyor failures. We will investigate later. + @Tag("xAzureSQLDW") public void testRowError() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " (ROWID int IDENTITY, col1 int)"); stmt.executeUpdate("insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " values(0)"); stmt.executeUpdate("insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " values(1)"); stmt.executeUpdate("insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " values(2)"); stmt.execute( "create procedure " + AbstractSQLGenerator.escapeIdentifier(procName) + " @col1Value int AS " + " BEGIN " + " SELECT col1 FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " WITH (UPDLOCK) WHERE (col1 = @col1Value) " + " END"); + + " WITH (UPDLOCK) WHERE (col1 = @col1Value) ORDER BY ROWID" + " END"); // For the test, lock each row in the table, one by one, for update // on one connection and, on another connection, verify that the @@ -1515,8 +1471,9 @@ public void testRowError() throws Exception { try (Statement stmt2 = testConn2.createStatement()) { stmt2.executeUpdate("SET LOCK_TIMEOUT 0"); - try (CallableStatement cstmt2 = testConn2.prepareCall("SELECT col1 FROM " - + AbstractSQLGenerator.escapeIdentifier(tableName) + " WITH (UPDLOCK)")) { + try (CallableStatement cstmt2 = testConn2.prepareCall( + "SELECT col1 FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " WITH (UPDLOCK) ORDER BY ROWID")) { // Verify that the result set can be closed after // the lock timeout error @@ -1527,10 +1484,7 @@ public void testRowError() throws Exception { // indicated row and continues to report that exception on subsequent // accesses to that row. try (ResultSet rs = cstmt2.executeQuery()) { - for (int i = 0; i < row; i++) - assertEquals(true, rs.next(), "Query returned wrong number of rows."); - - for (int i = 0; i < 2; i++) { + for (int i = 0; i < row; i++) { try { rs.next(); assertEquals(false, true, "lock timeout" @@ -1607,6 +1561,7 @@ public void terminate() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testNBCROWNullsForLOBs() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1640,6 +1595,7 @@ public void testNBCROWNullsForLOBs() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testSparseColumnSetValues() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1679,6 +1635,7 @@ public void testSparseColumnSetValues() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testSparseColumnSetIndex() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1717,6 +1674,7 @@ public void testSparseColumnSetIndex() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testSparseColumnSetForException() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1754,6 +1712,7 @@ public void testSparseColumnSetForException() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testNBCRowForAllNulls() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1802,6 +1761,7 @@ public void testNBCRowForAllNulls() throws Exception { * @throws Exception */ @Test + @Tag("xAzureSQLDW") public void testNBCROWWithRandomAccess() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -2076,6 +2036,7 @@ public void testClosedConnection() throws Exception { } @Nested + @Tag("xAzureSQLDW") public class TCUpdateCountWithTriggers { private static final int NUM_ROWS = 3; @@ -2225,6 +2186,7 @@ public void terminate() throws Exception { } @Nested + @Tag("xAzureSQLDW") public class TCUpdateCountAfterRaiseError { private final String tableName = RandomUtil.getIdentifier("TCUpdateCountAfterRaiseError"); private final String triggerName = "TCUpdateCountAfterRaiseErrorTrigger"; @@ -2434,6 +2396,7 @@ public void terminate() throws Exception { } @Nested + @Tag("xAzureSQLDW") public class TCNocount { private final String tableName = RandomUtil.getIdentifier("TCNoCount"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java index d877c21c0..94a851ac2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java @@ -31,7 +31,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class WrapperTest extends AbstractTest { /** From e6f6ed4690d5e7fb4de7ca5de3d6283f26d2756d Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 29 Mar 2019 11:25:47 -0700 Subject: [PATCH 02/12] Update Azure Pipelines script + minor changes --- azure-pipelines.yml | 6 ++++-- .../jdbc/preparedStatement/BatchExecutionWithNullTest.java | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ed76a53be..e4577f947 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,8 +10,10 @@ jobs: matrix: SQL-2017: Target_SQL: 'SQL-2k17-03' + Ex_Groups: 'xSQLv13' SQL-2008R2: Target_SQL: 'SQL-2k8R2-SP3-1' + Ex_Groups: 'xSQLv12' maxParallel: 2 steps: - powershell: | @@ -31,7 +33,7 @@ jobs: displayName: 'Maven build 43' inputs: mavenPomFile: 'pom.xml' - goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild43' + goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild43 -DexcludeGroups=$(Ex_Groups)' testResultsFiles: '**/TEST-*.xml' testRunTitle: 'Maven build 43' javaHomeOption: Path @@ -43,7 +45,7 @@ jobs: displayName: 'Maven build 42' inputs: mavenPomFile: 'pom.xml' - goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild42' + goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild42 -DexcludeGroups=$(Ex_Groups)' testRunTitle: 'Maven build 42' javaHomeOption: Path jdkDirectory: $(JDK11) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java index ae613175f..f553d3a25 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java @@ -95,6 +95,7 @@ public void testAddBatch2() throws SQLException { * @throws SQLException */ @Test + @Tag("xSQLv12") public void testAddbatch2AEOnConnection() throws SQLException { try (Connection connection = PrepUtil.getConnection(connectionString + ";columnEncryptionSetting=Enabled;")) { testAddBatch2(); From e0ba5b26d5ddfbb6e789ce41286eb5e9a9189390 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 29 Mar 2019 12:02:37 -0700 Subject: [PATCH 03/12] Azure DB test compatibility added + Removed old tags --- .../microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java | 7 ------- .../jdbc/connection/NativeMSSQLDataSourceTest.java | 1 + .../jdbc/connection/RequestBoundaryMethodsTest.java | 1 + .../jdbc/databasemetadata/DatabaseMetaDataTest.java | 4 ++++ .../sqlserver/jdbc/preparedStatement/RegressionTest.java | 5 ----- .../microsoft/sqlserver/jdbc/resultset/ResultSetTest.java | 3 --- .../jdbc/ssl/trustmanager/CustomTrustManagerTest.java | 1 - .../com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java | 1 + .../sqlserver/jdbc/unit/statement/PoolableTest.java | 1 - .../jdbc/unit/statement/PreparedStatementTest.java | 5 ++--- .../sqlserver/jdbc/unit/statement/StatementTest.java | 3 --- 11 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 9ca0eeeb4..36c1fcceb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -179,7 +179,6 @@ protected static void createBinaryTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -251,7 +250,6 @@ protected static void createCharTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -305,7 +303,6 @@ protected void createDateTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -366,7 +363,6 @@ protected void createDatePrecisionTable(int scale) throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -403,7 +399,6 @@ protected static void createDateScaleTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -517,7 +512,6 @@ protected static void createNumericTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -555,7 +549,6 @@ protected void createNumericPrecisionTable(int floatPrecision, int precision, in try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); - stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java index 218eb194d..af486f5e2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java @@ -64,6 +64,7 @@ public void testDSNormal() throws ClassNotFoundException, IOException, SQLExcept @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); System.setProperty("java.net.preferIPv6Addresses", Boolean.TRUE.toString()); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java index b77221569..27a436e71 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java @@ -38,6 +38,7 @@ */ @RunWith(JUnitPlatform.class) @Tag("xAzureSQLDW") +@Tag("xAzureSQLDB") public class RequestBoundaryMethodsTest extends AbstractTest { static String tableName = RandomUtil.getIdentifier("RequestBoundaryTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java index 556c4b936..5ea7f2032 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java @@ -131,6 +131,7 @@ public void testGetURL() throws SQLException { */ @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testDBUserLogin() throws SQLException { try (Connection conn = getConnection()) { DatabaseMetaData databaseMetaData = conn.getMetaData(); @@ -188,6 +189,7 @@ public void testDBSchema() throws SQLException { */ @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testDBSchemasForDashedCatalogName() throws SQLException { UUID id = UUID.randomUUID(); String testCatalog = "dash-catalog" + id; @@ -241,6 +243,7 @@ public void testDBSchemasForDashedCatalogName() throws SQLException { */ @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testDBSchemasForDashedCatalogNameWithPattern() throws SQLException { UUID id = UUID.randomUUID(); String testCatalog = "dash-catalog" + id; @@ -492,6 +495,7 @@ public void testGetFunctionColumns() throws SQLException { @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testPreparedStatementMetadataCaching() throws SQLException { try (Connection connection = getConnection()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java index aa0df5114..538124d02 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java @@ -62,7 +62,6 @@ public static void setupTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void createViewTest() throws SQLException { try (Connection con = getConnection(); PreparedStatement pstmt1 = con.prepareStatement( @@ -83,7 +82,6 @@ public void createViewTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void createSchemaTest() throws SQLException { try (Connection con = getConnection(); PreparedStatement pstmt1 = con @@ -104,7 +102,6 @@ public void createSchemaTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void createTableTest() throws SQLException { try (Connection con = getConnection(); PreparedStatement pstmt1 = con.prepareStatement( @@ -125,7 +122,6 @@ public void createTableTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void alterTableTest() throws SQLException { try (Connection con = getConnection(); PreparedStatement pstmt1 = con.prepareStatement( @@ -149,7 +145,6 @@ public void alterTableTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void grantTest() throws SQLException { try (Connection con = getConnection(); PreparedStatement pstmt1 = con.prepareStatement( diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java index a69f68f20..98b3ce126 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java @@ -258,7 +258,6 @@ public void testJdbc41ResultSetMethods() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetObjectAsLocalDateTime() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TimeZone prevTimeZone = TimeZone.getDefault(); @@ -337,7 +336,6 @@ public void testGetObjectAsOffsetDateTime() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testResultSetWrapper() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -363,7 +361,6 @@ public void testResultSetWrapper() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetterOnNull() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select null")) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java index dc9371a8b..12b98a278 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java @@ -22,7 +22,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class CustomTrustManagerTest extends AbstractTest { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java index b22bf9af6..c01e1d535 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java @@ -35,6 +35,7 @@ */ @RunWith(JUnitPlatform.class) @Tag("xAzureSQLDW") +@Tag("xAzureSQLDB") public class UTF8SupportTest extends AbstractTest { private static Connection connection; private static String databaseName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java index bdea0a210..bd44ef196 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java @@ -33,7 +33,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class PoolableTest extends AbstractTest { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java index bc09c32cd..98049b275 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java @@ -78,9 +78,6 @@ public void testBatchedUnprepare() throws SQLException { // Turn off use of prepared statement cache. con.setStatementPoolingCacheSize(0); - // Clean-up proc cache - this.executeSQL(con, "DBCC FREEPROCCACHE;"); - String lookupUniqueifier = UUID.randomUUID().toString(); String queryCacheLookup = String.format("%%/*unpreparetest_%s%%*/SELECT 1;", lookupUniqueifier); @@ -148,6 +145,7 @@ public void testBatchedUnprepare() throws SQLException { */ @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testStatementPooling() throws Exception { testStatementPoolingInternal("batchInsert"); } @@ -163,6 +161,7 @@ public void testStatementPooling() throws Exception { */ @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testStatementPoolingUseBulkCopyAPI() throws Exception { testStatementPoolingInternal("BulkCopy"); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index abb7fa10b..a451e0aa6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -867,7 +867,6 @@ public void testCloseOnCompletion() throws Exception { } @Nested - @Tag("AzureDWTest") public class TCStatement { private final String table1Name = RandomUtil.getIdentifier("TCStatement1"); private final String table2Name = RandomUtil.getIdentifier("TCStatement2"); @@ -1867,7 +1866,6 @@ public void testNBCROWWithRandomAccess() throws Exception { } @Nested - @Tag("AzureDWTest") public class TCStatementIsClosed { @Test public void testActiveStatement() throws Exception { @@ -1931,7 +1929,6 @@ public void testClosedConnection() throws Exception { } @Nested - @Tag("AzureDWTest") public class TCResultSetIsClosed { /** From dbe571a91e091d32fa7c700b3159674133b6029d Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 29 Mar 2019 12:05:44 -0700 Subject: [PATCH 04/12] Fix AE tests --- .../microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java | 7 +++++++ .../jdbc/AlwaysEncrypted/CallableStatementTest.java | 1 + .../jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java | 1 + .../sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java | 1 + .../AlwaysEncrypted/RegressionAlwaysEncryptedTest.java | 1 + .../jdbc/unit/statement/PreparedStatementTest.java | 3 +++ 6 files changed, 14 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 36c1fcceb..9ca0eeeb4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -179,6 +179,7 @@ protected static void createBinaryTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -250,6 +251,7 @@ protected static void createCharTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -303,6 +305,7 @@ protected void createDateTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -363,6 +366,7 @@ protected void createDatePrecisionTable(int scale) throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -399,6 +403,7 @@ protected static void createDateScaleTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -512,6 +517,7 @@ protected static void createNumericTable() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } @@ -549,6 +555,7 @@ protected void createNumericPrecisionTable(int floatPrecision, int precision, in try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { fail(e.getMessage()); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index 3282f60a6..1fb75bc93 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -46,6 +46,7 @@ @RunWith(JUnitPlatform.class) @Tag("xSQLv12") @Tag("xAzureSQLDW") +@Tag("xAzureSQLDB") public class CallableStatementTest extends AESetup { private static String multiStatementsProcedure = RandomUtil.getIdentifier("multiStatementsProcedure"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index dcd7b8893..7220de127 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -37,6 +37,7 @@ @RunWith(JUnitPlatform.class) @Tag("xSQLv12") @Tag("xAzureSQLDW") +@Tag("xAzureSQLDB") public class JDBCEncryptionDecryptionTest extends AESetup { private boolean nullable = false; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index d8625e5de..b9c046885 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -39,6 +39,7 @@ @RunWith(JUnitPlatform.class) @Tag("xSQLv12") @Tag("xAzureSQLDW") +@Tag("xAzureSQLDB") public class PrecisionScaleTest extends AESetup { private static java.util.Date date = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java index 97832953b..ac97bd2b6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -27,6 +27,7 @@ @RunWith(JUnitPlatform.class) @Tag("xSQLv12") @Tag("xAzureSQLDW") +@Tag("xAzureSQLDB") public class RegressionAlwaysEncryptedTest extends AESetup { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java index 98049b275..23145d5f3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java @@ -78,6 +78,9 @@ public void testBatchedUnprepare() throws SQLException { // Turn off use of prepared statement cache. con.setStatementPoolingCacheSize(0); + // Clean-up proc cache + this.executeSQL(con, "DBCC FREEPROCCACHE;"); + String lookupUniqueifier = UUID.randomUUID().toString(); String queryCacheLookup = String.format("%%/*unpreparetest_%s%%*/SELECT 1;", lookupUniqueifier); From 94bbaadbdc8c4a29a0df9cc8c6710308747d5694 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 29 Mar 2019 12:06:18 -0700 Subject: [PATCH 05/12] Tag for Azure DB --- .../sqlserver/jdbc/unit/statement/PreparedStatementTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java index 23145d5f3..03de9a515 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java @@ -69,6 +69,7 @@ private int executeSQLReturnFirstInt(SQLServerConnection conn, String sql) throw */ @Test @Tag("xAzureSQLDW") + @Tag("xAzureSQLDB") public void testBatchedUnprepare() throws SQLException { SQLServerConnection conOuter = null; From d53cbc5c59b8d2a5e8d1c38f78b247fced86d084 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Mon, 1 Apr 2019 15:15:55 -0700 Subject: [PATCH 06/12] Minor fix --- pom.xml | 2 +- .../sqlserver/jdbc/unit/statement/RegressionTest.java | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index f1b3b770f..1d1bf62cf 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ xAzureSQLDW - - - - For tests not compatible with Azure Data Warehouse - xAzureSQLMI - - - - For tests not compatible with Azure SQL Managed Instance - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default testing enabled with SQL Server 2019 (SQLv14) in non-FIPS JVM --> + Default testing enabled with SQL Server 2019 (SQLv14) --> xSQLv14 UTF-8 diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java index 1a8ce8e95..96fa9ea2c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java @@ -30,8 +30,10 @@ @RunWith(JUnitPlatform.class) +@Tag("xAzureSQLDW") public class RegressionTest extends AbstractTest { - private static String tableName; + + private static String tableName = RandomUtil.getIdentifier("ServerCursorPStmt"); private static String procName = RandomUtil.getIdentifier("ServerCursorProc"); /** @@ -40,7 +42,6 @@ public class RegressionTest extends AbstractTest { * @throws SQLException */ @Test - @Tag("xAzureSQLDW") public void testServerCursorPStmt() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { @@ -49,8 +50,6 @@ public void testServerCursorPStmt() throws SQLException { String col3Value = "India"; String col3Lookup = "IN"; - tableName = RandomUtil.getIdentifier("ServerCursorPStmt"); - stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int primary key, col2 varchar(3), col3 varchar(128))"); stmt.executeUpdate( @@ -148,7 +147,6 @@ public void testSelectIntoUpdateCount() throws SQLException { * @throws SQLException */ @Test - @Tag("xAzureSQLDW") public void testUpdateQuery() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { String sql; @@ -205,7 +203,6 @@ public void testUpdateQuery() throws SQLException { * @throws SQLException */ @Test - @Tag("xAzureSQLDW") public void testXmlQuery() throws SQLException { try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { tableName = RandomUtil.getIdentifier("try_SQLXML_Table"); @@ -246,7 +243,7 @@ private void createTable(Statement stmt) throws SQLException { @AfterAll public static void terminate() throws SQLException { try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); } } From e0aa906e1db070129b3aa7c8f968298c08e4a61e Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 2 Apr 2019 11:41:53 -0700 Subject: [PATCH 07/12] Jacoco Merge capability --- pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pom.xml b/pom.xml index 1d1bf62cf..da63812a9 100644 --- a/pom.xml +++ b/pom.xml @@ -448,6 +448,23 @@ file:///${session.executionRootDirectory}/maven-version-rules.xml + + org.jacoco + jacoco-maven-plugin + 0.8.2 + + + + jacoco-execs/ + + *.exec + + + + + ${project.build.directory}/jacoco.exec + + From b021297746b2ff8771d2638ab2d2f230162bf1f7 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 2 Apr 2019 13:47:37 -0700 Subject: [PATCH 08/12] Exclude tags for tests not compatible --- .../sqlserver/jdbc/resultset/DataClassificationTest.java | 2 ++ .../java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java index e481f4950..cda6339cd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java @@ -24,6 +24,8 @@ @RunWith(JUnitPlatform.class) @Tag("xAzureSQLDW") +@Tag("xSQLv12") +@Tag("xSQLv13") public class DataClassificationTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("DataClassification"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java index c01e1d535..a0fc79845 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java @@ -36,6 +36,8 @@ @RunWith(JUnitPlatform.class) @Tag("xAzureSQLDW") @Tag("xAzureSQLDB") +@Tag("xSQLv12") +@Tag("xSQLv13") public class UTF8SupportTest extends AbstractTest { private static Connection connection; private static String databaseName; From e14177e7ad1cf9c4f44c863ce56f7e112add30bd Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 2 Apr 2019 17:28:37 -0700 Subject: [PATCH 09/12] Reduce connections and save resources --- .../jdbc/AlwaysEncrypted/AESetup.java | 6 +- .../CallableStatementTest.java | 147 +++++++------ .../AlwaysEncrypted/PrecisionScaleTest.java | 3 +- .../microsoft/sqlserver/jdbc/JDBC43Test.java | 2 + .../sqlserver/jdbc/SQLServerDriverTest.java | 1 - .../jdbc/SSLCertificateValidation.java | 1 - .../microsoft/sqlserver/jdbc/UtilTest.java | 1 - .../jdbc/bulkCopy/BulkCopyAllTypesTest.java | 5 +- .../bulkCopy/BulkCopyResultSetCursorTest.java | 2 +- .../jdbc/bulkCopy/BulkCopyRowSetTest.java | 37 ++-- .../ISQLServerBulkRecordIssuesTest.java | 4 +- .../callablestatement/CallableMixedTest.java | 4 +- .../CallableStatementTest.java | 4 +- .../jdbc/connection/ConnectionDriverTest.java | 11 +- .../connection/ConnectionWrapper43Test.java | 1 - .../jdbc/connection/DriverVersionTest.java | 1 - .../jdbc/connection/PoolingTest.java | 2 +- .../RequestBoundaryMethodsTest.java | 18 +- .../jdbc/connection/SSLProtocolTest.java | 1 - .../jdbc/connection/TimeoutTest.java | 18 +- .../jdbc/connection/WarningTest.java | 1 - .../DatabaseMetaDataForeignKeyTest.java | 3 +- .../jdbc/datatypes/BigIntegerTest.java | 107 +++++----- .../datatypes/BulkCopyWithSqlVariantTest.java | 7 +- .../jdbc/datatypes/DateAndTimeTypeTest.java | 3 +- .../SQLServerSpatialDatatypeTest.java | 45 ++-- .../datatypes/SQLVariantResultSetTest.java | 90 ++++---- .../sqlserver/jdbc/datatypes/SparseTest.java | 50 +++-- .../jdbc/exception/ExceptionTest.java | 21 +- .../sqlserver/jdbc/fips/FipsTest.java | 1 - .../ParameterMetaDataTest.java | 13 +- .../ParameterMetaDataWhiteSpaceTest.java | 7 +- .../BatchExecutionWithBulkCopyTest.java | 51 ++--- .../BatchExecutionWithNullTest.java | 30 ++- .../preparedStatement/RegressionTest.java | 57 +++-- .../resultset/DataClassificationTest.java | 2 +- .../trustmanager/CustomTrustManagerTest.java | 6 +- .../sqlserver/jdbc/tvp/TVPAllTypesTest.java | 2 +- .../sqlserver/jdbc/tvp/TVPIssuesTest.java | 89 ++++---- .../jdbc/tvp/TVPResultSetCursorTest.java | 23 +- .../sqlserver/jdbc/unit/UTF8SupportTest.java | 6 - .../jdbc/unit/lobs/LobsStreamingTest.java | 202 +++++++++--------- .../unit/statement/BatchExecutionTest.java | 3 +- .../jdbc/unit/statement/BatchTriggerTest.java | 27 +-- .../unit/statement/CallableMixedTest.java | 4 +- .../jdbc/unit/statement/LimitEscapeTest.java | 11 +- .../jdbc/unit/statement/MergeTest.java | 18 +- .../jdbc/unit/statement/PQImpsTest.java | 6 +- .../jdbc/unit/statement/PoolableTest.java | 1 - .../jdbc/unit/statement/RegressionTest.java | 9 +- .../jdbc/unit/statement/StatementTest.java | 38 ++-- .../jdbc/unit/statement/WrapperTest.java | 3 +- .../sqlserver/testframework/AbstractTest.java | 20 +- .../sqlserver/testframework/DBConnection.java | 2 +- 54 files changed, 557 insertions(+), 670 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 9ca0eeeb4..a55d5a125 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -73,8 +73,8 @@ public class AESetup extends AbstractTest { public static void setUpConnection() throws TestAbortedException, Exception { AETestConnectionString = connectionString + ";sendTimeAsDateTime=false"; readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name"); - try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString); + Statement stmt = con.createStatement()) { dropCEK(stmt); dropCMK(stmt); } @@ -101,7 +101,7 @@ public static void setUpConnection() throws TestAbortedException, Exception { */ @AfterAll public static void dropAll() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { dropTables(stmt); dropCEK(stmt); dropCMK(stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index 1fb75bc93..c89359f1b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -9,9 +9,12 @@ import static org.junit.jupiter.api.Assertions.fail; import java.math.BigDecimal; +import java.sql.Connection; import java.sql.Date; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; import java.util.LinkedList; @@ -26,7 +29,6 @@ import com.microsoft.sqlserver.jdbc.RandomData; import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.SQLServerStatement; @@ -277,8 +279,7 @@ public void testOutputProcedure4() throws SQLException { } private static void dropProcedures() throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProcedure), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProcedure2), stmt); @@ -302,8 +303,7 @@ private static void dropProcedures() throws SQLException { } private static void dropTables() throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); @@ -331,8 +331,8 @@ private static void createTables() throws SQLException { + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL" + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -352,8 +352,8 @@ private static void createTables() throws SQLException { + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -463,8 +463,8 @@ private static void createTables() throws SQLException { + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -476,8 +476,8 @@ private static void createTables() throws SQLException { + "DeterministicInt int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL," + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -491,8 +491,8 @@ private static void createTables() throws SQLException { + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL," + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -506,8 +506,8 @@ private static void createTables() throws SQLException { + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL," + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -517,9 +517,8 @@ private static void createTables() throws SQLException { private static void populateTable4() throws SQLException { String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(table4) + " values( " + "?,?,?" + ")"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, - stmtColEncSetting)) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + PreparedStatement pstmt = TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { // bit for (int i = 1; i <= 3; i++) { @@ -535,7 +534,7 @@ private static void populateTable3() throws SQLException { + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -643,7 +642,7 @@ private void createMultiInsertionSelection() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -662,7 +661,7 @@ private void createMultiInsertionSelection() throws SQLException { private void MultiInsertionSelection() throws SQLException { String sql = "{call " + AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure) + " (?,?,?,?,?,?)}"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -716,7 +715,7 @@ private void createInputProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(inputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -738,7 +737,7 @@ private void createInputProcedure() throws SQLException { } private void testInputProcedure(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -781,7 +780,7 @@ private void createInputProcedure2() throws SQLException { + TestUtils.escapeSingleQuotes(inputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure2); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -799,7 +798,7 @@ private void createInputProcedure2() throws SQLException { private void testInputProcedure2(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -834,7 +833,7 @@ private void createOutputProcedure3() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure3) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure3); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -849,7 +848,7 @@ private void createOutputProcedure3() throws SQLException { private void testOutputProcedure3RandomOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -879,7 +878,7 @@ private void testOutputProcedure3RandomOrder(String sql) throws SQLException { private void testOutputProcedure3Inorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -900,7 +899,7 @@ private void testOutputProcedure3Inorder(String sql) throws SQLException { private void testOutputProcedure3ReverseOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -924,7 +923,7 @@ private void createOutputProcedure2() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure2); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -941,7 +940,7 @@ private void createOutputProcedure2() throws SQLException { private void testOutputProcedure2RandomOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -994,7 +993,7 @@ private void testOutputProcedure2RandomOrder(String sql, String[] values) throws private void testOutputProcedure2Inorder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1047,7 +1046,7 @@ private void testOutputProcedure2Inorder(String sql, String[] values) throws SQL private void testOutputProcedure2ReverseOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1104,7 +1103,7 @@ private void createOutputProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1121,7 +1120,7 @@ private void createOutputProcedure() throws SQLException { private void testOutputProcedureRandomOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1170,7 +1169,7 @@ private void testOutputProcedureRandomOrder(String sql, String[] values) throws private void testOutputProcedureInorder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1212,7 +1211,7 @@ private void testOutputProcedureInorder(String sql, String[] values) throws SQLE private void testOutputProcedureReverseOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1256,7 +1255,7 @@ private void createInOutProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(inoutProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inoutProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1270,7 +1269,7 @@ private void createInOutProcedure() throws SQLException { private void testInOutProcedure(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1291,7 +1290,7 @@ private void createMixedProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(mixedProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1307,7 +1306,7 @@ private void createMixedProcedure() throws SQLException { private void testMixedProcedure(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1339,7 +1338,7 @@ private void createMixedProcedure2() throws SQLException { + TestUtils.escapeSingleQuotes(mixedProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure2); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1355,7 +1354,7 @@ private void createMixedProcedure2() throws SQLException { private void testMixedProcedure2RandomOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1390,7 +1389,7 @@ private void testMixedProcedure2RandomOrder(String sql) throws SQLException { private void testMixedProcedure2Inorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1415,7 +1414,7 @@ private void createMixedProcedure3() throws SQLException { + TestUtils.escapeSingleQuotes(mixedProcedure3) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure3); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1430,7 +1429,7 @@ private void createMixedProcedure3() throws SQLException { private void testMixedProcedure3RandomOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1465,7 +1464,7 @@ private void testMixedProcedure3RandomOrder(String sql) throws SQLException { private void testMixedProcedure3Inorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1487,7 +1486,7 @@ private void testMixedProcedure3Inorder(String sql) throws SQLException { private void testMixedProcedure3ReverseOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1513,7 +1512,7 @@ private void createMixedProcedureNumericPrcisionScale() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedureNumericPrcisionScale); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1530,7 +1529,7 @@ private void createMixedProcedureNumericPrcisionScale() throws SQLException { private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1561,7 +1560,7 @@ private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQ private void testMixedProcedureNumericPrcisionScaleParameterName(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1595,7 +1594,7 @@ private void createOutputProcedureChar() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureChar) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureChar); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1613,7 +1612,7 @@ private void createOutputProcedureChar() throws SQLException { private void testOutputProcedureCharInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1663,7 +1662,7 @@ private void testOutputProcedureCharInorder(String sql) throws SQLException { private void testOutputProcedureCharInorderObject(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1720,7 +1719,7 @@ private void createOutputProcedureNumeric() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureNumeric); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1741,7 +1740,7 @@ private void createOutputProcedureNumeric() throws SQLException { private void testOutputProcedureNumericInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1830,7 +1829,7 @@ private void testOutputProcedureNumericInorder(String sql) throws SQLException { private void testcoerctionsOutputProcedureNumericInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2116,7 +2115,7 @@ private void createOutputProcedureBinary() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureBinary) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2133,7 +2132,7 @@ private void createOutputProcedureBinary() throws SQLException { private void testOutputProcedureBinaryInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2181,7 +2180,7 @@ private void testOutputProcedureBinaryInorder(String sql) throws SQLException { private void testOutputProcedureBinaryInorderObject(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2222,7 +2221,7 @@ private void testOutputProcedureBinaryInorderObject(String sql) throws SQLExcept private void testOutputProcedureBinaryInorderString(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2318,7 +2317,7 @@ protected static void createDateTableCallableStatement() throws SQLException { + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); @@ -2357,7 +2356,7 @@ private static void populateDateNormalCase() throws SQLException { String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -2414,7 +2413,7 @@ private void createOutputProcedureDate() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureDate) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDate); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2437,7 +2436,7 @@ private void createOutputProcedureDate() throws SQLException { private void testOutputProcedureDateInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2488,7 +2487,7 @@ private void testOutputProcedureDateInorder(String sql) throws SQLException { private void testOutputProcedureDateInorderObject(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2542,7 +2541,7 @@ private void createOutputProcedureBatch() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureBatch) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBatch); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2562,7 +2561,7 @@ private void createOutputProcedureBatch() throws SQLException { private void testOutputProcedureBatchInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2593,7 +2592,7 @@ private void createOutputProcedure4() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure4) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure4); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2616,7 +2615,7 @@ private void createMixedProcedureDateScale() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDateScale); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2635,7 +2634,7 @@ private void createMixedProcedureDateScale() throws SQLException { private void testMixedProcedureDateScaleInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2666,7 +2665,7 @@ private void testMixedProcedureDateScaleInorder(String sql) throws SQLException private void testMixedProcedureDateScaleWithParameterName(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index b9c046885..f7b77dd61 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -4,6 +4,7 @@ */ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; @@ -363,7 +364,7 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro } else { - throw new Exception(TestResource.getResource("R_resultsetNotInstance")); + fail(TestResource.getResource("R_resultsetNotInstance")); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java index 2395d59ad..ac6ccb4c5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java @@ -7,7 +7,9 @@ import java.sql.JDBCType; import java.sql.SQLException; import java.sql.ShardingKey; + import javax.sql.ConnectionPoolDataSource; + import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java index b50f5533a..48c8f1efd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java @@ -17,7 +17,6 @@ import java.util.logging.Logger; import java.util.stream.Stream; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java b/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java index 5411792a4..101cfb4b2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java @@ -11,7 +11,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java index 103e5e8eb..13c76c0f9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java @@ -9,7 +9,6 @@ import java.sql.SQLException; import java.util.UUID; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java index d121e5f05..0459e3d2d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java @@ -39,7 +39,7 @@ public class BulkCopyAllTypesTest extends AbstractTest { @Tag("xAzureSQLDW") public void testTVPResultSet() throws SQLException { if (isSqlAzureDW()) { - //TODO : Fix this test to run with Azure DW + // TODO : Fix this test to run with Azure DW testBulkCopyResultSet(false, null, null); testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } else { @@ -88,8 +88,7 @@ private void setupVariation() throws SQLException { } private void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt); TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java index d8ec1c5b2..74c673578 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java @@ -235,7 +235,7 @@ private static void createTables(Statement stmt) throws SQLException { */ @AfterAll public static void terminate() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { dropTables(stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java index 4d27f2128..8c8ea8dca 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertEquals; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -29,16 +28,17 @@ import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; + @RunWith(JUnitPlatform.class) @Tag("xAzureSQLDW") public class BulkCopyRowSetTest extends AbstractTest { - - private static String tableName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("BulkCopyFloatTest")); - + + private static String tableName = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("BulkCopyFloatTest")); + @Test public void testBulkCopyFloatRowSet() throws SQLException { - try (Connection con = DriverManager.getConnection(connectionString); - Statement stmt = connection.createStatement()) { + try (Connection con = getConnection(); Statement stmt = connection.createStatement()) { RowSetFactory rsf = RowSetProvider.newFactory(); CachedRowSet crs = rsf.createCachedRowSet(); RowSetMetaData rsmd = new RowSetMetaDataImpl(); @@ -47,32 +47,32 @@ public void testBulkCopyFloatRowSet() throws SQLException { rsmd.setColumnName(2, "c2"); rsmd.setColumnType(1, java.sql.Types.FLOAT); rsmd.setColumnType(2, java.sql.Types.FLOAT); - + Float floatData = RandomData.generateReal(false); - + crs.setMetaData(rsmd); crs.moveToInsertRow(); crs.updateFloat(1, floatData); crs.updateFloat(2, floatData); crs.insertRow(); crs.moveToCurrentRow(); - + try (SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(con)) { bcOperation.setDestinationTableName(tableName); bcOperation.writeToServer(crs); } - - ResultSet rs = stmt.executeQuery("select * from " + tableName); - rs.next(); - assertEquals(floatData, (Float) rs.getFloat(1)); - assertEquals(floatData, (Float) rs.getFloat(2)); + + try (ResultSet rs = stmt.executeQuery("select * from " + tableName)) { + rs.next(); + assertEquals(floatData, (Float) rs.getFloat(1)); + assertEquals(floatData, (Float) rs.getFloat(2)); + } } } - + @BeforeAll public static void testSetup() throws TestAbortedException, Exception { - try (Connection connection = DriverManager.getConnection(connectionString); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql1 = "create table " + tableName + " (c1 float, c2 real)"; stmt.execute(sql1); } @@ -80,8 +80,7 @@ public static void testSetup() throws TestAbortedException, Exception { @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = DriverManager.getConnection(connectionString); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(tableName, stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java index c2b690687..0cd577f9a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java @@ -232,7 +232,7 @@ public void testSendValidValueforBinaryColumnAsString() throws Exception { */ @BeforeAll public static void setupHere() throws SQLException, SecurityException, IOException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTable), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(srcTable), stmt); } @@ -245,7 +245,7 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti */ @AfterEach public void afterEachTests() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTable), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(srcTable), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java index 8a5403c9a..d7cc0883c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java @@ -74,10 +74,8 @@ public void datatypestest() throws Exception { } } } finally { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(escapedTableName, stmt); - } catch (SQLException e) { - fail(e.getMessage()); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index d4536d89f..ce0b2ef8a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -48,7 +48,7 @@ public class CallableStatementTest extends AbstractTest { @BeforeAll public static void setupTest() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(setNullProcedureName), stmt); @@ -174,7 +174,7 @@ public void inputParamsTest() throws SQLException { */ @AfterAll public static void cleanup() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(setNullProcedureName), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java index 1b3e6edd8..186da6a33 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java @@ -244,7 +244,7 @@ public void testNegativeTimeout() throws Exception { try (Connection conn = getConnection()) { try { conn.isValid(-42); - throw new Exception(TestResource.getResource("R_noExceptionNegativeTimeout")); + fail(TestResource.getResource("R_noExceptionNegativeTimeout")); } catch (SQLException e) { MessageFormat form = new MessageFormat(TestResource.getResource("R_invalidQueryTimeout")); Object[] msgArgs = {"-42"}; @@ -284,8 +284,7 @@ public void testDeadConnection() throws SQLException { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); } finally { if (null != tableName) { - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil - .getConnection(connectionString + ";responseBuffering=adaptive"); + try (Connection conn = PrepUtil.getConnection(connectionString + ";responseBuffering=adaptive"); Statement stmt = conn.createStatement()) { stmt.execute("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName)); } @@ -301,7 +300,7 @@ public void testClientConnectionId() throws Exception { try { // Call getClientConnectionId on a closed connection, should raise exception conn.getClientConnectionId(); - throw new Exception(TestResource.getResource("R_noExceptionClosedConnection")); + fail(TestResource.getResource("R_noExceptionClosedConnection")); } catch (SQLException e) { assertEquals(e.getMessage(), TestResource.getResource("R_connectionIsClosed"), TestResource.getResource("R_wrongExceptionMessage")); @@ -309,7 +308,7 @@ public void testClientConnectionId() throws Exception { } // Wrong database, ClientConnectionId should be available in error message - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection(connectionString + ";databaseName=" + try (Connection conn = PrepUtil.getConnection(connectionString + ";databaseName=" + RandomUtil.getIdentifierForDB("DataBase") + Constants.SEMI_COLON)) { conn.close(); @@ -319,7 +318,7 @@ public void testClientConnectionId() throws Exception { } // Nonexist host, ClientConnectionId should not be available in error message - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection( + try (Connection conn = PrepUtil.getConnection( connectionString + ";instanceName=" + RandomUtil.getIdentifier("Instance") + ";logintimeout=5;")) { conn.close(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java index 3434e1999..07d548ed7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java index 46d301dd9..b315a2778 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java @@ -10,7 +10,6 @@ import java.util.Arrays; import java.util.Random; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java index 762fa4afa..8c637ec42 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java @@ -236,7 +236,7 @@ private static void connect(DataSource ds) throws SQLException { */ @AfterAll public static void afterAll() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tempTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java index 27a436e71..5c33a552c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java @@ -7,12 +7,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.sql.CallableStatement; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -136,7 +138,7 @@ public void testModifiableConnectionProperties() throws SQLException { con.setCatalog("master"); } } finally { - try (SQLServerConnection con = getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropDatabaseIfExists(sCatalog2, stmt); } } @@ -149,7 +151,7 @@ public void testModifiableConnectionProperties() throws SQLException { */ @Test public void testWarnings() throws SQLException { - try (SQLServerConnection con = getConnection()) { + try (Connection con = getConnection()) { if (TestUtils.isJDBC43OrGreater(con)) { con.beginRequest(); generateWarning(con); @@ -178,7 +180,7 @@ public void testWarnings() throws SQLException { */ @Test public void testOpenTransactions() throws SQLException { - try (SQLServerConnection con = getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { if (TestUtils.isJDBC43OrGreater(con)) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col int)"); @@ -199,7 +201,7 @@ public void testOpenTransactions() throws SQLException { } } } catch (Exception e) { - e.printStackTrace(); + fail(e.getMessage()); } } @@ -210,7 +212,7 @@ public void testOpenTransactions() throws SQLException { */ @Test public void testStatements() throws SQLException { - try (SQLServerConnection con = getConnection();) { + try (Connection con = getConnection();) { if (TestUtils.isJDBC43OrGreater(con)) { try (Statement stmt1 = con.createStatement()) { con.beginRequest(); @@ -278,7 +280,7 @@ public void testStatements() throws SQLException { @Test public void testThreads() throws SQLException { class Variables { - volatile SQLServerConnection con = null; + volatile Connection con = null; volatile Statement stmt = null; volatile PreparedStatement pstmt = null; } @@ -349,8 +351,8 @@ public void run() { assertTrue(sharedVariables.pstmt.isClosed()); } } catch (InterruptedException e) { - e.printStackTrace(); Thread.currentThread().interrupt(); + fail(e.getMessage()); } finally { if (null != sharedVariables.stmt) { sharedVariables.stmt.close(); @@ -427,7 +429,7 @@ private void compareValuesAgainstConnection(SQLServerConnection con, boolean aut "useBulkCopyForBatchInsert" + description); } - private void generateWarning(SQLServerConnection con) throws SQLException { + private void generateWarning(Connection con) throws SQLException { con.setClientInfo("name", "value"); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java index caa5d9e86..83e91bc13 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java @@ -12,7 +12,6 @@ import java.sql.DatabaseMetaData; import java.text.MessageFormat; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java index f89fc6ff5..9180bd29d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java @@ -19,7 +19,6 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; @@ -105,12 +104,12 @@ public void testQueryTimeout() throws Exception { createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection( + try (Connection conn = PrepUtil.getConnection( connectionString + ";queryTimeout=" + (waitForDelaySeconds / 2) + Constants.SEMI_COLON)) { try (Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof java.sql.SQLTimeoutException)) { throw e; @@ -142,8 +141,8 @@ public void testCancelQueryTimeout() throws Exception { createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection(connectionString + ";queryTimeout=" - + (waitForDelaySeconds / 2) + ";cancelQueryTimeout=" + waitForDelaySeconds + Constants.SEMI_COLON)) { + try (Connection conn = PrepUtil.getConnection(connectionString + ";queryTimeout=" + (waitForDelaySeconds / 2) + + ";cancelQueryTimeout=" + waitForDelaySeconds + Constants.SEMI_COLON)) { try (Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); @@ -156,7 +155,7 @@ public void testCancelQueryTimeout() throws Exception { TestResource.getResource("R_invalidExceptionMessage")); } - try (SQLServerStatement stmt = (SQLServerStatement) conn.createStatement()) { + try (Statement stmt = conn.createStatement()) { stmt.execute("SELECT @@version"); } catch (Exception e) { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); @@ -179,8 +178,7 @@ public void testCancelQueryTimeoutOnStatement() throws Exception { createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil - .getConnection(connectionString + Constants.SEMI_COLON)) { + try (Connection conn = PrepUtil.getConnection(connectionString + Constants.SEMI_COLON)) { try (SQLServerStatement stmt = (SQLServerStatement) conn.createStatement()) { stmt.setQueryTimeout(waitForDelaySeconds / 2); @@ -218,12 +216,12 @@ public void testSocketTimeout() throws Exception { createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection( + try (Connection conn = PrepUtil.getConnection( connectionString + ";socketTimeout=" + (waitForDelaySeconds * 1000 / 2) + Constants.SEMI_COLON)) { try (Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { throw e; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java index b87d67670..913f95899 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.Properties; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java index bf5492eb1..5d5d56e81 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java @@ -90,8 +90,7 @@ public static void setupVariation() throws SQLException { @AfterAll public static void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java index 5a5b32dd4..1b2770b9c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java @@ -41,63 +41,60 @@ enum TestType { */ @Test public void testBigInteger() throws Exception { - try (Connection conn = getConnection()) { - try (Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - // Create the test table - TestUtils.dropTableIfExists(escapedTableName, stmt); + // Create the test table + TestUtils.dropTableIfExists(escapedTableName, stmt); - String query = "create table " + escapedTableName - + " (col1 varchar(100), col2 bigint, col3 real, col4 float, " - + "col5 numeric(38,0), col6 int, col7 smallint, col8 char(100), col9 varchar(max), " - + "id int IDENTITY primary key)"; - stmt.executeUpdate(query); - - try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + escapedTableName - + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?) SELECT * FROM " + escapedTableName + " where id = ?")) { - - /* - * test conversion of BigInteger values greater than LONG.MAX_VALUE and lesser than LONG.MIN_VALUE - */ - - // A random value that is bigger than LONG.MAX_VALUE - BigInteger bigIntPos = new BigInteger("922337203685477580776767676"); - // A random value that is smaller than LONG.MIN_VALUE - BigInteger bigIntNeg = new BigInteger("-922337203685477580776767676"); - - // Test the setObject method for different types of BigInteger values - int row = 1; - testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHTYPE); - - testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(-10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHTYPE); - - // Test setObject method with SQL TYPE parameter - testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(1000), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(-1000), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); - - // Test setNull - testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETNULL); - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(escapedTableName, stmt); - } + String query = "create table " + escapedTableName + + " (col1 varchar(100), col2 bigint, col3 real, col4 float, " + + "col5 numeric(38,0), col6 int, col7 smallint, col8 char(100), col9 varchar(max), " + + "id int IDENTITY primary key)"; + stmt.executeUpdate(query); + + try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + escapedTableName + + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?) SELECT * FROM " + escapedTableName + " where id = ?")) { + + /* + * test conversion of BigInteger values greater than LONG.MAX_VALUE and lesser than LONG.MIN_VALUE + */ + + // A random value that is bigger than LONG.MAX_VALUE + BigInteger bigIntPos = new BigInteger("922337203685477580776767676"); + // A random value that is smaller than LONG.MIN_VALUE + BigInteger bigIntNeg = new BigInteger("-922337203685477580776767676"); + + // Test the setObject method for different types of BigInteger values + int row = 1; + testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHTYPE); + + testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(-10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHTYPE); + + // Test setObject method with SQL TYPE parameter + testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(1000), row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(-1000), row++, pstmt, + TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + + // Test setNull + testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETNULL); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(escapedTableName, stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java index 92412529c..4e10c0315 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java @@ -339,7 +339,6 @@ public void bulkCopyTestDate() throws SQLException { @Test public void bulkCopyTestTwoCols() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - String col1Value = "2015-05-05"; String col2Value = "126.1230"; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -779,6 +778,7 @@ public void bulkCopyTestTime() throws SQLException { SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con); bulkCopy.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(destTableName)); bulkCopy.writeToServer(rs); + bulkCopy.close(); } try (ResultSet rs = stmt @@ -854,8 +854,7 @@ public void bulkCopyTestVarChar8000() throws SQLException { } private void beforeEachSetup(String colType, Object colValue) throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTableName), stmt); stmt.executeUpdate( @@ -874,7 +873,7 @@ private void beforeEachSetup(String colType, Object colValue) throws SQLExceptio */ @AfterAll public static void afterAll() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(tableName, stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTableName), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java index b8f86b79a..081eadb3d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java @@ -223,8 +223,7 @@ public void testSetup() throws TestAbortedException, Exception { @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = PrepUtil.getConnection(connectionString + ";sendTimeAsDatetime=false"); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java index 94b4b169f..9b27ec38d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -27,7 +27,6 @@ import com.microsoft.sqlserver.jdbc.Geography; import com.microsoft.sqlserver.jdbc.Geometry; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; @@ -315,7 +314,7 @@ public void testCurvePolygonWkt() throws SQLException { @Test @Tag("xAzureSQLDW") public void testFullGlobeWkt() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { if (isDenaliOrLater) { beforeEachSetup(); @@ -491,7 +490,7 @@ public void testAllTypes() throws SQLException { Geography geogWKT; // Geometry - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)")) { @@ -646,7 +645,7 @@ public void testMixedAllTypes() throws SQLException { Geometry geomWKT; Geography geogWKT; - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName) + " values (?, ?, ?, ?, ?)");) { @@ -787,7 +786,7 @@ public void testParse() throws SQLException { Geometry geomWKT = Geometry.parse(geoWKT); Geography geogWKT = Geography.parse(geoWKT); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -828,7 +827,7 @@ public void testPoint() throws SQLException { Geometry geomWKT = Geometry.point(1, 2, 0); Geography geogWKT = Geography.point(2, 1, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -869,7 +868,7 @@ public void testSTAsText() throws SQLException { Geometry geomWKT = Geometry.STGeomFromText(geoWKT, 0); Geography geogWKT = Geography.STGeomFromText(geoWKT, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -926,7 +925,7 @@ public void testSTAsBinary() throws SQLException { public void testCheckGeomMetaData() throws SQLException { beforeEachSetup(); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement( "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " (c1) VALUES (?)")) { ParameterMetaData paramMetaData = pstmt.getParameterMetaData(); @@ -951,7 +950,7 @@ public void testCheckGeomMetaData() throws SQLException { public void testCheckGeogMetaData() throws SQLException { beforeEachSetup(); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement( "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(geogTableName) + " (c1) VALUES (?)")) { ParameterMetaData paramMetaData = pstmt.getParameterMetaData(); @@ -1016,7 +1015,7 @@ public void testNull() throws SQLException { Geometry geomWKT; Geography geogWKT; - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName) @@ -1065,7 +1064,7 @@ public void testWrongtype() throws SQLException { Geometry geomWKT = Geometry.point(1, 2, 0); Geography geogWKT = Geography.point(2, 1, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -1102,7 +1101,7 @@ public void testWrongtype() throws SQLException { } private void beforeEachSetup() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geomTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geogTableName), stmt); stmt.executeUpdate( @@ -1113,7 +1112,7 @@ private void beforeEachSetup() throws SQLException { } private void beforeEachSetupSpatialDatatype() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName), stmt); stmt.executeUpdate("Create table " + AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName) + " (c1 geometry," + "c2 geography," + "c3 nvarchar(512)," + "c4 decimal(28,4)," + "c5 int)"); @@ -1128,7 +1127,7 @@ private void testWkt(String geoWKT, String geoWKTSS) throws SQLException { Geometry geomWKT = Geometry.STGeomFromText(geoWKT, 0); Geography geogWKT = Geography.STGeomFromText(geoWKT, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -1179,21 +1178,15 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti geogTableName = RandomUtil.getIdentifier("geographyTestTable"); spatialDatatypeTableName = RandomUtil.getIdentifier("spatialDatatypeTestTable"); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("select SERVERPROPERTY ( 'ProductVersion' )")) { - rs.next(); + int version = Integer.parseInt(rs.getString(1).substring(0, 2)); - try { - int version = Integer.parseInt(rs.getString(1).substring(0, 2)); - - // if major version is greater than or equal to 11, it's SQL Server 2012 or above. - if (version >= 11) { - isDenaliOrLater = true; - } - } catch (Exception e) { - // Do nothing. + // if major version is greater than or equal to 11, it's SQL Server 2012 or above. + if (version >= 11) { + isDenaliOrLater = true; } } } @@ -1205,7 +1198,7 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti */ @AfterAll public static void afterAll() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geomTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geogTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java index a8b3ccf2a..36d7631da 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.sql.CallableStatement; +import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -25,7 +26,6 @@ import com.microsoft.sqlserver.jdbc.RandomData; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; @@ -55,7 +55,7 @@ public class SQLVariantResultSetTest extends AbstractTest { @Test @Tag("xAzureSQLDW") public void readInt() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int value = 2; createAndPopulateTable("int", value); @@ -76,7 +76,7 @@ public void readInt() throws SQLException, SecurityException, IOException { @Test @Tag("xAzureSQLDW") public void readMoney() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { Double value = 123.12; createAndPopulateTable("Money", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -95,7 +95,7 @@ public void readMoney() throws SQLException { @Test @Tag("xAzureSQLDW") public void readSmallMoney() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { Double value = 123.12; createAndPopulateTable("smallmoney", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -114,7 +114,7 @@ public void readSmallMoney() throws SQLException { @Test @Tag("xAzureSQLDW") public void readGUID() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "1AE740A2-2272-4B0F-8086-3DDAC595BC11"; createAndPopulateTable("uniqueidentifier", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -133,7 +133,7 @@ public void readGUID() throws SQLException { @Test @Tag("xAzureSQLDW") public void readDate() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08'"; createAndPopulateTable("date", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -152,7 +152,7 @@ public void readDate() throws SQLException { @Test @Tag("xAzureSQLDW") public void readTime() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'12:26:27.123345'"; createAndPopulateTable("time(3)", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -171,7 +171,7 @@ public void readTime() throws SQLException { @Test @Tag("xAzureSQLDW") public void readDateTime() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08 12:26:24'"; createAndPopulateTable("datetime", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -190,7 +190,7 @@ public void readDateTime() throws SQLException { @Test @Tag("xAzureSQLDW") public void readSmallDateTime() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08 12:26:24'"; createAndPopulateTable("smalldatetime", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -215,7 +215,7 @@ public void readVarChar8000() throws SQLException { } String value = "'" + buffer.toString() + "'"; createAndPopulateTable("VARCHAR(8000)", value); - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName))) { rs.next(); @@ -231,7 +231,7 @@ public void readVarChar8000() throws SQLException { @Test @Tag("xAzureSQLDW") public void readFloat() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { float value = 5; createAndPopulateTable("float", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -250,7 +250,7 @@ public void readFloat() throws SQLException { @Test @Tag("xAzureSQLDW") public void readBigInt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { long value = 5; createAndPopulateTable("bigint", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -269,7 +269,7 @@ public void readBigInt() throws SQLException { @Test @Tag("xAzureSQLDW") public void readSmallInt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { short value = 5; createAndPopulateTable("smallint", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -288,7 +288,7 @@ public void readSmallInt() throws SQLException { @Test @Tag("xAzureSQLDW") public void readTinyInt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { short value = 5; createAndPopulateTable("tinyint", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -307,7 +307,7 @@ public void readTinyInt() throws SQLException { @Test @Tag("xAzureSQLDW") public void readBit() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int value = 50000; createAndPopulateTable("bit", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -326,7 +326,7 @@ public void readBit() throws SQLException { @Test @Tag("xAzureSQLDW") public void readReal() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { float value = 5; createAndPopulateTable("Real", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -345,7 +345,7 @@ public void readReal() throws SQLException { @Test @Tag("xAzureSQLDW") public void readNChar() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "a"; createAndPopulateTable("nchar(5)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -366,7 +366,7 @@ public void readNChar() throws SQLException, SecurityException, IOException { @Test @Tag("xAzureSQLDW") public void readNVarChar() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "nvarchar"; createAndPopulateTable("nvarchar(10)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -387,7 +387,7 @@ public void readNVarChar() throws SQLException, SecurityException, IOException { @Test @Tag("xAzureSQLDW") public void readBinary20() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(20)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -408,7 +408,7 @@ public void readBinary20() throws SQLException, SecurityException, IOException { @Test @Tag("xAzureSQLDW") public void readVarBinary20() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("varbinary(20)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -429,7 +429,7 @@ public void readVarBinary20() throws SQLException, SecurityException, IOExceptio @Test @Tag("xAzureSQLDW") public void readBinary512() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(512)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -450,7 +450,7 @@ public void readBinary512() throws SQLException, SecurityException, IOException @Test @Tag("xAzureSQLDW") public void readBinary8000() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(8000)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -471,7 +471,7 @@ public void readBinary8000() throws SQLException, SecurityException, IOException @Test @Tag("xAzureSQLDW") public void readvarBinary8000() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("varbinary(8000)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -492,7 +492,7 @@ public void readvarBinary8000() throws SQLException, SecurityException, IOExcept @Test @Tag("xAzureSQLDW") public void readSQLVariantProperty() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(8000)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery( @@ -517,7 +517,7 @@ public void insertVarChar8001() throws SQLException { for (int i = 0; i < 8001; i++) { buffer.append("a"); } - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -547,7 +547,7 @@ public void readNvarChar4000() throws SQLException { } String value = "'" + buffer.toString() + "'"; createAndPopulateTable("NVARCHAR(4000)", value); - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName))) { rs.next(); @@ -566,7 +566,7 @@ public void readNvarChar4000() throws SQLException { @Test @Tag("xAzureSQLDW") public void UpdateInt() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { int value = 2; int updatedValue = 3; @@ -596,7 +596,7 @@ public void UpdateInt() throws SQLException, SecurityException, IOException { @Test @Tag("xAzureSQLDW") public void UpdateNChar() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { String value = "a"; String updatedValue = "b"; @@ -628,7 +628,7 @@ public void UpdateNChar() throws SQLException, SecurityException, IOException { @Test @Tag("xAzureSQLDW") public void updateBinary20() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { String value = "hi"; String updatedValue = "bye"; @@ -657,7 +657,7 @@ public void updateBinary20() throws SQLException, SecurityException, IOException @Test @Tag("xAzureSQLDW") public void insertTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant, col2 int)"); @@ -694,7 +694,7 @@ public void insertTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void insertTestNull() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -721,7 +721,7 @@ public void insertTestNull() throws SQLException { @Test @Tag("xAzureSQLDW") public void insertSetObject() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -748,7 +748,7 @@ public void insertSetObject() throws SQLException { @Test @Tag("xAzureSQLDW") public void callableStatementOutputIntTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int value = 5; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( @@ -779,7 +779,7 @@ public void callableStatementOutputIntTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void callableStatementOutputDateTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "2015-05-08"; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -811,7 +811,7 @@ public void callableStatementOutputDateTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void callableStatementOutputTimeTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "12:26:27.123345"; String returnValue = "12:26:27"; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -843,7 +843,7 @@ public void callableStatementOutputTimeTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void callableStatementOutputBinaryTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { byte[] binary20 = RandomData.generateBinaryTypes("20", false, false); byte[] secondBinary20 = RandomData.generateBinaryTypes("20", false, false); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -880,7 +880,7 @@ public void callableStatementOutputBinaryTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void callableStatementInputOutputIntTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int col1Value = 5; int col2Value = 2; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -912,7 +912,7 @@ public void callableStatementInputOutputIntTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void callableStatementInputOutputReturnIntTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int col1Value = 5; int col2Value = 2; int returnValue = 12; @@ -947,7 +947,7 @@ public void callableStatementInputOutputReturnIntTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void callableStatementInputOutputReturnStringTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String col1Value = "aa"; String col2Value = "bb"; int returnValue = 12; @@ -984,7 +984,7 @@ public void callableStatementInputOutputReturnStringTest() throws SQLException { @Test @Tag("xAzureSQLDW") public void readSeveralRows() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { short value1 = 5; int value2 = 10; String value3 = "hi"; @@ -1012,7 +1012,7 @@ public void readSeveralRows() throws SQLException { */ @Test public void readVarcharInteger() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { Object expected[] = {"abc", 42}; int index = 0; try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -1031,7 +1031,7 @@ public void readVarcharInteger() throws SQLException { */ @Test public void testUnsupportedDatatype() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery( "select cast(cast('2017-08-16 17:31:09.995 +07:00' as datetimeoffset) as sql_variant)")) { rs.next(); @@ -1052,7 +1052,7 @@ public void testUnsupportedDatatype() throws SQLException { */ @Test public void testTimeClassAsSqlVariant() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("select cast(cast('17:31:09.995' as time(3)) as sql_variant)")) { rs.next(); @@ -1078,7 +1078,7 @@ private boolean parseByte(byte[] expectedData, byte[] retrieved) { * @throws SQLException */ private void createAndPopulateTable(String columnType, Object value) throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -1107,7 +1107,7 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti */ @AfterAll public static void afterAll() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProc), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java index 72feecbaf..150239496 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java @@ -25,34 +25,32 @@ public class SparseTest extends AbstractTest { @Test @Tag("xAzureSQLDW") public void testSparse() throws Exception { - try (Connection conn = getConnection()) { - try (Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - // Create the test table - TestUtils.dropTableIfExists(escapedTableName, stmt); + // Create the test table + TestUtils.dropTableIfExists(escapedTableName, stmt); + + StringBuilder bd = new StringBuilder(); + bd.append("create table " + escapedTableName + " (col1 int, col2 varbinary(max)"); + for (int i = 3; i <= 1024; i++) { + bd.append(", col" + i + " varchar(20) SPARSE NULL"); + } + bd.append(")"); + String query = bd.toString(); + + stmt.executeUpdate(query); - StringBuilder bd = new StringBuilder(); - bd.append("create table " + escapedTableName + " (col1 int, col2 varbinary(max)"); - for (int i = 3; i <= 1024; i++) { - bd.append(", col" + i + " varchar(20) SPARSE NULL"); - } - bd.append(")"); - String query = bd.toString(); - - stmt.executeUpdate(query); - - stmt.executeUpdate("insert into " + escapedTableName + " (col1, col2, col1023)values(1, 0x45, 'yo')"); - - try (ResultSet rs = stmt.executeQuery("Select * from " + escapedTableName)) { - rs.next(); - assertEquals("yo", rs.getString("col1023")); - assertEquals(1, rs.getInt("col1")); - assertEquals(0x45, rs.getBytes("col2")[0]); - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(escapedTableName, stmt); - } + stmt.executeUpdate("insert into " + escapedTableName + " (col1, col2, col1023)values(1, 0x45, 'yo')"); + + try (ResultSet rs = stmt.executeQuery("Select * from " + escapedTableName)) { + rs.next(); + assertEquals("yo", rs.getString("col1023")); + assertEquals(1, rs.getInt("col1")); + assertEquals(0x45, rs.getBytes("col2")[0]); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(escapedTableName, stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java index 35d6cbc34..44d423922 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java @@ -4,6 +4,7 @@ */ package com.microsoft.sqlserver.jdbc.exception; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.UnsupportedEncodingException; @@ -21,7 +22,6 @@ import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; @@ -46,9 +46,10 @@ public void testBulkCSVFileRecordExceptionCause() throws Exception { try { new SQLServerBulkCSVFileRecord(filePath + inputFile, "invalid_encoding", true); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { - throw e; + fail(e.getMessage()); } assertTrue(null != e.getCause(), TestResource.getResource("R_causeShouldNotBeNull")); @@ -70,8 +71,7 @@ public void testBulkCSVFileRecordExceptionCause() throws Exception { @Test @Tag("xAzureSQLDW") public void testSocketTimeoutExceptionCause() throws Exception { - try (SQLServerConnection conn = (SQLServerConnection) getConnection(); - Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName), stmt); createWaitForDelayPreocedure(conn); } @@ -80,10 +80,10 @@ public void testSocketTimeoutExceptionCause() throws Exception { connectionString + ";socketTimeout=" + (waitForDelaySeconds * 1000 / 2) + Constants.SEMI_COLON); Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { - throw e; + fail(e.getMessage()); } assertTrue(null != e.getCause(), TestResource.getResource("R_causeShouldNotBeNull")); @@ -93,16 +93,17 @@ public void testSocketTimeoutExceptionCause() throws Exception { } } - private void createWaitForDelayPreocedure(SQLServerConnection conn) throws SQLException { + private void createWaitForDelayPreocedure(Connection conn) throws SQLException { String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName) + " AS" + " BEGIN" + " WAITFOR DELAY '00:00:" + waitForDelaySeconds + "';" + " END"; - conn.createStatement().execute(sql); + try (Statement stmt = conn.createStatement()) { + stmt.execute(sql); + } } @AfterAll public static void cleanup() throws SQLException { - try (SQLServerConnection conn = (SQLServerConnection) getConnection(); - Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java index e27137b6e..8fe0c3906 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java @@ -11,7 +11,6 @@ import java.util.Properties; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java index 8df0c2d65..9fe67db8c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java @@ -36,14 +36,13 @@ public class ParameterMetaDataTest extends AbstractTest { @Test @Tag("xAzureSQLDW") public void testParameterMetaDataWrapper() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - + try (Statement stmt = connection.createStatement()) { stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int identity(1,1) primary key)"); try { String query = "SELECT * from " + AbstractSQLGenerator.escapeIdentifier(tableName) + " where col1 = ?"; - try (PreparedStatement pstmt = con.prepareStatement(query)) { + try (PreparedStatement pstmt = connection.prepareStatement(query)) { ParameterMetaData parameterMetaData = pstmt.getParameterMetaData(); assertTrue(parameterMetaData.isWrapperFor(ParameterMetaData.class)); assertSame(parameterMetaData, parameterMetaData.unwrap(ParameterMetaData.class)); @@ -61,9 +60,7 @@ public void testParameterMetaDataWrapper() throws SQLException { */ @Test public void testSQLServerExceptionNotWrapped() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt = connection.prepareStatement("invalid query :)");) { - + try (PreparedStatement pstmt = connection.prepareStatement("invalid query :)");) { pstmt.getParameterMetaData(); } catch (SQLException e) { assertTrue(!e.getMessage().contains("com.microsoft.sqlserver.jdbc.SQLException"), @@ -79,7 +76,7 @@ public void testSQLServerExceptionNotWrapped() throws SQLException { @Test @Tag("xAzureSQLDW") public void testNameWithBraces() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ([c1_varchar(max)] varchar(max))"); @@ -87,7 +84,7 @@ public void testNameWithBraces() throws SQLException { String query = "insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ([c1_varchar(max)]) values (?)"; - try (PreparedStatement pstmt = con.prepareStatement(query)) { + try (PreparedStatement pstmt = connection.prepareStatement(query)) { pstmt.getParameterMetaData(); } } finally { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java index 0184653b6..299a56e50 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java @@ -20,7 +20,6 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; @@ -38,15 +37,13 @@ public static void BeforeTests() throws SQLException { @AfterAll public static void dropTables() throws SQLException { - try (SQLServerConnection connection = (SQLServerConnection) getConnection(); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } private static void createCharTable() throws SQLException { - try (SQLServerConnection connection = (SQLServerConnection) getConnection(); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (c1 int)"); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java index dd8700aec..505774c98 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Field; @@ -28,8 +29,6 @@ import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import org.opentest4j.TestAbortedException; - import com.microsoft.sqlserver.jdbc.Geography; import com.microsoft.sqlserver.jdbc.Geometry; import com.microsoft.sqlserver.jdbc.RandomData; @@ -569,7 +568,7 @@ public void testIllegalNumberOfArgNoColumnList() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { assertEquals(TestResource.getResource("R_incorrectColumnNum"), e.getMessage()); } @@ -591,7 +590,7 @@ public void testIllegalNumberOfArgNoColumnList() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { if (isSqlAzureDW()) { assertEquals(TestResource.getResource("R_incorrectColumnNumInsertDW"), e.getMessage()); @@ -621,7 +620,7 @@ public void testNonParameterizedQuery() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { if (isSqlAzureDW()) { assertTrue(e.getMessage().contains(TestResource.getResource("R_incorrectSyntaxTableDW"))); @@ -645,7 +644,7 @@ public void testNonParameterizedQuery() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { assertEquals(TestResource.getResource("R_incorrectColumnNum"), e.getMessage()); } @@ -694,33 +693,29 @@ public void testNonSupportedColumns() throws Exception { } @BeforeEach - public void testSetup() throws TestAbortedException, Exception { - try (Connection connection = PrepUtil.getConnection(connectionString + ";useBulkCopyForBatchInsert=true;")) { - try (Statement stmt = (SQLServerStatement) connection.createStatement()) { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - String sql1 = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " " + "(" - + "c1 bigint, " + "c2 binary(5), " + "c3 bit, " + "c4 char, " + "c5 date, " + "c6 datetime, " - + "c7 datetime2, " + "c8 datetimeoffset, " + "c9 decimal, " + "c10 float, " + "c11 int, " - + "c12 money, " + "c13 nchar, " + "c14 numeric, " + "c15 nvarchar(20), " + "c16 real, " - + "c17 smalldatetime, " + "c18 smallint, " + "c19 smallmoney, " + "c20 time, " + "c21 tinyint, " - + "c22 varbinary(5), " + "c23 varchar(20) " + ")"; - - stmt.execute(sql1); - } + public void testSetup() throws SQLException { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + String sql1 = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " " + "(" + "c1 bigint, " + + "c2 binary(5), " + "c3 bit, " + "c4 char, " + "c5 date, " + "c6 datetime, " + "c7 datetime2, " + + "c8 datetimeoffset, " + "c9 decimal, " + "c10 float, " + "c11 int, " + "c12 money, " + + "c13 nchar, " + "c14 numeric, " + "c15 nvarchar(20), " + "c16 real, " + "c17 smalldatetime, " + + "c18 smallint, " + "c19 smallmoney, " + "c20 time, " + "c21 tinyint, " + "c22 varbinary(5), " + + "c23 varchar(20) " + ")"; + + stmt.execute(sql1); } } @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = PrepUtil.getConnection(connectionString)) { - try (Statement stmt = (SQLServerStatement) connection.createStatement()) { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameBulk), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(unsupportedTableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(squareBracketTableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(doubleQuoteTableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(schemaTableName), stmt); - } + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameBulk), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(unsupportedTableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(squareBracketTableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(doubleQuoteTableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(schemaTableName), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java index f553d3a25..e856a86e7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java @@ -10,6 +10,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Types; import org.junit.jupiter.api.AfterAll; @@ -42,8 +43,7 @@ public class BatchExecutionWithNullTest extends AbstractTest { * * @throws SQLException */ - @Test - public void testAddBatch2() throws SQLException { + public void testAddBatch2(Connection conn) throws SQLException { // try { String sPrepStmt = "insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (id, name) values (?, ?)"; @@ -51,7 +51,7 @@ public void testAddBatch2() throws SQLException { int key = 42; // this is the minimum sequence, I've found to trigger the error\ - try (Connection conn = getConnection(); PreparedStatement pstmt = conn.prepareStatement(sPrepStmt)) { + try (PreparedStatement pstmt = conn.prepareStatement(sPrepStmt)) { pstmt.setInt(1, key++); pstmt.setNull(2, Types.VARCHAR); pstmt.addBatch(); @@ -80,17 +80,16 @@ public void testAddBatch2() throws SQLException { assertTrue(updateCountlen == 5, TestResource.getResource("R_addBatchFailed")); } - String sPrepStmt1 = "select count(*) from " + AbstractSQLGenerator.escapeIdentifier(tableName); - try (PreparedStatement pstmt1 = connection.prepareStatement(sPrepStmt1); ResultSet rs = pstmt1.executeQuery()) { + String sPrepStmt1 = "select count(*) from " + AbstractSQLGenerator.escapeIdentifier(tableName); + try (PreparedStatement pstmt1 = conn.prepareStatement(sPrepStmt1); ResultSet rs = pstmt1.executeQuery()) { rs.next(); assertTrue(rs.getInt(1) == 5, TestResource.getResource("R_insertBatchFailed")); - pstmt1.close(); } } /** - * Tests the same as addBatch2, only with AE on the connection string + * Tests with AE enabled on the connection * * @throws SQLException */ @@ -98,15 +97,24 @@ public void testAddBatch2() throws SQLException { @Tag("xSQLv12") public void testAddbatch2AEOnConnection() throws SQLException { try (Connection connection = PrepUtil.getConnection(connectionString + ";columnEncryptionSetting=Enabled;")) { - testAddBatch2(); + testAddBatch2(connection); } } + /** + * Tests the same as testAddbatch2AEOnConnection, with AE disabled + * + * @throws SQLException + */ + @Test + public void testAddbatch2() throws SQLException { + testAddBatch2(getConnection()); + } + @BeforeEach @Tag("xSQLv12") public void testSetup() throws TestAbortedException, Exception { - try (Connection connection = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); String sql1 = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (id integer not null, name varchar(255), constraint " @@ -117,7 +125,7 @@ public void testSetup() throws TestAbortedException, Exception { @AfterAll public static void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); SQLServerStatement stmt = (SQLServerStatement) conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java index 538124d02..14f246d01 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java @@ -51,7 +51,7 @@ public class RegressionTest extends AbstractTest { */ @BeforeAll public static void setupTest() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } @@ -63,10 +63,9 @@ public static void setupTest() throws SQLException { */ @Test public void createViewTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create view " + AbstractSQLGenerator.escapeIdentifier(tableName) + " as select 1 a"); - PreparedStatement pstmt2 = con + try (PreparedStatement pstmt1 = connection + .prepareStatement("create view " + AbstractSQLGenerator.escapeIdentifier(tableName) + " as select 1 a"); + PreparedStatement pstmt2 = connection .prepareStatement("drop view " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -83,10 +82,9 @@ public void createViewTest() throws SQLException { */ @Test public void createSchemaTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con - .prepareStatement("create schema " + AbstractSQLGenerator.escapeIdentifier(schemaName)); - PreparedStatement pstmt2 = con + try (PreparedStatement pstmt1 = connection + .prepareStatement("create schema " + AbstractSQLGenerator.escapeIdentifier(schemaName)); + PreparedStatement pstmt2 = connection .prepareStatement("drop schema " + AbstractSQLGenerator.escapeIdentifier(schemaName))) { pstmt1.execute(); pstmt2.execute(); @@ -103,10 +101,9 @@ public void createSchemaTest() throws SQLException { */ @Test public void createTableTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); - PreparedStatement pstmt2 = con + try (PreparedStatement pstmt1 = connection + .prepareStatement("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + PreparedStatement pstmt2 = connection .prepareStatement("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -123,12 +120,11 @@ public void createTableTest() throws SQLException { */ @Test public void alterTableTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); - PreparedStatement pstmt2 = con.prepareStatement( + try (PreparedStatement pstmt1 = connection + .prepareStatement("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + PreparedStatement pstmt2 = connection.prepareStatement( "ALTER TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ADD column_name char;"); - PreparedStatement pstmt3 = con + PreparedStatement pstmt3 = connection .prepareStatement("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -146,14 +142,13 @@ public void alterTableTest() throws SQLException { */ @Test public void grantTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); - PreparedStatement pstmt2 = con.prepareStatement( + try (PreparedStatement pstmt1 = connection + .prepareStatement("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + PreparedStatement pstmt2 = connection.prepareStatement( "grant select on " + AbstractSQLGenerator.escapeIdentifier(tableName) + " to public"); - PreparedStatement pstmt3 = con.prepareStatement( + PreparedStatement pstmt3 = connection.prepareStatement( "revoke select on " + AbstractSQLGenerator.escapeIdentifier(tableName) + " from public"); - PreparedStatement pstmt4 = con + PreparedStatement pstmt4 = connection .prepareStatement("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -372,8 +367,7 @@ public void addBatchWithLargeStringTest() throws SQLException { @Test public void testQueryParamsWithHyphen() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("SELECT 1 WHERE -1=-1 AND 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("SELECT 1 WHERE -1=-1 AND 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) @@ -384,8 +378,7 @@ public void testQueryParamsWithHyphen() throws Exception { @Test public void testQueryParamsWithComment() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("/**COMMENT**/ SELECT 1 WHERE 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("/**COMMENT**/ SELECT 1 WHERE 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) @@ -396,8 +389,7 @@ public void testQueryParamsWithComment() throws Exception { @Test public void testQueryParamsWithLineComment() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("--comment\nSELECT 1 WHERE 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("--comment\nSELECT 1 WHERE 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) @@ -408,8 +400,7 @@ public void testQueryParamsWithLineComment() throws Exception { @Test public void testQueryParamsWithBackSlash() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("SELECT 1, '/''' AS str WHERE 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("SELECT 1, '/''' AS str WHERE 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) { @@ -427,7 +418,7 @@ public void testQueryParamsWithBackSlash() throws Exception { */ @AfterAll public static void cleanup() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName2), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java index cda6339cd..796cbcb7f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java @@ -37,7 +37,7 @@ public class DataClassificationTest extends AbstractTest { @Test public void testDataClassificationMetadata() throws Exception { // Run this test only with newer SQL Servers (version>=2018) that support Data Classification - try (Connection con = getConnection(); Statement stmt = connection.createStatement();) { + try (Statement stmt = connection.createStatement();) { if (TestUtils.serverSupportsDataClassification(stmt)) { createTable(connection, stmt); runTestsForServer(stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java index 12b98a278..4064ad1d1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java @@ -11,12 +11,10 @@ import java.sql.Connection; import java.sql.SQLException; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -47,7 +45,7 @@ public void testWithPermissiveX509TrustManager() throws Exception { public void testWithTrustManagerConstructorArg() throws Exception { String url = connectionString + ";trustManagerClass=" + TrustManagerWithConstructorArg.class.getName() + ";trustManagerConstructorArg=dummyString;" + ";encrypt=true;"; - try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(url)) { + try (Connection con = PrepUtil.getConnection(url)) { assertTrue(con != null); } } @@ -60,7 +58,7 @@ public void testWithTrustManagerConstructorArg() throws Exception { @Test public void testWithInvalidTrustManager() throws Exception { String url = connectionString + ";trustManagerClass=" + InvalidTrustManager.class.getName() + ";encrypt=true;"; - try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(url)) { + try (Connection con = PrepUtil.getConnection(url)) { fail(); } catch (SQLException e) { assertTrue(e.getMessage().contains( diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java index 9c9a07041..2d644e0f5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java @@ -214,7 +214,7 @@ private void setupVariation(boolean setSelectMethod, Statement stmt) throws SQLE } private void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt); TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt); TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java index 29f6e38c0..d4cc1f6cd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java @@ -4,11 +4,13 @@ */ package com.microsoft.sqlserver.jdbc.tvp; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -58,7 +60,7 @@ public void tryTVPRSvarcharMax4000Issue() throws Exception { pstmt.setStructured(1, tvp_varcharMax, rs); pstmt.execute(); - testCharDestTable(); + testCharDestTable(st); } } @@ -69,22 +71,22 @@ public void tryTVPRSvarcharMax4000Issue() throws Exception { */ @Test public void testExceptionWithInvalidStoredProcedureName() throws Exception { - SQLServerStatement st = (SQLServerStatement) connection.createStatement(); - ResultSet rs = st.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable_varcharMax)); - - dropProcedure(); - - final String sql = "{call " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + "(?)}"; - - try (SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connection.prepareCall(sql)) { - Cstmt.setObject(1, rs); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); - } catch (Exception e) { - if (e instanceof SQLException) { - assertTrue(e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound")), - TestResource.getResource("R_invalidErrorMessage") + e.getMessage()); - } else { - throw e; + try (Statement stmt = connection.createStatement(); ResultSet rs = stmt + .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable_varcharMax))) { + + dropProcedure(stmt); + String sql = "{call " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + "(?)}"; + + try (SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connection.prepareCall(sql)) { + Cstmt.setObject(1, rs); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); + } catch (Exception e) { + if (e instanceof SQLException) { + assertTrue(e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound")), + TestResource.getResource("R_invalidErrorMessage") + e.getMessage()); + } else { + fail(e.getMessage()); + } } } } @@ -106,12 +108,12 @@ public void tryTVPPrecisionmissedissue315() throws Exception { pstmt.setStructured(1, tvp_time_6, rs); pstmt.execute(); - testTime6DestTable(); + testTime6DestTable(stmt); } } - private void testCharDestTable() throws SQLException, IOException { - try (ResultSet rs = connection.createStatement() + private void testCharDestTable(Statement stmt) throws SQLException, IOException { + try (ResultSet rs = stmt .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(desTable_varcharMax))) { while (rs.next()) { assertEquals(rs.getString(1).length(), 4001, TestResource.getResource("R_lengthTruncated")); @@ -119,8 +121,8 @@ private void testCharDestTable() throws SQLException, IOException { } } - private void testTime6DestTable() throws SQLException, IOException { - try (ResultSet rs = connection.createStatement() + private void testTime6DestTable(Statement stmt) throws SQLException, IOException { + try (ResultSet rs = stmt .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(desTable_time_6))) { while (rs.next()) { assertEquals(rs.getString(1), expectedTime6value, TestResource.getResource("R_timeValueTruncated")); @@ -132,7 +134,7 @@ private void testTime6DestTable() throws SQLException, IOException { public static void beforeAll() throws SQLException { try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - dropProcedure(); + dropProcedure(stmt); stmt.executeUpdate("IF EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name = '" + TestUtils.escapeSingleQuotes(tvp_varcharMax) + "') " + " drop type " @@ -166,10 +168,10 @@ public static void beforeAll() throws SQLException { + " as table (c1 time(6) null)"; stmt.executeUpdate(TVPCreateCmd); - createProcedure(); + createProcedure(stmt); populateCharSrcTable(); - populateTime6SrcTable(); + populateTime6SrcTable(stmt); } } @@ -182,42 +184,35 @@ private static void populateCharSrcTable() throws SQLException { } String value = sb.toString(); - try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement(sql)) { - + try (PreparedStatement pstmt = connection.prepareStatement(sql)) { pstmt.setString(1, value); pstmt.execute(); } } - private static void populateTime6SrcTable() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(srcTable_time_6) - + " values ('2017-05-12 " + expectedTime6value + "')"; - connection.createStatement().execute(sql); - } + private static void populateTime6SrcTable(Statement stmt) throws SQLException { + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(srcTable_time_6) + " values ('2017-05-12 " + + expectedTime6value + "')"; + stmt.execute(sql); } - private static void dropProcedure() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(spName_varcharMax), stmt); - } + private static void dropProcedure(Statement stmt) throws SQLException { + TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(spName_varcharMax), stmt); } - private static void createProcedure() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + " @InputData " - + AbstractSQLGenerator.escapeIdentifier(tvp_varcharMax) + " READONLY " + " AS " + " BEGIN " - + " INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable_varcharMax) - + " SELECT * FROM @InputData" + " END"; + private static void createProcedure(Statement stmt) throws SQLException { + String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + " @InputData " + + AbstractSQLGenerator.escapeIdentifier(tvp_varcharMax) + " READONLY " + " AS " + " BEGIN " + + " INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable_varcharMax) + + " SELECT * FROM @InputData" + " END"; - stmt.execute(sql); - } + stmt.execute(sql); } @AfterAll public static void terminateVariation() throws SQLException { - dropProcedure(); - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { + dropProcedure(stmt); stmt.executeUpdate("IF EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name = '" + TestUtils.escapeSingleQuotes(tvp_varcharMax) + "') " + " drop type " + AbstractSQLGenerator.escapeIdentifier(tvp_varcharMax)); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java index a2d822d50..b3979c2bd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java @@ -4,6 +4,7 @@ */ package com.microsoft.sqlserver.jdbc.tvp; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; @@ -82,7 +83,6 @@ private void serverCursorsTest(int resultSetType, int resultSetConcurrency) thro "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable) + " select * from ? ;")) { pstmt.setStructured(1, AbstractSQLGenerator.escapeIdentifier(tvpName), rs); pstmt.execute(); - verifyDestinationTableData(expectedBigDecimals.length); } } @@ -115,7 +115,6 @@ public void testSelectMethodSetToCursor() throws SQLException { "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable) + " select * from ? ;")) { pstmt.setStructured(1, AbstractSQLGenerator.escapeIdentifier(tvpName), rs); pstmt.execute(); - verifyDestinationTableData(expectedBigDecimals.length); } } @@ -149,9 +148,7 @@ public void testSelectMethodSetToCursorWithSP() throws SQLException { SQLServerCallableStatement pstmt = (SQLServerCallableStatement) conn .prepareCall("{call " + AbstractSQLGenerator.escapeIdentifier(procedureName) + "(?)}")) { pstmt.setStructured(1, AbstractSQLGenerator.escapeIdentifier(tvpName), rs); - pstmt.execute(); - verifyDestinationTableData(expectedBigDecimals.length); } finally { dropProcedure(); @@ -190,7 +187,7 @@ public void testInvalidTVPName() throws SQLException { pstmt.execute(); } catch (SQLException e) { if (!e.getMessage().contains(TestResource.getResource("R_dataTypeNotFound"))) { - throw e; + fail(e.getMessage()); } } } @@ -223,14 +220,12 @@ public void testInvalidStoredProcedureName() throws SQLException { SQLServerCallableStatement pstmt = (SQLServerCallableStatement) conn.prepareCall( "{call invalid" + AbstractSQLGenerator.escapeIdentifier(procedureName) + "(?)}")) { pstmt.setStructured(1, tvpName, rs); - pstmt.execute(); } catch (SQLException e) { if (!e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound"))) { - throw e; + fail(e.getMessage()); } } finally { - dropProcedure(); } } @@ -352,14 +347,14 @@ private static void populateSourceTable() throws SQLException { } private static void dropTables() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(srcTable), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(desTable), stmt); } } private static void createTables() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(srcTable) + " (c1 decimal(10,5) null, c2 nchar(50) null, c3 datetime2(7) null, c4 char(7000), id int not null identity);"; stmt.execute(sql); @@ -371,7 +366,7 @@ private static void createTables() throws SQLException { } private static void createTVPS() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { String TVPCreateCmd = "CREATE TYPE " + AbstractSQLGenerator.escapeIdentifier(tvpName) + " as table (c1 decimal(10,5) null, c2 nchar(50) null, c3 datetime2(7) null, c4 char(7000) null)"; stmt.execute(TVPCreateCmd); @@ -379,7 +374,7 @@ private static void createTVPS() throws SQLException { } private static void dropTVPS() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.execute("IF EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name = '" + TestUtils.escapeSingleQuotes(tvpName) + "') " + " drop type " + AbstractSQLGenerator.escapeIdentifier(tvpName)); @@ -387,13 +382,13 @@ private static void dropTVPS() throws SQLException { } private static void dropProcedure() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt); } } private static void createProcedure() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procedureName) + " @InputData " + AbstractSQLGenerator.escapeIdentifier(tvpName) + " READONLY " + " AS " + " BEGIN " + " INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java index a0fc79845..8bbde8bc4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java @@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.charset.StandardCharsets; -import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -39,7 +38,6 @@ @Tag("xSQLv12") @Tag("xSQLv13") public class UTF8SupportTest extends AbstractTest { - private static Connection connection; private static String databaseName; private static String tableName; @@ -112,7 +110,6 @@ public void testVarchar() throws SQLException { @BeforeAll public static void setUp() throws ClassNotFoundException, SQLException { - connection = PrepUtil.getConnection(getConnectionString()); if (TestUtils.serverSupportsUTF8(connection)) { databaseName = RandomUtil.getIdentifier("UTF8Database"); tableName = RandomUtil.getIdentifier("UTF8Table"); @@ -128,9 +125,6 @@ public static void cleanUp() throws SQLException { TestUtils.dropDatabaseIfExists(databaseName, stmt); } } - if (null != connection) { - connection.close(); - } } private static void createDatabaseWithUTF8Collation() throws SQLException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java index 16c86afa1..c7e39b78d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java @@ -126,141 +126,133 @@ public void testLengthAfterStream() throws SQLException, IOException { @Test @DisplayName("testClobsVarcharASCII") public void testClobsVarcharASCII() throws SQLException { - try (Connection conn = getConnection()) { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - createLobTable(stmt, tableName, Constants.LOB.CLOB); - ArrayList lob_data = createRandomStringArray(Constants.LOB.CLOB); - insertData(conn, tableName, lob_data); + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + createLobTable(stmt, tableName, Constants.LOB.CLOB); + ArrayList lob_data = createRandomStringArray(Constants.LOB.CLOB); + insertData(conn, tableName, lob_data); - ArrayList lobsFromServer = new ArrayList<>(); - try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { - while (rs.next()) { - int index = rs.getInt(1); - Clob c = rs.getClob(2); - assertEquals(c.length(), lob_data.get(index).length()); - lobsFromServer.add(c); - String received = getStringFromInputStream(c.getAsciiStream());// streaming string - assertEquals(lob_data.get(index), received);// compare streamed string to initial string - } - } - for (int i = 0; i < lob_data.size(); i++) { - String received = getStringFromInputStream(lobsFromServer.get(i).getAsciiStream());// non-streaming - // string - assertEquals(received, lob_data.get(i));// compare static string to streamed string - } - for (Clob c : lobsFromServer) { - c.free(); - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); + ArrayList lobsFromServer = new ArrayList<>(); + try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { + while (rs.next()) { + int index = rs.getInt(1); + Clob c = rs.getClob(2); + assertEquals(c.length(), lob_data.get(index).length()); + lobsFromServer.add(c); + String received = getStringFromInputStream(c.getAsciiStream());// streaming string + assertEquals(lob_data.get(index), received);// compare streamed string to initial string } } + for (int i = 0; i < lob_data.size(); i++) { + String received = getStringFromInputStream(lobsFromServer.get(i).getAsciiStream());// non-streaming + // string + assertEquals(received, lob_data.get(i));// compare static string to streamed string + } + for (Clob c : lobsFromServer) { + c.free(); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + } } } @Test @DisplayName("testNClobsNVarcharASCII") public void testNClobsVarcharASCII() throws SQLException, IOException { - try (Connection conn = getConnection()) { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - createLobTable(stmt, tableName, Constants.LOB.NCLOB); - // Testing AsciiStream, use Clob string set or characters will be converted to '?' - ArrayList lob_data = createRandomStringArray(Constants.LOB.CLOB); - insertData(conn, tableName, lob_data); + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + createLobTable(stmt, tableName, Constants.LOB.NCLOB); + // Testing AsciiStream, use Clob string set or characters will be converted to '?' + ArrayList lob_data = createRandomStringArray(Constants.LOB.CLOB); + insertData(conn, tableName, lob_data); - try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { - while (rs.next()) { - int index = rs.getInt(1); - NClob c = rs.getNClob(2); - assertEquals(c.length(), lob_data.get(index).length()); - String received = getStringFromInputStream(c.getAsciiStream());// NClob AsciiStream is never - // streamed - c.free(); - assertEquals(lob_data.get(index), received);// compare string to initial string - } - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); + try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { + while (rs.next()) { + int index = rs.getInt(1); + NClob c = rs.getNClob(2); + assertEquals(c.length(), lob_data.get(index).length()); + String received = getStringFromInputStream(c.getAsciiStream());// NClob AsciiStream is never + // streamed + c.free(); + assertEquals(lob_data.get(index), received);// compare string to initial string } } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + } } } @Test @DisplayName("testClobsVarcharCHARA") public void testClobsVarcharCHARA() throws SQLException, IOException { - try (Connection conn = getConnection()) { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - createLobTable(stmt, tableName, Constants.LOB.CLOB); - ArrayList lob_data = createRandomStringArray(Constants.LOB.CLOB); - insertData(conn, tableName, lob_data); + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + createLobTable(stmt, tableName, Constants.LOB.CLOB); + ArrayList lob_data = createRandomStringArray(Constants.LOB.CLOB); + insertData(conn, tableName, lob_data); - ArrayList lobsFromServer = new ArrayList<>(); - try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { - while (rs.next()) { - int index = rs.getInt(1); - Clob c = rs.getClob(2); - assertEquals(c.length(), lob_data.get(index).length()); - lobsFromServer.add(c); - String received = getStringFromReader(c.getCharacterStream(), c.length());// streaming string - assertEquals(lob_data.get(index), received);// compare streamed string to initial string - } - } - for (int i = 0; i < lob_data.size(); i++) { - String received = getStringFromReader(lobsFromServer.get(i).getCharacterStream(), - lobsFromServer.get(i).length());// non-streaming string - assertEquals(received, lob_data.get(i));// compare static string to streamed string - } - for (Clob c : lobsFromServer) { - c.free(); - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); + ArrayList lobsFromServer = new ArrayList<>(); + try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { + while (rs.next()) { + int index = rs.getInt(1); + Clob c = rs.getClob(2); + assertEquals(c.length(), lob_data.get(index).length()); + lobsFromServer.add(c); + String received = getStringFromReader(c.getCharacterStream(), c.length());// streaming string + assertEquals(lob_data.get(index), received);// compare streamed string to initial string } } + for (int i = 0; i < lob_data.size(); i++) { + String received = getStringFromReader(lobsFromServer.get(i).getCharacterStream(), + lobsFromServer.get(i).length());// non-streaming string + assertEquals(received, lob_data.get(i));// compare static string to streamed string + } + for (Clob c : lobsFromServer) { + c.free(); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + } } } @Test @DisplayName("testNClobsVarcharCHARA") public void testNClobsVarcharCHARA() throws SQLException, IOException { - try (Connection conn = getConnection()) { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - createLobTable(stmt, tableName, Constants.LOB.NCLOB); - ArrayList lob_data = createRandomStringArray(Constants.LOB.NCLOB); - insertData(conn, tableName, lob_data); + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + createLobTable(stmt, tableName, Constants.LOB.NCLOB); + ArrayList lob_data = createRandomStringArray(Constants.LOB.NCLOB); + insertData(conn, tableName, lob_data); - ArrayList lobsFromServer = new ArrayList<>(); - try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { - while (rs.next()) { - int index = rs.getInt(1); - NClob c = rs.getNClob(2); - assertEquals(c.length(), lob_data.get(index).length()); - lobsFromServer.add(c); - String received = getStringFromReader(c.getCharacterStream(), c.length());// streaming string - assertEquals(lob_data.get(index), received);// compare streamed string to initial string - } - } - for (int i = 0; i < lob_data.size(); i++) { - String received = getStringFromReader(lobsFromServer.get(i).getCharacterStream(), - lobsFromServer.get(i).length());// non-streaming string - assertEquals(received, lob_data.get(i));// compare static string to streamed string - } - for (Clob c : lobsFromServer) { - c.free(); - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); + ArrayList lobsFromServer = new ArrayList<>(); + try (ResultSet rs = stmt.executeQuery("SELECT * FROM [" + tableName + "] ORDER BY id ASC")) { + while (rs.next()) { + int index = rs.getInt(1); + NClob c = rs.getNClob(2); + assertEquals(c.length(), lob_data.get(index).length()); + lobsFromServer.add(c); + String received = getStringFromReader(c.getCharacterStream(), c.length());// streaming string + assertEquals(lob_data.get(index), received);// compare streamed string to initial string } } + for (int i = 0; i < lob_data.size(); i++) { + String received = getStringFromReader(lobsFromServer.get(i).getCharacterStream(), + lobsFromServer.get(i).length());// non-streaming string + assertEquals(received, lob_data.get(i));// compare static string to streamed string + } + for (Clob c : lobsFromServer) { + c.free(); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + } } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java index 9bec966d6..5fc2bf469 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java @@ -239,8 +239,7 @@ public static void testSetup() throws TestAbortedException, Exception { } private static void dropTable() throws SQLException { - try (Connection connection = PrepUtil.getConnection(connectionString + ";columnEncryptionSetting=Enabled;"); - Statement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(ctstable2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(ctstable1), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java index 5645ccd0e..4a136593c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java @@ -48,7 +48,7 @@ public class BatchTriggerTest extends AbstractTest { */ @Test public void statementTest() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.addBatch(insertQuery); stmt.executeBatch(); fail(TestResource.getResource("R_expectedExceptionNotThrown")); @@ -64,14 +64,11 @@ public void statementTest() throws SQLException { */ @Test public void preparedStatementTest() throws SQLException { - try (Connection connection = getConnection(); - PreparedStatement pstmt = connection.prepareStatement(insertQuery)) { - + try (PreparedStatement pstmt = connection.prepareStatement(insertQuery)) { pstmt.addBatch(); pstmt.executeBatch(); fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { - assertTrue(e.getMessage().equalsIgnoreCase(TestResource.getResource("R_customErrorMessage"))); } } @@ -83,7 +80,7 @@ public void preparedStatementTest() throws SQLException { * @throws SQLException */ private static void createTrigger(String triggerName) throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql = "create trigger " + triggerName + " on " + AbstractSQLGenerator.escapeIdentifier(tableName) + " for insert " + "as " + "begin " + "if (select col1 from " + AbstractSQLGenerator.escapeIdentifier(tableName) + ") > 10 " + "begin " + "return " + "end " @@ -98,12 +95,10 @@ private static void createTrigger(String triggerName) throws SQLException { * * @throws SQLException */ - private static void createTable() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " ( col1 int, col2 varchar(50), col3 varchar(10), col4 int)"; - stmt.execute(sql); - } + private static void createTable(Statement stmt) throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " ( col1 int, col2 varchar(50), col3 varchar(10), col4 int)"; + stmt.execute(sql); } /** @@ -119,11 +114,10 @@ public static void testSetup() throws TestAbortedException, Exception { insertQuery = "insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1, col2, col3, col4) values (1, '22-08-2017 17:30:00.000', 'R4760', 31)"; - try (Connection connection = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTriggerIfExists(triggerName, stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - createTable(); + createTable(stmt); createTrigger(AbstractSQLGenerator.escapeIdentifier(triggerName)); } } @@ -135,8 +129,7 @@ public static void testSetup() throws TestAbortedException, Exception { */ @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.execute("IF EXISTS (\r\n" + " SELECT *\r\n" + " FROM sys.objects\r\n" + " WHERE [type] = 'TR' AND [name] = '" + TestUtils.escapeSingleQuotes(triggerName) + "'\r\n" diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java index d2df80af6..2e5c8147f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java @@ -12,7 +12,6 @@ import java.sql.SQLException; import java.sql.Statement; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -42,8 +41,7 @@ public class CallableMixedTest extends AbstractTest { */ @Test public void datatypesTest() throws SQLException { - try (Connection connection = getConnection(); Statement statement = connection.createStatement();) { - + try (Statement statement = connection.createStatement();) { statement.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (c1_int int primary key, col2 int)"); statement diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java index ffba0d520..f126c4e54 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java @@ -15,6 +15,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import java.util.Vector; import java.util.logging.Logger; @@ -891,8 +892,8 @@ public void verifyOffsetException() throws Exception { */ @BeforeAll public static void beforeAll() { - try (Connection conn = getConnection()) { - createAndPopulateTables(conn); + try { + createAndPopulateTables(connection); } catch (Exception e) { fail(e.getMessage()); } @@ -904,15 +905,13 @@ public static void beforeAll() { * @throws Exception */ @AfterAll - public static void afterAll() throws Exception { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + public static void afterAll() throws SQLException { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table4), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); - } catch (Exception ex) { - fail(ex.toString()); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java index 939edecfe..2e402e832 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java @@ -5,14 +5,11 @@ package com.microsoft.sqlserver.jdbc.unit.statement; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -import java.sql.Connection; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -91,15 +88,10 @@ public void runTest() throws Exception { * @throws Exception */ @AfterAll - public static void afterAll() throws Exception { - - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeams), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeamsUpdated), stmt); - } catch (Exception ex) { - fail(ex.toString()); - } + public static void afterAll() throws SQLException { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeams), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeamsUpdated), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java index 8e5ea2eff..4d62e92ad 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java @@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import java.sql.Connection; import java.sql.ParameterMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -23,7 +24,6 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; @@ -41,7 +41,7 @@ public class PQImpsTest extends AbstractTest { private static final int SQL_SERVER_2012_VERSION = 11; - private static SQLServerConnection connection = null; + private static Connection connection = null; private static Statement stmt = null; private static PreparedStatement pstmt = null; private static ResultSet rs = null; @@ -66,7 +66,7 @@ public class PQImpsTest extends AbstractTest { */ @BeforeAll public static void BeforeTests() throws SQLException { - connection = (SQLServerConnection) getConnection(); + connection = getConnection(); stmt = connection.createStatement(); version = getSQLServerVersion(); createMultipleTypesTable(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java index bd44ef196..ced1473e1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java @@ -15,7 +15,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java index 96fa9ea2c..4e567d18d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java @@ -21,7 +21,6 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; @@ -43,7 +42,7 @@ public class RegressionTest extends AbstractTest { */ @Test public void testServerCursorPStmt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { // expected values int numRowsInResult = 1; @@ -109,7 +108,7 @@ public void testServerCursorPStmt() throws SQLException { */ @Test public void testSelectIntoUpdateCount() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection()) { + try (Connection con = getConnection()) { // Azure does not do SELECT INTO if (!isSqlAzure()) { @@ -148,7 +147,7 @@ public void testSelectIntoUpdateCount() throws SQLException { */ @Test public void testUpdateQuery() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String sql; JDBCType[] targets = {JDBCType.INTEGER, JDBCType.SMALLINT}; int rows = 3; @@ -242,7 +241,7 @@ private void createTable(Statement stmt) throws SQLException { @AfterAll public static void terminate() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index 32641b4c4..d314e8675 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -89,7 +89,7 @@ public void init() throws Exception { @AfterEach public void terminate() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } @@ -926,7 +926,7 @@ public void testCloseOnCompletion() throws Exception { * @throws Exception */ @Test - public void testConsecutiveQueries() throws Exception { + public void testConsecutiveQueries() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { // enable isCloseOnCompletion try { @@ -935,12 +935,8 @@ public void testConsecutiveQueries() throws Exception { throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1Name), stmt); - } catch (SQLException e) {} - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); - } catch (SQLException e) {} + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1Name), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(table1Name) + " (col1 INT)"); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(table2Name) + " (col1 INT)"); @@ -1509,14 +1505,10 @@ public void testRowError() throws Exception { } @AfterEach - public void terminate() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); - } catch (SQLException e) { - fail(e.getMessage()); - } + public void terminate() throws SQLException { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); } } } @@ -2169,15 +2161,11 @@ public void testStatementInsertExecInsert() throws Exception { } @AfterEach - public void terminate() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement();) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(sprocName), stmt); - } catch (SQLException e) { - fail(e.getMessage()); - } + public void terminate() throws SQLException { + try (Statement stmt = connection.createStatement();) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); + TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(sprocName), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java index 94a851ac2..92d324b66 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java @@ -13,7 +13,6 @@ import java.sql.Statement; import java.text.MessageFormat; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -119,7 +118,7 @@ public void wrapTest() throws Exception { */ @Test public void unWrapFailureTest() throws Exception { - try (Connection con = getConnection(); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String str = "java.lang.String"; boolean isWrapper = stmt.isWrapperFor(Class.forName(str)); stmt.unwrap(Class.forName(str)); diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 6c77881c7..5b5b20f4f 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -9,7 +9,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.FileHandler; import java.util.logging.Handler; @@ -57,7 +56,6 @@ public abstract class AbstractTest { protected static Connection connectionAzure = null; protected static String connectionString = null; - protected static Properties info = new Properties(); private static boolean _determinedSqlAzureOrSqlServer = false; private static boolean _isSqlAzure = false; @@ -76,28 +74,16 @@ public static void setup() throws Exception { applicationClientID = getConfiguredProperty("applicationClientID"); applicationKey = getConfiguredProperty("applicationKey"); keyIDs = getConfiguredProperty("keyID", "").split(Constants.SEMI_COLON); - connectionString = getConfiguredProperty(Constants.MSSQL_JDBC_TEST_CONNECTION_PROPERTIES); + ds = updateDataSource(new SQLServerDataSource()); dsXA = updateDataSource(new SQLServerXADataSource()); dsPool = updateDataSource(new SQLServerConnectionPoolDataSource()); - jksPaths = getConfiguredProperty("jksPaths", "").split(Constants.SEMI_COLON); - javaKeyAliases = getConfiguredProperty("javaKeyAliases", "").split(Constants.SEMI_COLON); - windowsKeyPath = getConfiguredProperty("windowsKeyPath"); - - // info.setProperty("ColumnEncryptionSetting", "Enabled"); // May be we - // can use parameterized way to change this value - if (!jksPaths[0].isEmpty()) { - info.setProperty("keyStoreAuthentication", Constants.JAVA_KEY_STORE_PASSWORD); - info.setProperty("keyStoreLocation", jksPaths[0]); - info.setProperty("keyStoreSecret", Constants.JKS_SECRET_STRING); - } - try { Assertions.assertNotNull(connectionString, TestResource.getResource("R_ConnectionStringNull")); Class.forName(Constants.MSSQL_JDBC_PACKAGE + ".SQLServerDriver"); - connection = PrepUtil.getConnection(connectionString, info); + connection = getConnection(); isSqlAzureOrAzureDW(connection); } catch (Exception e) { throw e; @@ -220,8 +206,6 @@ public static void teardown() throws Exception { if (connection != null && !connection.isClosed()) { connection.close(); } - } catch (Exception e) { - connection.close(); } finally { connection = null; } diff --git a/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java b/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java index ef779e597..ce270e3d3 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java @@ -252,7 +252,7 @@ public double getServerVersion() throws Exception { serverversion = 16; } } catch (Exception e) { - throw new Exception("Unable to get dbms major version", e); + fail("Unable to get dbms major version", e); } } return serverversion; From 58a53c87d8fa40cb67ad075202d068cfdbe19d4a Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Wed, 3 Apr 2019 11:04:10 -0700 Subject: [PATCH 10/12] Fix tests --- .../sqlserver/jdbc/unit/lobs/LobsTest.java | 14 +++++++++----- .../sqlserver/testframework/AbstractTest.java | 13 ++++++------- .../testframework/DBInvalidUtil.java | 19 +++++++++---------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java index e674ae177..35c8e9bef 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java @@ -81,7 +81,7 @@ public static void init() throws SQLException { @TestFactory public Collection executeDynamicTests() { List> classes = new ArrayList>( - Arrays.asList(Blob.class, Clob.class, DBBinaryStream.class, DBCharacterStream.class)); + Arrays.asList(Blob.class, Clob.class, NClob.class, DBBinaryStream.class, DBCharacterStream.class)); List isResultSetTypes = new ArrayList<>(Arrays.asList(true, false)); Collection dynamicTests = new ArrayList<>(); @@ -163,7 +163,7 @@ private void testInvalidLobs(Class lobClass, boolean isResultSet) throws SQLE } catch (SQLException e) { boolean verified = false; - if (lobClass == Clob.class) + if (lobClass == Clob.class || lobClass == NClob.class) streamLength = ((DBInvalidUtil.InvalidClob) lob).length; else if (lobClass == Blob.class) streamLength = ((DBInvalidUtil.InvalidBlob) lob).length; @@ -180,8 +180,8 @@ else if (lobClass == Blob.class) } // Case 2: CharacterStream or Clob.getCharacterStream threw IOException - if (lobClass == DBCharacterStream.class - || (lobClass == Clob.class && ((DBInvalidUtil.InvalidClob) lob).stream != null)) { + if (lobClass == DBCharacterStream.class || ((lobClass == Clob.class || lobClass == NClob.class) + && ((DBInvalidUtil.InvalidClob) lob).stream != null)) { try (DBInvalidUtil.InvalidCharacterStream stream = lobClass == DBCharacterStream.class ? ((DBInvalidUtil.InvalidCharacterStream) lob) : ((DBInvalidUtil.InvalidClob) lob).stream) { if (stream.threwException) { @@ -670,6 +670,8 @@ else if (lob instanceof DBBinaryStream) ps.setBinaryStream(index, (InputStream) lob, length); else if (lob instanceof Clob) ps.setClob(index, (Clob) lob); + else if (lob instanceof NClob) + ps.setNClob(index, (NClob) lob); else ps.setBlob(index, (Blob) lob); assertEquals(ps.executeUpdate(), 1, TestResource.getResource("R_incorrectUpdateCount")); @@ -682,6 +684,8 @@ private void updateResultSet(ResultSet rs, Object lob, int index, int length) th rs.updateBinaryStream(index, (InputStream) lob, length); } else if (lob instanceof Clob) { rs.updateClob(index, (Clob) lob); + } else if (lob instanceof NClob) { + rs.updateNClob(index, (NClob) lob); } else { rs.updateBlob(index, (Blob) lob); } @@ -703,7 +707,7 @@ private Object createLob(Class lobClass) { return new DBInvalidUtil().new InvalidCharacterStream(new String(data), streamLength < -1); else if (lobClass == DBBinaryStream.class) return new DBInvalidUtil().new InvalidBinaryStream(data, streamLength < -1); - if (lobClass == Clob.class) { + if (lobClass == Clob.class || lobClass == NClob.class) { SqlType type = TestUtils.find(String.class); Object expected = type.createdata(String.class, data); return new DBInvalidUtil().new InvalidClob(expected, false); diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 5b5b20f4f..0e60ce231 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -83,7 +83,11 @@ public static void setup() throws Exception { try { Assertions.assertNotNull(connectionString, TestResource.getResource("R_ConnectionStringNull")); Class.forName(Constants.MSSQL_JDBC_PACKAGE + ".SQLServerDriver"); - connection = getConnection(); + if (!SQLServerDriver.isRegistered()) + SQLServerDriver.register(); + if (null == connection || connection.isClosed()) { + connection = getConnection(); + } isSqlAzureOrAzureDW(connection); } catch (Exception e) { throw e; @@ -203,7 +207,7 @@ protected static SQLServerConnection getConnection() throws SQLException { @AfterAll public static void teardown() throws Exception { try { - if (connection != null && !connection.isClosed()) { + if (null != connection && !connection.isClosed()) { connection.close(); } } finally { @@ -211,11 +215,6 @@ public static void teardown() throws Exception { } } - @BeforeAll - public static void registerDriver() throws Exception { - SQLServerDriver.register(); - } - /** * Read variable from property files if found null try to read from env. * diff --git a/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java b/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java index 21afe445f..fd1ea5868 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java @@ -15,7 +15,6 @@ import java.sql.Blob; import java.sql.Clob; import java.sql.SQLException; -import java.util.concurrent.ThreadLocalRandom; import java.util.logging.Logger; import com.microsoft.sqlserver.jdbc.TestUtils.DBBinaryStream; @@ -67,8 +66,8 @@ public long length() throws SQLException { long ret = actualLength; long actual = ret; if (invalidLength == -1) { - int choose = ThreadLocalRandom.current().nextInt(5); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(5); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // more than ret @@ -189,8 +188,8 @@ public int read(char[] cbuf, int off, int len) throws IOException { int ret = super.read(cbuf, off, len); int actual = ret; if (!returnValid) { - int choose = ThreadLocalRandom.current().nextInt(5); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(5); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // more than ret @@ -247,8 +246,8 @@ public long length() throws SQLException { long ret = actualLength; long actual = ret; if (invalidLength == -1) { - int choose = ThreadLocalRandom.current().nextInt(5); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(5); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // more than ret @@ -342,7 +341,7 @@ public InputStream getBinaryStream(long pos, long length) throws SQLException { */ public class InvalidBinaryStream extends DBBinaryStream { final int diff = 5; - private boolean _returnValid = false; // Perfom invalid actions at most once + private boolean _returnValid = false; // Perform invalid actions at most once /** * Constructor @@ -360,8 +359,8 @@ public int read(byte[] bytes, int off, int len) { int ret = super.read(bytes, off, len); int actual = ret; if (!_returnValid) { - int choose = ThreadLocalRandom.current().nextInt(4); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(4); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // greater than ret actual = ret + randomInt; From 57effee80206df9719ffacb161a28efe2cfe953b Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 5 Apr 2019 14:46:09 -0700 Subject: [PATCH 11/12] Fix conflict issues --- .../jdbc/unit/lobs/LobsStreamingTest.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java index 99e87e3db..6cb71ed7c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java @@ -164,18 +164,6 @@ public void testClobsVarcharASCII() throws SQLException, IOException { TestUtils.dropTableIfExists(tableName, stmt); } } - for (int i = 0; i < lob_data.size(); i++) { - String received = getStringFromInputStream(lobsFromServer.get(i).getAsciiStream());// non-streaming - // string - assertEquals(received, lob_data.get(i));// compare static string to streamed string - } - for (Clob c : lobsFromServer) { - c.free(); - } - } finally { - try (Statement stmt = connection.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - } } } @@ -254,18 +242,6 @@ public void testClobsVarcharCHARA() throws SQLException, IOException { TestUtils.dropTableIfExists(tableName, stmt); } } - for (int i = 0; i < lob_data.size(); i++) { - String received = getStringFromReader(lobsFromServer.get(i).getCharacterStream(), - lobsFromServer.get(i).length());// non-streaming string - assertEquals(received, lob_data.get(i));// compare static string to streamed string - } - for (Clob c : lobsFromServer) { - c.free(); - } - } finally { - try (Statement stmt = connection.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - } } } @@ -304,18 +280,6 @@ public void testNClobsVarcharCHARA() throws SQLException, IOException { TestUtils.dropTableIfExists(tableName, stmt); } } - for (int i = 0; i < lob_data.size(); i++) { - String received = getStringFromReader(lobsFromServer.get(i).getCharacterStream(), - lobsFromServer.get(i).length());// non-streaming string - assertEquals(received, lob_data.get(i));// compare static string to streamed string - } - for (Clob c : lobsFromServer) { - c.free(); - } - } finally { - try (Statement stmt = connection.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - } } } } From 8d295755176b3bcf531aaf3422f34a07bd18206e Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 5 Apr 2019 14:50:18 -0700 Subject: [PATCH 12/12] Conflict changes reverted --- .../microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java index 6cb71ed7c..d4d8e52ae 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java @@ -200,10 +200,6 @@ public void testNClobsVarcharASCII() throws SQLException, IOException { TestUtils.dropTableIfExists(tableName, stmt); } } - } finally { - try (Statement stmt = connection.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - } } }