From 58f07eff1d4357fbb643b85211fb99e309f347ad Mon Sep 17 00:00:00 2001 From: susanh Date: Wed, 16 May 2018 18:02:19 -0400 Subject: [PATCH 1/8] resource bundle for junit test error strings --- .gitattributes | 33 -- .../jdbc/AlwaysEncrypted/AESetup.java | 5 +- .../CallableStatementTest.java | 380 +++++++++--------- .../JDBCEncryptionDecryptionTest.java | 55 ++- .../AlwaysEncrypted/PrecisionScaleTest.java | 22 +- .../microsoft/sqlserver/jdbc/JDBC43Test.java | 30 +- .../sqlserver/jdbc/TestResource.java | 171 ++++++++ .../bulkCopy/BulkCopyColumnMappingTest.java | 10 +- .../jdbc/bulkCopy/BulkCopyConnectionTest.java | 4 +- .../jdbc/bulkCopy/BulkCopyTestUtil.java | 7 +- .../ISQLServerBulkRecordIssuesTest.java | 21 +- .../microsoft/sqlserver/jdbc/bvt/bvtTest.java | 19 +- .../CallableStatementTest.java | 12 +- .../jdbc/connection/ConnectionDriverTest.java | 122 +++--- .../connection/NativeMSSQLDataSourceTest.java | 3 +- .../jdbc/connection/PoolingTest.java | 13 +- .../jdbc/connection/SSLProtocolTest.java | 15 +- .../jdbc/connection/TimeoutTest.java | 35 +- .../jdbc/connection/WarningTest.java | 7 +- .../DatabaseMetaDataForeignKeyTest.java | 21 +- .../DatabaseMetaDataTest.java | 122 +++--- .../SQLServerSpatialDatatypeTest.java | 18 +- .../datatypes/SQLVariantResultSetTest.java | 3 +- .../jdbc/datatypes/TVPWithSqlVariantTest.java | 6 +- .../jdbc/exception/ExceptionTest.java | 16 +- .../sqlserver/jdbc/fips/FipsEnvTest.java | 22 +- .../sqlserver/jdbc/fips/FipsTest.java | 26 +- .../BatchExecutionWithNullTest.java | 9 +- .../preparedStatement/RegressionTest.java | 13 +- .../sqlserver/jdbc/tvp/TVPIssuesTest.java | 10 +- .../jdbc/tvp/TVPResultSetCursorTest.java | 7 +- .../sqlserver/jdbc/tvp/TVPSchemaTest.java | 15 +- .../sqlserver/jdbc/unit/TestSavepoint.java | 29 +- .../sqlserver/jdbc/unit/lobs/lobsTest.java | 22 +- .../statement/BatchExecuteWithErrorsTest.java | 60 +-- .../unit/statement/BatchExecutionTest.java | 29 +- .../jdbc/unit/statement/BatchTriggerTest.java | 14 +- .../unit/statement/CallableMixedTest.java | 13 +- .../jdbc/unit/statement/LimitEscapeTest.java | 15 +- .../jdbc/unit/statement/MergeTest.java | 3 +- .../statement/NamedParamMultiPartTest.java | 13 +- .../jdbc/unit/statement/PQImpsTest.java | 39 +- .../jdbc/unit/statement/PoolableTest.java | 13 +- .../unit/statement/PreparedStatementTest.java | 5 +- .../jdbc/unit/statement/RegressionTest.java | 11 +- .../statement/StatementCancellationTest.java | 10 +- .../jdbc/unit/statement/StatementTest.java | 201 +++++---- .../jdbc/unit/statement/WrapperTest.java | 31 +- 48 files changed, 1008 insertions(+), 752 deletions(-) delete mode 100644 .gitattributes create mode 100644 src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index eb5d74682..000000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# -# The above will handle all files NOT found below -# -# These files are text and should be normalized (Convert crlf => lf) -*.css text -*.md text -*.htm text -*.html text -*.java text -*.js text -*.json text -*.properties text -*.sh text -*.svg text -*.txt text -*.xml text - -# These files are binary and should be left untouched -# (binary is a macro for -text -diff) -*.class binary -*.dll binary -*.ear binary -*.gif binary -*.ico binary -*.jar binary -*.jpg binary -*.jpeg binary -*.png binary -*.so binary -*.war binary 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 0c31108ac..72a8b2417 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -34,6 +34,7 @@ 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.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.Utils; @@ -87,7 +88,7 @@ public class AESetup extends AbstractTest { @BeforeAll static void setUpConnection() throws TestAbortedException, Exception { assumeTrue(13 <= new DBConnection(connectionString).getServerVersion(), - "Aborting test case as SQL Server version is not compatible with Always encrypted "); + TestResource.getResource("R_Incompat_SQLServerVersion")); String AETestConenctionString = connectionString + ";sendTimeAsDateTime=false"; readFromFile(javaKeyStoreInputFile, "Alias name"); @@ -140,7 +141,7 @@ private static void readFromFile(String inputFile, filePath = Utils.getCurrentClassPath(); try { File f = new File(filePath + inputFile); - assumeTrue(f.exists(), "Aborting test case since no java key store and alias name exists!"); + assumeTrue(f.exists(), "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 bc0c8f173..84b0e20cf 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -28,6 +28,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.Utils; import com.microsoft.sqlserver.testframework.util.RandomData; import com.microsoft.sqlserver.testframework.util.Util; @@ -696,7 +697,7 @@ private void testInputProcedure(String sql, try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) { rs.next(); - assertEquals(rs.getString(1), values[3], "" + "Test for input parameter fails.\n"); + assertEquals(rs.getString(1), values[3], "" + TestResource.getResource("R_inputParamFailed")); } } catch (Exception e) { @@ -734,14 +735,14 @@ private void testInputProcedure2(String sql) throws SQLException { try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) { rs.next(); - assertEquals(rs.getString(1).trim(), charValues[1], "Test for input parameter fails.\n"); - assertEquals(rs.getUniqueIdentifier(2), charValues[6].toUpperCase(), "Test for input parameter fails.\n"); - assertEquals(rs.getString(3).trim(), charValues[2], "Test for input parameter fails.\n"); - assertEquals(rs.getString(4).trim(), charValues[3], "Test for input parameter fails.\n"); - assertEquals(rs.getString(5).trim(), charValues[4], "Test for input parameter fails.\n"); - assertEquals(rs.getString(6).trim(), charValues[5], "Test for input parameter fails.\n"); - assertEquals(rs.getString(7).trim(), charValues[7], "Test for input parameter fails.\n"); - assertEquals(rs.getString(8).trim(), charValues[8], "Test for input parameter fails.\n"); + assertEquals(rs.getString(1).trim(), charValues[1], TestResource.getResource("R_inputParamFailed")); + assertEquals(rs.getUniqueIdentifier(2), charValues[6].toUpperCase(), TestResource.getResource("R_inputParamFailed")); + assertEquals(rs.getString(3).trim(), charValues[2], TestResource.getResource("R_inputParamFailed")); + assertEquals(rs.getString(4).trim(), charValues[3], TestResource.getResource("R_inputParamFailed")); + assertEquals(rs.getString(5).trim(), charValues[4], TestResource.getResource("R_inputParamFailed")); + assertEquals(rs.getString(6).trim(), charValues[5], TestResource.getResource("R_inputParamFailed")); + assertEquals(rs.getString(7).trim(), charValues[7], TestResource.getResource("R_inputParamFailed")); + assertEquals(rs.getString(8).trim(), charValues[8], TestResource.getResource("R_inputParamFailed")); } } catch (Exception e) { @@ -770,19 +771,19 @@ private void testOutputProcedure3RandomOrder(String sql) throws SQLException { callableStatement.execute(); int intValue2 = callableStatement.getInt(2); - assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed")); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed")); int intValue3 = callableStatement.getInt(2); - assertEquals("" + intValue3, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue3, numericValues[3], TestResource.getResource("R_outputParamFailed")); int intValue4 = callableStatement.getInt(2); - assertEquals("" + intValue4, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue4, numericValues[3], TestResource.getResource("R_outputParamFailed")); int intValue5 = callableStatement.getInt(1); - assertEquals("" + intValue5, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue5, numericValues[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -799,10 +800,10 @@ private void testOutputProcedure3Inorder(String sql) throws SQLException { callableStatement.execute(); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed")); int intValue2 = callableStatement.getInt(2); - assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -819,10 +820,10 @@ private void testOutputProcedure3ReverseOrder(String sql) throws SQLException { callableStatement.execute(); int intValue2 = callableStatement.getInt(2); - assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed")); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -863,34 +864,34 @@ private void testOutputProcedure2RandomOrder(String sql, callableStatement.execute(); BigDecimal ecnryptedSmallMoney = callableStatement.getSmallMoney(7); - assertEquals("" + ecnryptedSmallMoney, values[12], "Test for output parameter fails.\n"); + assertEquals("" + ecnryptedSmallMoney, values[12], TestResource.getResource("R_outputParamFailed")); short encryptedSmallint = callableStatement.getShort(4); - assertEquals("" + encryptedSmallint, values[2], "Test for output parameter fails.\n"); + assertEquals("" + encryptedSmallint, values[2], TestResource.getResource("R_outputParamFailed")); BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8); - assertEquals("" + SmallMoneyValue, values[12], "Test for output parameter fails.\n"); + assertEquals("" + SmallMoneyValue, values[12], TestResource.getResource("R_outputParamFailed")); short encryptedTinyint = callableStatement.getShort(6); - assertEquals("" + encryptedTinyint, values[1], "Test for output parameter fails.\n"); + assertEquals("" + encryptedTinyint, values[1], TestResource.getResource("R_outputParamFailed")); short tinyintValue = callableStatement.getShort(5); - assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed")); BigDecimal encryptedMoneyValue = callableStatement.getMoney(9); - assertEquals("" + encryptedMoneyValue, values[13], "Test for output parameter fails.\n"); + assertEquals("" + encryptedMoneyValue, values[13], TestResource.getResource("R_outputParamFailed")); short smallintValue = callableStatement.getShort(3); - assertEquals("" + smallintValue, values[2], "Test for output parameter fails.\n"); + assertEquals("" + smallintValue, values[2], TestResource.getResource("R_outputParamFailed")); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, values[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, values[3], TestResource.getResource("R_outputParamFailed")); BigDecimal encryptedSmallMoney = callableStatement.getMoney(10); - assertEquals("" + encryptedSmallMoney, values[13], "Test for output parameter fails.\n"); + assertEquals("" + encryptedSmallMoney, values[13], TestResource.getResource("R_outputParamFailed")); int encryptedInt = callableStatement.getInt(2); - assertEquals("" + encryptedInt, values[3], "Test for output parameter fails.\n"); + assertEquals("" + encryptedInt, values[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -915,34 +916,34 @@ private void testOutputProcedure2Inorder(String sql, callableStatement.execute(); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, values[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, values[3], TestResource.getResource("R_outputParamFailed")); int encryptedInt = callableStatement.getInt(2); - assertEquals("" + encryptedInt, values[3], "Test for output parameter fails.\n"); + assertEquals("" + encryptedInt, values[3], TestResource.getResource("R_outputParamFailed")); short smallintValue = callableStatement.getShort(3); - assertEquals("" + smallintValue, values[2], "Test for output parameter fails.\n"); + assertEquals("" + smallintValue, values[2], TestResource.getResource("R_outputParamFailed")); short encryptedSmallint = callableStatement.getShort(4); - assertEquals("" + encryptedSmallint, values[2], "Test for output parameter fails.\n"); + assertEquals("" + encryptedSmallint, values[2], TestResource.getResource("R_outputParamFailed")); short tinyintValue = callableStatement.getShort(5); - assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed")); short encryptedTinyint = callableStatement.getShort(6); - assertEquals("" + encryptedTinyint, values[1], "Test for output parameter fails.\n"); + assertEquals("" + encryptedTinyint, values[1], TestResource.getResource("R_outputParamFailed")); BigDecimal encryptedSmallMoney = callableStatement.getSmallMoney(7); - assertEquals("" + encryptedSmallMoney, values[12], "Test for output parameter fails.\n"); + assertEquals("" + encryptedSmallMoney, values[12], TestResource.getResource("R_outputParamFailed")); BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8); - assertEquals("" + SmallMoneyValue, values[12], "Test for output parameter fails.\n"); + assertEquals("" + SmallMoneyValue, values[12], TestResource.getResource("R_outputParamFailed")); BigDecimal MoneyValue = callableStatement.getMoney(9); - assertEquals("" + MoneyValue, values[13], "Test for output parameter fails.\n"); + assertEquals("" + MoneyValue, values[13], TestResource.getResource("R_outputParamFailed")); BigDecimal encryptedMoney = callableStatement.getMoney(10); - assertEquals("" + encryptedMoney, values[13], "Test for output parameter fails.\n"); + assertEquals("" + encryptedMoney, values[13], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -969,34 +970,33 @@ private void testOutputProcedure2ReverseOrder(String sql, callableStatement.execute(); BigDecimal encryptedMoney = callableStatement.getMoney(10); - assertEquals("" + encryptedMoney, values[13], "Test for output parameter fails.\n"); + assertEquals("" + encryptedMoney, values[13], TestResource.getResource("R_outputParamFailed")); BigDecimal MoneyValue = callableStatement.getMoney(9); - assertEquals("" + MoneyValue, values[13], "Test for output parameter fails.\n"); + assertEquals("" + MoneyValue, values[13], TestResource.getResource("R_outputParamFailed")); BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8); - assertEquals("" + SmallMoneyValue, values[12], "Test for output parameter fails.\n"); + assertEquals("" + SmallMoneyValue, values[12], TestResource.getResource("R_outputParamFailed")); BigDecimal encryptedSmallMoney = callableStatement.getSmallMoney(7); - assertEquals("" + encryptedSmallMoney, values[12], "Test for output parameter fails.\n"); + assertEquals("" + encryptedSmallMoney, values[12], TestResource.getResource("R_outputParamFailed")); short encryptedTinyint = callableStatement.getShort(6); - assertEquals("" + encryptedTinyint, values[1], "Test for output parameter fails.\n"); short tinyintValue = callableStatement.getShort(5); - assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed")); short encryptedSmallint = callableStatement.getShort(4); - assertEquals("" + encryptedSmallint, values[2], "Test for output parameter fails.\n"); + assertEquals("" + encryptedSmallint, values[2], TestResource.getResource("R_outputParamFailed")); short smallintValue = callableStatement.getShort(3); - assertEquals("" + smallintValue, values[2], "Test for output parameter fails.\n"); + assertEquals("" + smallintValue, values[2], TestResource.getResource("R_outputParamFailed")); int encryptedInt = callableStatement.getInt(2); - assertEquals("" + encryptedInt, values[3], "Test for output parameter fails.\n"); + assertEquals("" + encryptedInt, values[3], TestResource.getResource("R_outputParamFailed")); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, values[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, values[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1033,33 +1033,33 @@ private void testOutputProcedureRandomOrder(String sql, callableStatement.execute(); double floatValue0 = callableStatement.getDouble(2); - assertEquals("" + floatValue0, "" + values[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue0, "" + values[5], TestResource.getResource("R_outputParamFailed")); long bigintValue = callableStatement.getLong(4); - assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue, values[4], TestResource.getResource("R_outputParamFailed")); short tinyintValue = callableStatement.getShort(5); // tinyint - assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed")); double floatValue1 = callableStatement.getDouble(2); - assertEquals("" + floatValue1, "" + values[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue1, "" + values[5], TestResource.getResource("R_outputParamFailed")); int intValue2 = callableStatement.getInt(1); - assertEquals("" + intValue2, "" + values[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, "" + values[3], TestResource.getResource("R_outputParamFailed")); double floatValue2 = callableStatement.getDouble(2); - assertEquals("" + floatValue2, "" + values[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue2, "" + values[5], TestResource.getResource("R_outputParamFailed")); short shortValue3 = callableStatement.getShort(3); // smallint - assertEquals("" + shortValue3, "" + values[2], "Test for output parameter fails.\n"); + assertEquals("" + shortValue3, "" + values[2], TestResource.getResource("R_outputParamFailed")); short shortValue32 = callableStatement.getShort(3); - assertEquals("" + shortValue32, "" + values[2], "Test for output parameter fails.\n"); + assertEquals("" + shortValue32, "" + values[2], TestResource.getResource("R_outputParamFailed")); BigDecimal smallmoney1 = callableStatement.getSmallMoney(6); - assertEquals("" + smallmoney1, "" + values[12], "Test for output parameter fails.\n"); + assertEquals("" + smallmoney1, "" + values[12], TestResource.getResource("R_outputParamFailed")); BigDecimal money1 = callableStatement.getMoney(7); - assertEquals("" + money1, "" + values[13], "Test for output parameter fails.\n"); + assertEquals("" + money1, "" + values[13], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -1082,25 +1082,25 @@ private void testOutputProcedureInorder(String sql, callableStatement.execute(); int intValue2 = callableStatement.getInt(1); - assertEquals("" + intValue2, values[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, values[3], TestResource.getResource("R_outputParamFailed")); double floatValue0 = callableStatement.getDouble(2); - assertEquals("" + floatValue0, values[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue0, values[5], TestResource.getResource("R_outputParamFailed")); short shortValue3 = callableStatement.getShort(3); - assertEquals("" + shortValue3, values[2], "Test for output parameter fails.\n"); + assertEquals("" + shortValue3, values[2], TestResource.getResource("R_outputParamFailed")); long bigintValue = callableStatement.getLong(4); - assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue, values[4], TestResource.getResource("R_outputParamFailed")); short tinyintValue = callableStatement.getShort(5); - assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed")); BigDecimal smallMoney1 = callableStatement.getSmallMoney(6); - assertEquals("" + smallMoney1, values[12], "Test for output parameter fails.\n"); + assertEquals("" + smallMoney1, values[12], TestResource.getResource("R_outputParamFailed")); BigDecimal money1 = callableStatement.getMoney(7); - assertEquals("" + money1, values[13], "Test for output parameter fails.\n"); + assertEquals("" + money1, values[13], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1123,25 +1123,25 @@ private void testOutputProcedureReverseOrder(String sql, callableStatement.execute(); BigDecimal smallMoney1 = callableStatement.getSmallMoney(6); - assertEquals("" + smallMoney1, values[12], "Test for output parameter fails.\n"); + assertEquals("" + smallMoney1, values[12], TestResource.getResource("R_outputParamFailed")); BigDecimal money1 = callableStatement.getMoney(7); - assertEquals("" + money1, values[13], "Test for output parameter fails.\n"); + assertEquals("" + money1, values[13], TestResource.getResource("R_outputParamFailed")); short tinyintValue = callableStatement.getShort(5); - assertEquals("" + tinyintValue, values[1], "Test for output parameter fails.\n"); + assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed")); long bigintValue = callableStatement.getLong(4); - assertEquals("" + bigintValue, values[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue, values[4], TestResource.getResource("R_outputParamFailed")); short shortValue3 = callableStatement.getShort(3); - assertEquals("" + shortValue3, values[2], "Test for output parameter fails.\n"); + assertEquals("" + shortValue3, values[2], TestResource.getResource("R_outputParamFailed")); double floatValue0 = callableStatement.getDouble(2); - assertEquals("" + floatValue0, values[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue0, values[5], TestResource.getResource("R_outputParamFailed")); int intValue2 = callableStatement.getInt(1); - assertEquals("" + intValue2, values[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, values[3], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1207,7 +1207,7 @@ private void testMixedProcedure(String sql) throws SQLException { assertEquals("" + intValue, numericValues[3], "Test for Inout parameter fails.\n"); double floatValue = callableStatement.getDouble(3); - assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); int returnedValue = callableStatement.getInt(1); assertEquals("" + returnedValue, "" + 123, "Test for Inout parameter fails.\n"); @@ -1240,22 +1240,22 @@ private void testMixedProcedure2RandomOrder(String sql) throws SQLException { callableStatement.execute(); double floatValue = callableStatement.getDouble(2); - assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed")); double floatValue2 = callableStatement.getDouble(2); - assertEquals("" + floatValue2, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue2, numericValues[5], TestResource.getResource("R_outputParamFailed")); int intValue2 = callableStatement.getInt(1); - assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed")); int intValue3 = callableStatement.getInt(1); - assertEquals("" + intValue3, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue3, numericValues[3], TestResource.getResource("R_outputParamFailed")); double floatValue3 = callableStatement.getDouble(2); - assertEquals("" + floatValue3, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue3, numericValues[5], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1274,10 +1274,10 @@ private void testMixedProcedure2Inorder(String sql) throws SQLException { callableStatement.execute(); int intValue = callableStatement.getInt(1); - assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed")); double floatValue = callableStatement.getDouble(2); - assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -1306,22 +1306,22 @@ private void testMixedProcedure3RandomOrder(String sql) throws SQLException { callableStatement.execute(); double floatValue = callableStatement.getDouble(2); - assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); long bigintValue = callableStatement.getLong(1); - assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue, numericValues[4], TestResource.getResource("R_outputParamFailed")); long bigintValue1 = callableStatement.getLong(1); - assertEquals("" + bigintValue1, numericValues[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue1, numericValues[4], TestResource.getResource("R_outputParamFailed")); double floatValue2 = callableStatement.getDouble(2); - assertEquals("" + floatValue2, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue2, numericValues[5], TestResource.getResource("R_outputParamFailed")); double floatValue3 = callableStatement.getDouble(2); - assertEquals("" + floatValue3, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue3, numericValues[5], TestResource.getResource("R_outputParamFailed")); long bigintValue3 = callableStatement.getLong(1); - assertEquals("" + bigintValue3, numericValues[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue3, numericValues[4], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1340,10 +1340,10 @@ private void testMixedProcedure3Inorder(String sql) throws SQLException { callableStatement.execute(); long bigintValue = callableStatement.getLong(1); - assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue, numericValues[4], TestResource.getResource("R_outputParamFailed")); double floatValue = callableStatement.getDouble(2); - assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -1361,10 +1361,10 @@ private void testMixedProcedure3ReverseOrder(String sql) throws SQLException { callableStatement.execute(); double floatValue = callableStatement.getDouble(2); - assertEquals("" + floatValue, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue, numericValues[5], TestResource.getResource("R_outputParamFailed")); long bigintValue = callableStatement.getLong(1); - assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue, numericValues[4], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -1474,31 +1474,31 @@ private void testOutputProcedureCharInorder(String sql) throws SQLException { callableStatement.execute(); String charValue = callableStatement.getString(1).trim(); - assertEquals(charValue, charValues[0], "Test for output parameter fails.\n"); + assertEquals(charValue, charValues[0], TestResource.getResource("R_outputParamFailed")); String varcharValue = callableStatement.getString(2).trim(); - assertEquals(varcharValue, charValues[1], "Test for output parameter fails.\n"); + assertEquals(varcharValue, charValues[1], TestResource.getResource("R_outputParamFailed")); String ncharValue = callableStatement.getString(3).trim(); - assertEquals(ncharValue, charValues[3], "Test for output parameter fails.\n"); + assertEquals(ncharValue, charValues[3], TestResource.getResource("R_outputParamFailed")); String nvarcharValue = callableStatement.getString(4).trim(); - assertEquals(nvarcharValue, charValues[4], "Test for output parameter fails.\n"); + assertEquals(nvarcharValue, charValues[4], TestResource.getResource("R_outputParamFailed")); String uniqueIdentifierValue = callableStatement.getString(5).trim(); - assertEquals(uniqueIdentifierValue.toLowerCase(), charValues[6], "Test for output parameter fails.\n"); + assertEquals(uniqueIdentifierValue.toLowerCase(), charValues[6], TestResource.getResource("R_outputParamFailed")); String varcharValuemax = callableStatement.getString(6).trim(); - assertEquals(varcharValuemax, charValues[2], "Test for output parameter fails.\n"); + assertEquals(varcharValuemax, charValues[2], TestResource.getResource("R_outputParamFailed")); String nvarcharValuemax = callableStatement.getString(7).trim(); - assertEquals(nvarcharValuemax, charValues[5], "Test for output parameter fails.\n"); + assertEquals(nvarcharValuemax, charValues[5], TestResource.getResource("R_outputParamFailed")); String varcharValue8000 = callableStatement.getString(8).trim(); - assertEquals(varcharValue8000, charValues[7], "Test for output parameter fails.\n"); + assertEquals(varcharValue8000, charValues[7], TestResource.getResource("R_outputParamFailed")); String nvarcharValue4000 = callableStatement.getNString(9).trim(); - assertEquals(nvarcharValue4000, charValues[8], "Test for output parameter fails.\n"); + assertEquals(nvarcharValue4000, charValues[8], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1522,33 +1522,33 @@ private void testOutputProcedureCharInorderObject(String sql) throws SQLExceptio callableStatement.execute(); String charValue = (String) callableStatement.getObject(1); - assertEquals(charValue.trim(), charValues[0], "Test for output parameter fails.\n"); + assertEquals(charValue.trim(), charValues[0], TestResource.getResource("R_outputParamFailed")); String varcharValue = (String) callableStatement.getObject(2); - assertEquals(varcharValue.trim(), charValues[1], "Test for output parameter fails.\n"); + assertEquals(varcharValue.trim(), charValues[1], TestResource.getResource("R_outputParamFailed")); String ncharValue = (String) callableStatement.getObject(3); - assertEquals(ncharValue.trim(), charValues[3], "Test for output parameter fails.\n"); + assertEquals(ncharValue.trim(), charValues[3], TestResource.getResource("R_outputParamFailed")); String nvarcharValue = (String) callableStatement.getObject(4); - assertEquals(nvarcharValue.trim(), charValues[4], "Test for output parameter fails.\n"); + assertEquals(nvarcharValue.trim(), charValues[4], TestResource.getResource("R_outputParamFailed")); String uniqueIdentifierValue = (String) callableStatement.getObject(5); - assertEquals(uniqueIdentifierValue.toLowerCase(), charValues[6], "Test for output parameter fails.\n"); + assertEquals(uniqueIdentifierValue.toLowerCase(), charValues[6], TestResource.getResource("R_outputParamFailed")); String varcharValuemax = (String) callableStatement.getObject(6); - assertEquals(varcharValuemax, charValues[2], "Test for output parameter fails.\n"); + assertEquals(varcharValuemax, charValues[2], TestResource.getResource("R_outputParamFailed")); String nvarcharValuemax = (String) callableStatement.getObject(7); - assertEquals(nvarcharValuemax.trim(), charValues[5], "Test for output parameter fails.\n"); + assertEquals(nvarcharValuemax.trim(), charValues[5], TestResource.getResource("R_outputParamFailed")); String varcharValue8000 = (String) callableStatement.getObject(8); - assertEquals(varcharValue8000, charValues[7], "Test for output parameter fails.\n"); + assertEquals(varcharValue8000, charValues[7], TestResource.getResource("R_outputParamFailed")); String nvarcharValue4000 = (String) callableStatement.getObject(9); - assertEquals(nvarcharValue4000, charValues[8], "Test for output parameter fails.\n"); + assertEquals(nvarcharValue4000, charValues[8], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1597,54 +1597,54 @@ private void testOutputProcedureNumericInorder(String sql) throws SQLException { int bitValue = callableStatement.getInt(1); if (bitValue == 0) - assertEquals("" + false, numericValues[0], "Test for output parameter fails.\n"); + assertEquals("" + false, numericValues[0], TestResource.getResource("R_outputParamFailed")); else - assertEquals("" + true, numericValues[0], "Test for output parameter fails.\n"); + assertEquals("" + true, numericValues[0], TestResource.getResource("R_outputParamFailed")); short tinyIntValue = callableStatement.getShort(2); - assertEquals("" + tinyIntValue, numericValues[1], "Test for output parameter fails.\n"); + assertEquals("" + tinyIntValue, numericValues[1], TestResource.getResource("R_outputParamFailed")); short smallIntValue = callableStatement.getShort(3); - assertEquals("" + smallIntValue, numericValues[2], "Test for output parameter fails.\n"); + assertEquals("" + smallIntValue, numericValues[2], TestResource.getResource("R_outputParamFailed")); int intValue = callableStatement.getInt(4); - assertEquals("" + intValue, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed")); long bigintValue = callableStatement.getLong(5); - assertEquals("" + bigintValue, numericValues[4], "Test for output parameter fails.\n"); + assertEquals("" + bigintValue, numericValues[4], TestResource.getResource("R_outputParamFailed")); double floatDefault = callableStatement.getDouble(6); - assertEquals("" + floatDefault, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatDefault, numericValues[5], TestResource.getResource("R_outputParamFailed")); double floatValue = callableStatement.getDouble(7); - assertEquals("" + floatValue, numericValues[6], "Test for output parameter fails.\n"); + assertEquals("" + floatValue, numericValues[6], TestResource.getResource("R_outputParamFailed")); float realValue = callableStatement.getFloat(8); - assertEquals("" + realValue, numericValues[7], "Test for output parameter fails.\n"); + assertEquals("" + realValue, numericValues[7], TestResource.getResource("R_outputParamFailed")); BigDecimal decimalDefault = callableStatement.getBigDecimal(9); - assertEquals(decimalDefault, new BigDecimal(numericValues[8]), "Test for output parameter fails.\n"); + assertEquals(decimalDefault, new BigDecimal(numericValues[8]), TestResource.getResource("R_outputParamFailed")); BigDecimal decimalValue = callableStatement.getBigDecimal(10); - assertEquals(decimalValue, new BigDecimal(numericValues[9]), "Test for output parameter fails.\n"); + assertEquals(decimalValue, new BigDecimal(numericValues[9]), TestResource.getResource("R_outputParamFailed")); BigDecimal numericDefault = callableStatement.getBigDecimal(11); - assertEquals(numericDefault, new BigDecimal(numericValues[10]), "Test for output parameter fails.\n"); + assertEquals(numericDefault, new BigDecimal(numericValues[10]), TestResource.getResource("R_outputParamFailed")); BigDecimal numericValue = callableStatement.getBigDecimal(12); - assertEquals(numericValue, new BigDecimal(numericValues[11]), "Test for output parameter fails.\n"); + assertEquals(numericValue, new BigDecimal(numericValues[11]), TestResource.getResource("R_outputParamFailed")); BigDecimal smallMoneyValue = callableStatement.getSmallMoney(13); - assertEquals(smallMoneyValue, new BigDecimal(numericValues[12]), "Test for output parameter fails.\n"); + assertEquals(smallMoneyValue, new BigDecimal(numericValues[12]), TestResource.getResource("R_outputParamFailed")); BigDecimal moneyValue = callableStatement.getMoney(14); - assertEquals(moneyValue, new BigDecimal(numericValues[13]), "Test for output parameter fails.\n"); + assertEquals(moneyValue, new BigDecimal(numericValues[13]), TestResource.getResource("R_outputParamFailed")); BigDecimal decimalValue2 = callableStatement.getBigDecimal(15); - assertEquals(decimalValue2, new BigDecimal(numericValues[14]), "Test for output parameter fails.\n"); + assertEquals(decimalValue2, new BigDecimal(numericValues[14]), TestResource.getResource("R_outputParamFailed")); BigDecimal numericValue2 = callableStatement.getBigDecimal(16); - assertEquals(numericValue2, new BigDecimal(numericValues[15]), "Test for output parameter fails.\n"); + assertEquals(numericValue2, new BigDecimal(numericValues[15]), TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -1683,7 +1683,7 @@ private void testcoerctionsOutputProcedureNumericInorder(String sql) throws SQLE boolVal = true; else if (value.toString().equals("0") || value.equals(false) || value.toString().equals("0.0")) boolVal = false; - assertEquals("" + boolVal, numericValues[0], "Test for output parameter fails.\n"); + assertEquals("" + boolVal, numericValues[0], TestResource.getResource("R_outputParamFailed")); } Class[] tinyint_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, String.class}; @@ -1693,9 +1693,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(tinyint_coercions[i], 1); if (x instanceof String) - assertEquals("" + tinyIntValue, x, "Test for output parameter fails.\n"); + assertEquals("" + tinyIntValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(tinyIntValue, x, "Test for output parameter fails.\n"); + assertEquals(tinyIntValue, x, TestResource.getResource("R_outputParamFailed")); } Class[] smallint_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, @@ -1705,9 +1705,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(smallint_coercions[i], 2); if (x instanceof String) - assertEquals("" + smallIntValue, x, "Test for output parameter fails.\n"); + assertEquals("" + smallIntValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(smallIntValue, x, "Test for output parameter fails.\n"); + assertEquals(smallIntValue, x, TestResource.getResource("R_outputParamFailed")); } Class[] int_coercions = {Object.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, String.class}; @@ -1716,9 +1716,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(int_coercions[i], 3); if (x != null) { if (x instanceof String) - assertEquals("" + IntValue, x, "Test for output parameter fails.\n"); + assertEquals("" + IntValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(IntValue, x, "Test for output parameter fails.\n"); + assertEquals(IntValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1729,9 +1729,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(bigint_coercions[i], 4); if (x != null) { if (x instanceof String) - assertEquals("" + bigIntValue, x, "Test for output parameter fails.\n"); + assertEquals("" + bigIntValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(bigIntValue, x, "Test for output parameter fails.\n"); + assertEquals(bigIntValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1742,9 +1742,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(float_coercions[i], 5); if (x != null) { if (x instanceof String) - assertEquals("" + floatDefaultValue, x, "Test for output parameter fails.\n"); + assertEquals("" + floatDefaultValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(floatDefaultValue, x, "Test for output parameter fails.\n"); + assertEquals(floatDefaultValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1753,9 +1753,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(float_coercions[i], 6); if (x != null) { if (x instanceof String) - assertEquals("" + floatValue, x, "Test for output parameter fails.\n"); + assertEquals("" + floatValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(floatValue, x, "Test for output parameter fails.\n"); + assertEquals(floatValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1767,9 +1767,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(real_coercions[i], 7); if (x != null) { if (x instanceof String) - assertEquals("" + realValue, x, "Test for output parameter fails for Coercion: " + real_coercions[i] + " for real value.\n"); + assertEquals("" + realValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(realValue, x, "Test for output parameter fails for Coercion: " + real_coercions[i] + " for real value.\n"); + assertEquals(realValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1780,9 +1780,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 8); if (x != null) { if (x instanceof String) - assertEquals("" + decimalDefaultValue, x, "Test for output parameter fails.\n"); + assertEquals("" + decimalDefaultValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(decimalDefaultValue, x, "Test for output parameter fails.\n"); + assertEquals(decimalDefaultValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1791,9 +1791,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 9); if (x != null) { if (x instanceof String) - assertEquals("" + decimalValue, x, "Test for output parameter fails.\n"); + assertEquals("" + decimalValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(decimalValue, x, "Test for output parameter fails.\n"); + assertEquals(decimalValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1802,9 +1802,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 10); if (x != null) { if (x instanceof String) - assertEquals("" + numericDefaultValue, x, "Test for output parameter fails.\n"); + assertEquals("" + numericDefaultValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(numericDefaultValue, x, "Test for output parameter fails.\n"); + assertEquals(numericDefaultValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1813,9 +1813,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 11); if (x != null) { if (x instanceof String) - assertEquals("" + numericValue, x, "Test for output parameter fails.\n"); + assertEquals("" + numericValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(numericValue, x, "Test for output parameter fails.\n"); + assertEquals(numericValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1824,9 +1824,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 12); if (x != null) { if (x instanceof String) - assertEquals("" + smallMoneyValue, x, "Test for output parameter fails.\n"); + assertEquals("" + smallMoneyValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(smallMoneyValue, x, "Test for output parameter fails.\n"); + assertEquals(smallMoneyValue, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1835,9 +1835,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 13); if (x != null) { if (x instanceof String) - assertEquals("" + moneyValue, x, "Test for output parameter fails.\n"); + assertEquals("" + moneyValue, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(moneyValue, x, "Test for output parameter fails.\n"); + assertEquals(moneyValue, x, TestResource.getResource("R_outputParamFailed")); } } for (int i = 0; i < decimalDefault_coercions.length; i++) { @@ -1845,9 +1845,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 14); if (x != null) { if (x instanceof String) - assertEquals("" + decimalValue2, x, "Test for output parameter fails.\n"); + assertEquals("" + decimalValue2, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(decimalValue2, x, "Test for output parameter fails.\n"); + assertEquals(decimalValue2, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1856,9 +1856,9 @@ else if (value.toString().equals("0") || value.equals(false) || value.toString() Object x = createValue(decimalDefault_coercions[i], 15); if (x != null) { if (x instanceof String) - assertEquals("" + numericValue1, x, "Test for output parameter fails.\n"); + assertEquals("" + numericValue1, x, TestResource.getResource("R_outputParamFailed")); else - assertEquals(numericValue1, x, "Test for output parameter fails.\n"); + assertEquals(numericValue1, x, TestResource.getResource("R_outputParamFailed")); } } @@ -1977,31 +1977,31 @@ private void testOutputProcedureBinaryInorder(String sql) throws SQLException { byte[] received1 = callableStatement.getBytes(1); for (int i = 0; i < expected.length; i++) { - assertEquals(received1[i], expected[i], "Test for output parameter fails.\n"); + assertEquals(received1[i], expected[i], TestResource.getResource("R_outputParamFailed")); } expected = byteValues.get(1); byte[] received2 = callableStatement.getBytes(2); for (int i = 0; i < expected.length; i++) { - assertEquals(received2[i], expected[i], "Test for output parameter fails.\n"); + assertEquals(received2[i], expected[i], TestResource.getResource("R_outputParamFailed")); } expected = byteValues.get(2); byte[] received3 = callableStatement.getBytes(3); for (int i = 0; i < expected.length; i++) { - assertEquals(received3[i], expected[i], "Test for output parameter fails.\n"); + assertEquals(received3[i], expected[i], TestResource.getResource("R_outputParamFailed")); } expected = byteValues.get(3); byte[] received4 = callableStatement.getBytes(4); for (int i = 0; i < expected.length; i++) { - assertEquals(received4[i], expected[i], "Test for output parameter fails.\n"); + assertEquals(received4[i], expected[i], TestResource.getResource("R_outputParamFailed")); } expected = byteValues.get(4); byte[] received5 = callableStatement.getBytes(5); for (int i = 0; i < expected.length; i++) { - assertEquals(received5[i], expected[i], "Test for output parameter fails.\n"); + assertEquals(received5[i], expected[i], TestResource.getResource("R_outputParamFailed")); } } catch (Exception e) { @@ -2274,20 +2274,20 @@ private void testOutputProcedureDateInorder(String sql) throws SQLException { callableStatement.registerOutParameter(18, microsoft.sql.Types.DATETIMEOFFSET, 2); callableStatement.execute(); - assertEquals(callableStatement.getDate(1), callableStatement.getDate(2), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getDate(1), callableStatement.getDate(2), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getTimestamp(3), callableStatement.getTimestamp(4), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTimestamp(3), callableStatement.getTimestamp(4), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getTime(7), callableStatement.getTime(8), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTime(7), callableStatement.getTime(8), TestResource.getResource("R_outputParamFailed")); assertEquals(callableStatement.getDateTime(9), // actual plain callableStatement.getDateTime(10), // received expected enc - "Test for output parameter fails.\n"); - assertEquals(callableStatement.getSmallDateTime(11), callableStatement.getSmallDateTime(12), "Test for output parameter fails.\n"); - assertEquals(callableStatement.getTimestamp(13), callableStatement.getTimestamp(14), "Test for output parameter fails.\n"); - assertEquals(callableStatement.getTime(15).getTime(), callableStatement.getTime(16).getTime(), "Test for output parameter fails.\n"); - assertEquals(callableStatement.getDateTimeOffset(17), callableStatement.getDateTimeOffset(18), "Test for output parameter fails.\n"); + TestResource.getResource("R_outputParamFailed")); + assertEquals(callableStatement.getSmallDateTime(11), callableStatement.getSmallDateTime(12), TestResource.getResource("R_outputParamFailed")); + assertEquals(callableStatement.getTimestamp(13), callableStatement.getTimestamp(14), TestResource.getResource("R_outputParamFailed")); + assertEquals(callableStatement.getTime(15).getTime(), callableStatement.getTime(16).getTime(), TestResource.getResource("R_outputParamFailed")); + assertEquals(callableStatement.getDateTimeOffset(17), callableStatement.getDateTimeOffset(18), TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -2318,20 +2318,20 @@ private void testOutputProcedureDateInorderObject(String sql) throws SQLExceptio callableStatement.registerOutParameter(18, microsoft.sql.Types.DATETIMEOFFSET, 2); callableStatement.execute(); - assertEquals(callableStatement.getObject(1), callableStatement.getObject(2), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(1), callableStatement.getObject(2), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getObject(3), callableStatement.getObject(4), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(3), callableStatement.getObject(4), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getObject(5), callableStatement.getObject(6), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(5), callableStatement.getObject(6), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getObject(7), callableStatement.getObject(8), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getObject(7), callableStatement.getObject(8), TestResource.getResource("R_outputParamFailed")); assertEquals(callableStatement.getObject(9), // actual plain callableStatement.getObject(10), // received expected enc - "Test for output parameter fails.\n"); - assertEquals(callableStatement.getObject(11), callableStatement.getObject(12), "Test for output parameter fails.\n"); - assertEquals(callableStatement.getObject(13), callableStatement.getObject(14), "Test for output parameter fails.\n"); - assertEquals(callableStatement.getObject(15), callableStatement.getObject(16), "Test for output parameter fails.\n"); - assertEquals(callableStatement.getObject(17), callableStatement.getObject(18), "Test for output parameter fails.\n"); + TestResource.getResource("R_outputParamFailed")); + assertEquals(callableStatement.getObject(13), callableStatement.getObject(14), TestResource.getResource("R_outputParamFailed")); + assertEquals(callableStatement.getObject(15), callableStatement.getObject(16), TestResource.getResource("R_outputParamFailed")); +TestResource.getResource("R_outputParamFailed"); + assertEquals(callableStatement.getObject(17), callableStatement.getObject(18), TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -2364,16 +2364,16 @@ private void testOutputProcedureBatchInorder(String sql) throws SQLException { callableStatement.execute(); int intValue2 = callableStatement.getInt(1); - assertEquals("" + intValue2, numericValues[3], "Test for output parameter fails.\n"); + assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed")); double floatValue0 = callableStatement.getDouble(2); - assertEquals("" + floatValue0, numericValues[5], "Test for output parameter fails.\n"); + assertEquals("" + floatValue0, numericValues[5], TestResource.getResource("R_outputParamFailed")); short shortValue3 = callableStatement.getShort(3); - assertEquals("" + shortValue3, numericValues[2], "Test for output parameter fails.\n"); + assertEquals("" + shortValue3, numericValues[2], TestResource.getResource("R_outputParamFailed")); BigDecimal smallmoneyValue = callableStatement.getSmallMoney(4); - assertEquals("" + smallmoneyValue, numericValues[12], "Test for output parameter fails.\n"); + assertEquals("" + smallmoneyValue, numericValues[12], TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { fail(e.toString()); @@ -2422,11 +2422,11 @@ private void testMixedProcedureDateScaleInorder(String sql) throws SQLException callableStatement.setDateTimeOffset(5, (DateTimeOffset) dateValues.get(6), 2); callableStatement.execute(); - assertEquals(callableStatement.getTimestamp(1), callableStatement.getTimestamp(2), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTimestamp(1), callableStatement.getTimestamp(2), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getTime(3), callableStatement.getTime(4), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTime(3), callableStatement.getTime(4), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { @@ -2448,11 +2448,11 @@ private void testMixedProcedureDateScaleWithParameterName(String sql) throws SQL callableStatement.setDateTimeOffset("p5", (DateTimeOffset) dateValues.get(6), 2); callableStatement.execute(); - assertEquals(callableStatement.getTimestamp(1), callableStatement.getTimestamp(2), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTimestamp(1), callableStatement.getTimestamp(2), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getTime(3), callableStatement.getTime(4), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getTime(3), callableStatement.getTime(4), TestResource.getResource("R_outputParamFailed")); - assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), "Test for output parameter fails.\n"); + assertEquals(callableStatement.getDateTimeOffset(5), callableStatement.getDateTimeOffset(6), TestResource.getResource("R_outputParamFailed")); } catch (Exception e) { 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 06e44276b..471643012 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -23,6 +23,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.util.RandomData; import com.microsoft.sqlserver.testframework.util.Util; @@ -568,12 +569,12 @@ private void testGetObject(ResultSet rs, && objectValue3.equalsIgnoreCase("" + values[index]); if (("" + values[index]).length() >= 1000) { - assertTrue(matches, "\nDecryption failed with getObject() at index: " + i + ", " + (i + 1) + ", " + (i + 2) - + ".\nExpected Value at index: " + index); + assertTrue(matches, TestResource.getResource("R_decryptionFailed") + "getObject(): " + i + ", " + (i + 1) + ", " + (i + 2) + + ".\n" + TestResource.getResource("R_expectedValue") + index); } else { - assertTrue(matches, "\nDecryption failed with getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 - + ".\nExpected Value: " + values[index]); + assertTrue(matches, TestResource.getResource("R_decryptionFailed") + "getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + values[index]); } } finally { @@ -605,8 +606,7 @@ else if (rs.getMetaData().getColumnTypeName(i).equalsIgnoreCase("datetime")) { assertTrue( objectValue1.equalsIgnoreCase("" + expected) && objectValue2.equalsIgnoreCase("" + expected) && objectValue3.equalsIgnoreCase("" + expected), - "\nDecryption failed with getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + ".\nExpected Value: " - + expected); + TestResource.getResource("R_decryptionFailed") + "getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + ".\n" + TestResource.getResource("R_expectedValue") + expected); } finally { index++; @@ -633,7 +633,7 @@ private void testGetObjectForBinary(ResultSet rs, if (null != values.get(index)) { for (int j = 0; j < expectedBytes.length; j++) { assertTrue(expectedBytes[j] == objectValue1[j] && expectedBytes[j] == objectValue2[j] && expectedBytes[j] == objectValue3[j], - "Decryption failed with getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + ".\n"); + TestResource.getResource("R_decryptionFailed") + "getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + ".\n"); } } } @@ -685,8 +685,8 @@ else if (values[index].equalsIgnoreCase("-3.4E38")) { assertTrue( decimalValue1.equalsIgnoreCase("" + values[index]) && decimalValue2.equalsIgnoreCase("" + values[index]) && decimalValue3.equalsIgnoreCase("" + values[index]), - "\nDecryption failed with getBigDecimal(): " + decimalValue1 + ", " + decimalValue2 + ", " + decimalValue3 - + ".\nExpected Value: " + values[index]); + TestResource.getResource("R_decryptionFailed") + "getBigDecimal(): " + decimalValue1 + ", " + decimalValue2 + ", " + decimalValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + values[index]); } finally { index++; @@ -720,13 +720,12 @@ else if (stringValue1.equalsIgnoreCase("1") && (values[index].equalsIgnoreCase(" && stringValue3.equalsIgnoreCase("" + values[index]); if (("" + values[index]).length() >= 1000) { - assertTrue(matches, "\nDecryption failed with getString() at index: " + i + ", " + (i + 1) + ", " + (i + 2) - + ".\nExpected Value at index: " + index); - + assertTrue(matches, TestResource.getResource("R_decryptionFailed") + "getString():" + i + ", " + (i + 1) + ", " + (i + 2) + + ".\n" + TestResource.getResource("R_expectedValue") + index); } else { - assertTrue(matches, "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\nExpected Value: " + values[index]); + assertTrue(matches, TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + values[index]); } } finally { @@ -752,8 +751,8 @@ private void testGetStringForDate(ResultSet rs, assertTrue( stringValue1.contains("" + values.get(index)) && stringValue2.contains("" + values.get(index)) && stringValue3.contains("" + values.get(index)), - "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\nExpected Value: " + values.get(index)); + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + values.get(index)); } else if (index == 4) // round value for datetime { @@ -761,8 +760,8 @@ else if (index == 4) // round value for datetime assertTrue( stringValue1.equalsIgnoreCase("" + datetimeValue) && stringValue2.equalsIgnoreCase("" + datetimeValue) && stringValue3.equalsIgnoreCase("" + datetimeValue), - "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\nExpected Value: " + datetimeValue); + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + datetimeValue); } else if (index == 5) // round value for smalldatetime { @@ -770,15 +769,15 @@ else if (index == 5) // round value for smalldatetime assertTrue( stringValue1.equalsIgnoreCase("" + smalldatetimeValue) && stringValue2.equalsIgnoreCase("" + smalldatetimeValue) && stringValue3.equalsIgnoreCase("" + smalldatetimeValue), - "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\nExpected Value: " + smalldatetimeValue); + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + smalldatetimeValue); } else { assertTrue( stringValue1.contains("" + values.get(index)) && stringValue2.contains("" + values.get(index)) && stringValue3.contains("" + values.get(index)), - "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\nExpected Value: " + values.get(index)); + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + values.get(index)); } } finally { @@ -806,7 +805,7 @@ private void testGetBytes(ResultSet rs, if (null != values.get(index)) { for (int j = 0; j < expectedBytes.length; j++) { assertTrue(expectedBytes[j] == b1[j] && expectedBytes[j] == b2[j] && expectedBytes[j] == b3[j], - "Decryption failed with getObject(): " + b1 + ", " + b2 + ", " + b3 + ".\n"); + TestResource.getResource("R_decryptionFailed") + "getObject(): " + b1 + ", " + b2 + ", " + b3 + ".\n"); } } } @@ -841,7 +840,7 @@ private void testGetStringForBinary(ResultSet rs, try { assertTrue(stringValue1.startsWith(expectedStr) && stringValue2.startsWith(expectedStr) && stringValue3.startsWith(expectedStr), - "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + ".\nExpected Value: " + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + ".\n" + TestResource.getResource("R_expectedValue") + expectedStr); } finally { @@ -907,17 +906,17 @@ private void testGetDate(ResultSet rs, break; default: - fail("Switch case is not matched with data"); + fail(TestResource.getResource("R_switchFailed")); } assertTrue( stringValue1.equalsIgnoreCase(expected) && stringValue2.equalsIgnoreCase(expected) && stringValue3.equalsIgnoreCase(expected), - "\nDecryption failed with testGetDate: " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + ".\nExpected Value: " + TestResource.getResource("R_decryptionFailed") + "testGetDate: " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + ".\n" + TestResource.getResource("R_expectedValue") + expected); } else { - fail("Result set is not instance of SQLServerResultSet"); + fail(TestResource.getResource("R_resultsetNotInstance")); } } } @@ -1120,7 +1119,7 @@ else if (expectedValue.equalsIgnoreCase("-3.4E+38")) { assertTrue( value1.equalsIgnoreCase("" + expectedValue) && value2.equalsIgnoreCase("" + expectedValue) && value3.equalsIgnoreCase("" + expectedValue), - "\nDecryption failed with getBigDecimal(): " + value1 + ", " + value2 + ", " + value3 + ".\nExpected Value: " + expectedValue); + TestResource.getResource("R_decryptionFailed") + "getBigDecimal(): " + value1 + ", " + value2+ ", " + value3 + ".\n" + TestResource.getResource("R_expectedValue")); } } 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 4d7b8b3d0..f426db0c9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -26,6 +26,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.util.Util; /** @@ -201,15 +202,15 @@ private void testGetString(ResultSet rs, try { if (rs.getMetaData().getColumnTypeName(i).equalsIgnoreCase("time")) { assertTrue(stringValue2.equalsIgnoreCase("" + values[index]) && stringValue3.equalsIgnoreCase("" + values[index]), - "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\nExpected Value: " + values[index]); + TestResource.getResource("R_decryptionFailed" + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + ": " + values[index])); } else { assertTrue( values[index].contains(stringValue1) && stringValue2.equalsIgnoreCase("" + values[index]) && stringValue3.equalsIgnoreCase("" + values[index]), - "\nDecryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\nExpected Value: " + values[index]); + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + TestResource.getResource("R_expected Value:") + values[index]); } } finally { @@ -232,8 +233,8 @@ private void testGetBigDecimal(ResultSet rs, assertTrue( decimalValue1.equalsIgnoreCase(values[index]) && decimalValue2.equalsIgnoreCase(values[index]) && decimalValue3.equalsIgnoreCase(values[index]), - "Decryption failed with getBigDecimal(): " + decimalValue1 + ", " + decimalValue2 + ", " + decimalValue3 - + "\nExpected value: " + values[index]); + TestResource.getResource("R_decryptionFailed") + "getBigDecimal(): " + decimalValue1 + ", " + decimalValue2 + ", " + decimalValue3 + + "\n" + TestResource.getResource("R_expectedValue") + ": " + values[index]); } finally { @@ -260,7 +261,7 @@ private void testGetObject(ResultSet rs, assertTrue( objectValue1.equalsIgnoreCase(values[index]) && objectValue2.equalsIgnoreCase(values[index]) && objectValue3.equalsIgnoreCase(values[index]), - "Decryption failed with getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + "\nExpected value: " + TestResource.getResource("R_decryptionFailed") + "getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 + "\n" + TestResource.getResource("R_expectedValue") + ": " + values[index]); } @@ -321,15 +322,14 @@ private void testGetDate(ResultSet rs, break; default: - fail("Switch case is not matched with data"); } try { assertTrue( stringValue1.equalsIgnoreCase(dates[index]) && stringValue2.equalsIgnoreCase(dates[index]) && stringValue3.equalsIgnoreCase(dates[index]), - "Decryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + "\nExpected value: " - + dates[index]); + TestResource.getResource("R_decryptionFailed" + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + "\n" + TestResource.getResource("R_expectedValue") + ": " + + dates[index])); } finally { index++; @@ -337,7 +337,7 @@ private void testGetDate(ResultSet rs, } else { - throw new Exception("Result set is not instance of SQLServerResultSet"); + throw new Exception(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 6873bbffe..fda54026a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java @@ -32,6 +32,8 @@ import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; +import com.microsoft.sqlserver.jdbc.TestResource;; + /** * Tests JDBC 4.3 APIs * @@ -56,14 +58,14 @@ public void connectionBuilderTest() throws TestAbortedException, SQLException { superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { shardingKey = ds.createShardingKeyBuilder().subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { @@ -71,7 +73,7 @@ public void connectionBuilderTest() throws TestAbortedException, SQLException { .build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } } @@ -90,14 +92,14 @@ public void xaConnectionBuilderTest() throws TestAbortedException, SQLException superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { shardingKey = ds.createShardingKeyBuilder().subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { @@ -105,7 +107,7 @@ public void xaConnectionBuilderTest() throws TestAbortedException, SQLException .superShardingKey(superShardingKey).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } } @@ -123,21 +125,21 @@ public void connectionPoolDataSourceTest() throws TestAbortedException, SQLExcep superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { shardingKey = ds.createShardingKeyBuilder().subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { PooledConnection con = ds.createPooledConnectionBuilder().user("rafa").password("tennis").shardingKey(shardingKey) .superShardingKey(superShardingKey).build(); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } } @@ -155,13 +157,13 @@ public void setShardingKeyIfValidTest() throws TestAbortedException, SQLExceptio connection43.setShardingKeyIfValid(shardingKey, 10); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { connection43.setShardingKeyIfValid(shardingKey, superShardingKey, 10); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } } @@ -180,13 +182,13 @@ public void setShardingKeyTest() throws TestAbortedException, SQLException { connection43.setShardingKey(shardingKey); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } try { connection43.setShardingKey(shardingKey, superShardingKey); } catch (SQLException e) { - assert (e.getMessage().contains("not implemented")); + assert (e.getMessage().contains(TestResource.getResource("R_notImplemented"))); } } @@ -225,4 +227,4 @@ public void deregisterDriverTest() throws SQLException, ClassNotFoundException { DriverManager.registerDriver(current); } -} \ No newline at end of file +} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java new file mode 100644 index 000000000..490120467 --- /dev/null +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -0,0 +1,171 @@ +/* + * 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; + +import java.util.ListResourceBundle; + +/** + * A simple resource bundle containing the strings for localizing. + * + */ +public final class TestResource extends ListResourceBundle { + public static String getResource(String key) { + return TestResource.getBundle("com.microsoft.sqlserver.jdbc.TestResource").getString(key); + } + + protected Object[][] getContents() { + return contents; + } + + // the keys must be prefixed with R_ to denote they are resource strings and their names should follow the camelCasing + // convention and be descriptive + static final Object[][] contents = { + {"R_wrongEnv", "Aborting test: As this is not the right environement: "}, + {"R_fipsPropertyNotSet", "Aborting test case as FIPS_ENV property is not set."}, + {"R_invalidTrustCert", "Invalid TrustServerCertificate value."}, + {"R_invalidEncrypt", "Invalid encrypt value."}, + {"R_notImplemented", "not implemented"}, + {"R_resultsetClosed", "The result set is closed."}, + {"R_resultsetNull", "The result set is null."}, + {"R_invalidFipsConfig", "Unable to verify FIPS mode settings."}, + {"R_shouldBeEnabled", "should be enabled."}, + {"R_StoredProcedureNotFound", "Could not find stored procedure"}, + {"R_givenValueType", "The given value of type"}, + {"R_lengthTruncated", " The inserted length is truncated or not correct!"}, + {"R_timeValueTruncated", " The time value is truncated or not correct!"}, + {"R_invalidErrorMessage", "Invalid Error Message: "}, + {"R_expectedFailPassed", "Expected failure did not fail"}, + {"R_dataTypeNotFound", "Cannot find data type"}, + {"R_illegalCharWkt", "Illegal character at wkt position "}, + {"R_errorMessage", " Error message: "}, + {"R_createDropViewFailed", "Create/drop view with preparedStatement failed!"}, + {"R_createDropSchemaFailed", "Create/drop schema with preparedStatement failed!"}, + {"R_createDropTableFailed", "Create/drop table with preparedStatement failed!"}, + {"R_createDropAlterTableFailed", "Create/drop/alter table with preparedStatement failed!"}, + {"R_grantFailed", "grant table with preparedStatement failed!"}, + {"R_connectionIsClosed", "The connection is closed."}, + {"R_connectionIsNotClosed", "The connection is not closed."}, + {"R_invalidExceptionMessage", "Invalid exception message"}, + {"R_failedValidate", "failed to validate values in $0} "}, + {"R_tableNotDropped", "table not dropped. "}, + {"R_connectionReset", "Connection reset"}, + {"R_unknownException", "Unknown exception"}, + {"R_deadConnection", "Dead connection should be invalid"}, + {"R_wrongExceptionMessage", "Wrong exception message"}, + {"R_parameterNotDefined", "Parameter {0} was not defined"}, + {"R_unexpectedExceptionContent", "Unexpected content in exception message"}, + {"R_conversionFailed", "Conversion failed when converting {0} to {1} data type"}, + {"R_invalidQueryTimeout", "The query timeout value {0} is not valid."}, + {"R_skipAzure", "Skipping test case on Azure SQL."}, + {"R_expectedExceptionNotThrown", "Expected exception is not thrown."}, + {"R_errorNotCalled", "Error occurred is not called."}, + {"R_errorCalled", "Error occurred is called."}, + {"R_supportUnwrapping", "{0} supports unwrapping."}, + {"R_cantAccessSnapshot", "Cant access the TRANSACTION_SNAPSHOT "}, + {"R_newConnectionShouldBeValid", "Newly created connection should be valid"}, + {"R_closedConnectionShouldBeInvalid", "Closed connection should be invalid"}, + {"R_noExceptionNegativeTimeout", "No exception thrown with negative timeout"}, + {"R_noExceptionClosedConnection", "No exception thrown calling getClientConnectionId on a closed connection"}, + {"R_clientConnectionIdNull", "ClientConnectionId is null"}, + {"R_valuesAreDifferent", "Values are different"}, + {"R_parrentLoggerNameWrong", "Parent Logger name is wrong"}, + {"R_unexpectedWrongDB", "Unexpected: ClientConnectionId is not in exception message due to wrong DB"}, + {"R_unexpectedWrongHost", "Unexpected: ClientConnectionId is in exception message due to wrong host"}, + {"R_cannotOpenDatabase", "Cannot open database"}, + {"R_shouldNotConnect", "Should not have connected"}, + {"R_loginFailed", "Login failed"}, + {"R_exitedMoreSeconds", "Exited in more than {0} seconds."}, + {"R_exitedLessSeconds", "Exited in less than {0} seconds."}, + {"R_invalidArgumentExecutor", "The argument executor is not valid"}, + {"R_threadInterruptNotSet", "Thread's interrupt status is not set."}, + {"R_connectMirrored", "Connecting to a mirrored"}, + {"R_trustStorePasswordNotSet", "The DataSource trustStore password needs to be set."}, + {"R_invalidObjectName", "Invalid object name"}, + {"R_tempTAbleNotRemoved", "Temporary table is not removed."}, + {"R_firstConnectionNotClosed", "First connection is not closed"}, + {"R_connectionNotClosedWithPoolClose", "Connection is not closed with pool close"}, + {"R_connectionNotClosedWithPoolClose", "Unexpected: ClientConnectionId is null from Pool"}, + {"R_idFromPoolNotSame", "ClientConnection Ids from pool are not the same."}, + {"R_noProtocolVersion", "protocol version is not enabled or not supported by the client."}, + {"R_protocolException", "Any protocol other than TLSv1, TLSv1.1, and TLSv1.2 should throw Exception"}, + {"R_invalidProtocolLabel", "SSL Protocol {0} label is not valid. Only TLS, TLSv1, TLSv1.1, and TLSv1.2 are supported."}, + {"R_SQLServerResourceMessage", "Message should be from SQL Server resources: "}, + {"R_shouldThrowException", "Exception should have been thrown"}, + {"R_tcpipConnectionToHost", "The TCP/IP connection to the host"}, + {"R_queryTimedOut", "The query has timed out."}, + {"R_readTimedOut", "Read timed out"}, + {"R_unexpectedErrorMessage", "Unexpected error message occured!"}, + {"R_warningsNotFound", "Warnings not found!"}, + {"R_warningsFound", "Warnings found!"}, + {"R_causeShouldNotBeNull", "Cause should not be null."}, + {"R_causeShouldBeInstance", "Cause should be instance of {0}."}, + {"R_connShouldNotBeClosed", "Connection should not be closed"}, + {"R_connShouldNotBeOpen", "Connection should not be open"}, + {"R_incorrectDriverNameFormat", "Driver name is not a correct format! "}, + {"R_incorrectDriverVersionFormat", "Driver version number should be four parts! "}, + {"R_previousShouldThrow", "Previous should have thrown an exception"}, + {"R_objectMissingOrEmpty", "An object or column name is missing or empty."}, + {"R_dbNameIsCurrentDB", "The database name component of the object qualifier must be the name of the current database."}, + {"R_numKeysIncorrect", "number of foreign key entries is incorrect."}, + {"R_manifestNotFound", "Manifest file does not exist on classpath so ignoring test"}, + {"R_buildVersionError", "build version should be greater than driver versions for non SNAPSHOT versions, and same for SNAPSHOT versions"}, + {"R_getURLContainsPwd", "Get URL should not have password attribute / property."}, + {"R_userNameNull", "Username should not be null"}, + {"R_userNameNotMatch", "Username does not match UserName from Connection String."}, + {"R_nameEmpty", "{0} name should not be empty."}, + {"R_nameNull", "{0} name should not be NULL."}, + {"R_atLeastOneFound", "At least one {0} should be found."}, + {"R_noSchemaShouldFail", "As we are not supplying schema it should fail."}, + {"R_addBatchFailed", "addBatch does not add the SQL Statements to Batch, call to addBatch failed"}, + {"R_insertBatchFailed", "affected rows does not match with batch size. Insert failed"}, + {"R_savePointError", "Savepoint {0} should be {1}."}, + {"R_Incompat_SQLServerVersion", "Aborting test case as SQL Server version is not compatible with Always encrypted"}, + {"R_noKeyStore", "Aborting test case as no java key store and alias name exists."}, + {"R_badStreamLength", "The stream value is not the specified length. The specified length was"}, + {"R_streamReadError", "An error occurred while reading the value from the stream object. Error"}, + {"R_SQLStateNull", "SQLState should not be null"}, + {"R_blobFreed", "This Blob oject has been freed."}, + {"R_streamNull", "Stream is null when data is not."}, + {"R_incorrectUpdateCount", "Incorrect updateCount."}, + {"R_testInterleaved", "Test interleaved inserts and warnings"}, + {"R_errorFollowInserts", "Test error followed by inserts"}, + {"R_errorFollow50280", "Test insert followed by non-fatal error (50280)"}, + {"R_syntaxErrorDateConvert", "Syntax error converting date"}, + {"R_dateConvertError", "Conversion failed when converting date"}, + {"R_incompatJDBC", "Aborting test case as JDBC version is not compatible."}, + {"R_unexpectedException", "Unexpected exception occurred"}, + {"R_addBatchFailed", "addBatch failed"}, + {"R_executeBatchFailed", "executeBatch failed"}, + {"R_customErrorMessage", "Custom error message: col1 should be higher than 10"}, + {"R_setDataNotEqual", "Received data not equal to setdata"}, + {"R_syntaxMatchError", "Syntax translation does not match for query"}, + {"R_valueNotMatch", "Value does not match: "}, + {"R_incorrectDefault", "Incorrect default"}, + {"R_shouldBeSupported", "should be supported."}, + {"R_operationNotSupported", "This operation is not supported."}, + {"R_paramNotRecognized", "Not all parameters are recognized by driver."}, + {"R_invalidGetPreparedStatementHandle", "Invalid use of getPreparedStatementHandle() after statement close expected."}, + {"R_cancellationFailed", "Cancellation failed."}, + {"R_executionNotTimeout", "Execution did not timeout."}, + {"R_executionTooLong", "Execution took too long."}, + {"R_executionNotLong", "Execution did not take long enough."}, + {"R_queryCancelled", "The query was canceled."}, + {"R_statementShouldBeClosed", "statement should be closed since resultset is closed."}, + {"R_statementShouldBeOpened", "statement should be opened since resultset is opened."}, + {"R_shouldBeWrapper", "{0} should be a wrapper for {1}."}, + {"R_shouldNotBeWrapper", "{0} should not be a wrapper for {1}."}, + {"R_outputParamFailed", "Test for output parameter failed."}, + {"R_inputParamFailed", "Test for input parameter failed."}, + {"R_decryptionFailed", "Decryption failed"}, + {"R_expectedValue", "Expected value: "}, + {"R_switchFailed", "Switch case is not matched with data"}, + {"R_resultsetNotInstance", "Result set is not instance of SQLServerResultSet"}, + + }; +} 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 2de49b360..49e72a880 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java @@ -13,6 +13,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.concurrent.ThreadLocalRandom; +import java.text.MessageFormat; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -28,6 +29,8 @@ import com.microsoft.sqlserver.testframework.sqlType.SqlType; import com.microsoft.sqlserver.testframework.util.ComparisonUtil; +import com.microsoft.sqlserver.jdbc.TestResource; + /** * Test BulkCopy Column Mapping */ @@ -193,7 +196,10 @@ void testRepetativeCM() { validateValuesRepetativeCM(con, sourceTable1, destTable); } catch (SQLException e) { - fail("failed to validate values in " + sourceTable1.getTableName() + " and " + destTable.getTableName() + "\n" + e.getMessage()); + MessageFormat form = new MessageFormat(TestResource.getResource("R_failedValidate")); + Object[] msgArgs = {sourceTable1.getTableName()+" and"+destTable.getTableName()}; + + fail(form.format(msgArgs) + "\n" + destTable.getTableName() + "\n" + e.getMessage()); } dropTable(sourceTable1.getEscapedTableName()); dropTable(destTable.getEscapedTableName()); @@ -367,7 +373,7 @@ private void dropTable(String tableName) { stmt.execute(dropSQL); } catch (SQLException e) { - fail("table " + tableName + " not dropped\n" + e.getMessage()); + fail(tableName + " " + TestResource.getResource("R_tableNotDropped") + "\n" + e.getMessage()); } } 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 abcae31a8..bbc3f7100 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java @@ -115,10 +115,10 @@ public void execute() throws SQLException { } /** - * BulkCopy:test empty connenction string + * BulkCopy:test empty connection string */ @Test - @DisplayName("BulkCopy:test empty connenction string") + @DisplayName("BulkCopy:test empty connection string") void testInvalidConnection3() { assertThrows(SQLException.class, new org.junit.jupiter.api.function.Executable() { @Override diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java index 0b902587e..5a7aa7aa9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java @@ -16,6 +16,7 @@ import com.microsoft.sqlserver.jdbc.ISQLServerBulkRecord; import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; import com.microsoft.sqlserver.jdbc.bulkCopy.BulkCopyTestWrapper.ColumnMap; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.DBResultSet; import com.microsoft.sqlserver.testframework.DBStatement; @@ -203,7 +204,7 @@ else if ((!currentMap.sourceIsInt) && (!currentMap.destIsInt)) { } bulkCopy.writeToServer((ResultSet) srcResultSet.product()); if (fail) - fail("bulkCopy.writeToServer did not fail when it should have"); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); if (validateResult) { validateValues(con, sourceTable, destinationTable); } @@ -269,7 +270,7 @@ else if ((!currentMap.sourceIsInt) && (!currentMap.destIsInt)) { } bulkCopy.writeToServer((ResultSet) srcResultSet.product()); if (fail) - fail("bulkCopy.writeToServer did not fail when it should have"); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); bulkCopy.close(); if (validateResult) { validateValues(con, sourceTable, destinationTable); @@ -394,4 +395,4 @@ static void validateValues( } } } -} \ No newline at end of file +} 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 23ba2127c..276f62619 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.text.MessageFormat; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -34,6 +35,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerException; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -64,11 +66,11 @@ public void testVarchar() throws Exception { bcOperation.setDestinationTableName(destTable); bcOperation.writeToServer(bData); bcOperation.close(); - fail("BulkCopy executed for testVarchar when it it was expected to fail"); + fail(TestResource.getResource("R_expectedFailPassed")); } catch (Exception e) { if (e instanceof SQLException) { - assertTrue(e.getMessage().contains("The given value of type"), "Invalid Error message: " + e.toString()); + assertTrue(e.getMessage().contains(TestResource.getResource("R_givenValueType")), TestResource.getResource("R_invalidErrorMessage") + e.toString()); } else { fail(e.getMessage()); @@ -121,8 +123,11 @@ public void testSmalldatetimeOutofRange() throws Exception { } catch (Exception e) { if (e instanceof SQLException) { - assertTrue(e.getMessage().contains("Conversion failed when converting character string to smalldatetime data type"), - "Invalid Error message: " + e.toString()); + MessageFormat form = new MessageFormat(TestResource.getResource("R_conversionFailed")); + Object[] msgArgs = {"character string", "smalldatetime"}; + + assertTrue(e.getMessage().contains(form.format(msgArgs)), + TestResource.getResource("R_invalidErrorMessage") + e.toString()); } else { fail(e.getMessage()); @@ -145,11 +150,11 @@ public void testBinaryColumnAsByte() throws Exception { try (SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(connectionString)) { bcOperation.setDestinationTableName(destTable); bcOperation.writeToServer(bData); - fail("BulkCopy executed for testBinaryColumnAsByte when it it was expected to fail"); + fail("R_expectedFailPassed"); } catch (Exception e) { if (e instanceof SQLException) { - assertTrue(e.getMessage().contains("The given value of type"), "Invalid Error message: " + e.toString()); + assertTrue(e.getMessage().contains(TestResource.getResource("R_givenValueType")), TestResource.getResource("R_invalidErrorMessage") + e.toString()); } else { fail(e.getMessage()); @@ -172,11 +177,11 @@ public void testBinaryColumnAsString() throws Exception { try (SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(connectionString)) { bcOperation.setDestinationTableName(destTable); bcOperation.writeToServer(bData); - fail("BulkCopy executed for testBinaryColumnAsString when it it was expected to fail"); + fail("R_expectedFailPassed"); } catch (Exception e) { if (e instanceof SQLException) { - assertTrue(e.getMessage().contains("The given value of type"), "Invalid Error message: " + e.toString()); + assertTrue(e.getMessage().contains(TestResource.getResource("R_givenValueType")), TestResource.getResource("R_invalidErrorMessage") + e.toString()); } else { fail(e.getMessage()); 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 eaad85365..d96044039 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/bvtTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/bvtTest.java @@ -29,6 +29,8 @@ import com.microsoft.sqlserver.testframework.DBResultSetTypes; import com.microsoft.sqlserver.testframework.DBStatement; +import com.microsoft.sqlserver.jdbc.TestResource;; + @RunWith(JUnitPlatform.class) @DisplayName("BVT Test") public class bvtTest extends bvtTestSetup { @@ -53,9 +55,10 @@ public void testConnection() throws SQLException { @Test public void testConnectionIsClosed() throws SQLException { try (DBConnection conn = new DBConnection(connectionString)) { - assertTrue(!conn.isClosed(), "BVT connection should not be closed"); + assertTrue(!conn.isClosed(), TestResource.getResource("R_connShouldNotBeClosed")); conn.close(); - assertTrue(conn.isClosed(), "BVT connection should not be open"); + assertTrue(conn.isClosed(), TestResource.getResource("R_connShouldNotBeOpen")); + } } @@ -70,10 +73,10 @@ public void testDriverNameAndDriverVersion() throws SQLException { DatabaseMetaData metaData = conn.getMetaData(); Pattern p = Pattern.compile(driverNamePattern); Matcher m = p.matcher(metaData.getDriverName()); - assertTrue(m.find(), "Driver name is not a correct format! "); + assertTrue(m.find(), TestResource.getResource("R_incorrectDriverNameFormat")); String[] parts = metaData.getDriverVersion().split("\\."); if (parts.length != 4) - assertTrue(true, "Driver version number should be four parts! "); + assertTrue(true, TestResource.getResource("R_incorrectDriverVewrsionFormat")); } } @@ -209,7 +212,7 @@ public void testStmtForwardOnlyUpdateable() throws SQLException { rs.verifyCurrentRow(table1); try { rs.previous(); - assertTrue(false, "Previous should have thrown an exception"); + assertTrue(false, TestResource.getResource("R_previousShouldThrow")); } catch (SQLException ex) { // expected exception @@ -402,7 +405,7 @@ public void testTwoResultsetsSameStmt() throws SQLException { rs1.next(); } catch (SQLException e) { - assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed."); + assertEquals(e.getMessage(), TestResource.getResource("R_resultsetClosed")); } rs2.next(); rs2.verifyCurrentRow(table2); @@ -410,7 +413,7 @@ public void testTwoResultsetsSameStmt() throws SQLException { rs1.next(); } catch (SQLException e) { - assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed."); + assertEquals(e.getMessage(), TestResource.getResource("R_resultsetClosed")); } rs1.close(); rs2.next(); @@ -436,7 +439,7 @@ public void testResultSetAndCloseStmt() throws SQLException { rs.next(); } catch (SQLException e) { - assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed."); + assertEquals(e.getMessage(), TestResource.getResource("R_resultsetClosed")); } assertTrue(true, "Previous one should have thrown exception!"); } 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 287786c0f..cbf4a0066 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -11,6 +11,7 @@ import java.sql.Statement; import java.sql.Types; import java.util.UUID; +import java.text.MessageFormat; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -20,6 +21,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -150,10 +152,14 @@ public void inputParamsTest() throws SQLException { CallableStatement cs3 = connection.prepareCall(call); try { cs3.setString("@whatever", "test"); - fail("SQLException should have been thrown"); + fail(TestResource.getResource("R_shouldThrowException")); } catch (SQLException sse) { - if (!sse.getMessage().startsWith("Parameter @whatever was not defined")) { - fail("Unexpected content in exception message"); + + MessageFormat form = new MessageFormat(TestResource.getResource("R_parameterNotDefined")); + Object[] msgArgs = {"@whatever"}; + + if (!sse.getMessage().startsWith(form.format(msgArgs))) { + fail(TestResource.getResource("R_unexpectedExceptionContent")); } } 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 3de43f7c1..40010c3ea 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java @@ -25,6 +25,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.logging.Logger; +import java.text.MessageFormat; import javax.sql.ConnectionEvent; import javax.sql.PooledConnection; @@ -39,6 +40,7 @@ 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.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.DBTable; @@ -77,16 +79,16 @@ public void testConnectionDriver() throws SQLException { infoArray = d.getPropertyInfo(url.toString(), info); for (DriverPropertyInfo anInfoArray : infoArray) { if (anInfoArray.name.equals("encrypt")) { - assertTrue(anInfoArray.value.equals("true"), "Values are different"); + assertTrue(anInfoArray.value.equals("true"), TestResource.getResource("R_valuesAreDifferent")); } if (anInfoArray.name.equals("trustStore")) { - assertTrue(anInfoArray.value.equals("someStore"), "Values are different"); + assertTrue(anInfoArray.value.equals("someStore"), TestResource.getResource("R_valuesAreDifferent")); } if (anInfoArray.name.equals("trustStorePassword")) { - assertTrue(anInfoArray.value.equals("somepassword"), "Values are different"); + assertTrue(anInfoArray.value.equals("somepassword"), TestResource.getResource("R_valuesAreDifferent")); } if (anInfoArray.name.equals("hostNameInCertificate")) { - assertTrue(anInfoArray.value.equals("someHost"), "Values are different"); + assertTrue(anInfoArray.value.equals("someHost"), TestResource.getResource("R_valuesAreDifferent")); } } } @@ -109,9 +111,9 @@ public void testDataSource() { ds.setEncrypt(true); ds.setTrustStorePassword(trustStorePassword); ds.setTrustServerCertificate(true); - assertEquals(trustStore, ds.getTrustStore(), "Values are different"); - assertEquals(true, ds.getEncrypt(), "Values are different"); - assertEquals(true, ds.getTrustServerCertificate(), "Values are different"); + assertEquals(trustStore, ds.getTrustStore(), TestResource.getResource("R_valuesAreDifferent")); + assertEquals(true, ds.getEncrypt(), TestResource.getResource("R_valuesAreDifferent")); + assertEquals(true, ds.getTrustServerCertificate(), TestResource.getResource("R_valuesAreDifferent")); } @Test @@ -129,14 +131,14 @@ public void testEncryptedConnection() throws SQLException { public void testJdbcDriverMethod() throws SQLFeatureNotSupportedException { SQLServerDriver serverDriver = new SQLServerDriver(); Logger logger = serverDriver.getParentLogger(); - assertEquals(logger.getName(), "com.microsoft.sqlserver.jdbc", "Parent Logger name is wrong"); + assertEquals(logger.getName(), "com.microsoft.sqlserver.jdbc", TestResource.getResource("R_parrentLoggerNameWrong")); } @Test public void testJdbcDataSourceMethod() throws SQLFeatureNotSupportedException { SQLServerDataSource fxds = new SQLServerDataSource(); Logger logger = fxds.getParentLogger(); - assertEquals(logger.getName(), "com.microsoft.sqlserver.jdbc", "Parent Logger name is wrong"); + assertEquals(logger.getName(), "com.microsoft.sqlserver.jdbc", TestResource.getResource("R_parrentLoggerNameWrong")); } class MyEventListener implements javax.sql.ConnectionEventListener { @@ -162,7 +164,7 @@ public void connectionErrorOccurred(ConnectionEvent event) { */ @Test public void testConnectionEvents() throws SQLException { - assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), "Skipping test case on Azure SQL."); + assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), TestResource.getResource("R_skipAzure")); SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource(); mds.setURL(connectionString); @@ -184,17 +186,17 @@ public void testConnectionEvents() throws SQLException { catch (Exception e) { exceptionThrown = true; } - assertTrue(exceptionThrown, "Expected exception is not thrown."); + assertTrue(exceptionThrown, TestResource.getResource("R_expectedExceptionNotThrown")); // Check to see if error occurred. - assertTrue(myE.errorOccurred, "Error occurred is not called."); + assertTrue(myE.errorOccurred, TestResource.getResource("R_errorNotCalled")); } // make sure that connection is closed. } @Test public void testConnectionPoolGetTwice() throws SQLException { - assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), "Skipping test case on Azure SQL."); + assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), TestResource.getResource("R_skipAzure")); SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource(); mds.setURL(connectionString); @@ -209,18 +211,18 @@ public void testConnectionPoolGetTwice() throws SQLException { // raise a non severe exception and make sure that the connection is not closed. stmt.executeUpdate("RAISERROR ('foo', 3,1) WITH LOG"); // not a serious error there should not be any errors. - assertTrue(!myE.errorOccurred, "Error occurred is called."); + assertTrue(!myE.errorOccurred, TestResource.getResource("R_errorCalled")); // check to make sure that connection is not closed. - assertTrue(!con.isClosed(), "Connection is closed."); + assertTrue(!con.isClosed(), TestResource.getResource("R_connectionIsClosed")); stmt.close(); con.close(); // check to make sure that connection is closed. - assertTrue(con.isClosed(), "Connection is not closed."); + assertTrue(con.isClosed(), TestResource.getResource("R_connectionIsNotClosed")); } @Test public void testConnectionClosed() throws SQLException { - assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), "Skipping test case on Azure SQL."); + assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), TestResource.getResource("R_skipAzure")); SQLServerDataSource mds = new SQLServerDataSource(); mds.setURL(connectionString); @@ -234,10 +236,10 @@ public void testConnectionClosed() throws SQLException { catch (Exception e) { exceptionThrown = true; } - assertTrue(exceptionThrown, "Expected exception is not thrown."); + assertTrue(exceptionThrown, TestResource.getResource("R_expectedExceptionNotThrown")); // check to make sure that connection is closed. - assertTrue(con.isClosed(), "Connection is not closed."); + assertTrue(con.isClosed(), TestResource.getResource("R_connectionIsNotClosed")); } @Test @@ -246,13 +248,17 @@ public void testIsWrapperFor() throws SQLException, ClassNotFoundException { SQLServerConnection ssconn = (SQLServerConnection) conn) { boolean isWrapper; isWrapper = ssconn.isWrapperFor(ssconn.getClass()); - assertTrue(isWrapper, "SQLServerConnection supports unwrapping"); - assertEquals(ssconn.TRANSACTION_SNAPSHOT, ssconn.TRANSACTION_SNAPSHOT, "Cant access the TRANSACTION_SNAPSHOT "); + MessageFormat form = new MessageFormat(TestResource.getResource("R_supportUnwrapping")); + Object[] msgArgs1 = {"SQLServerConnection"}; + + assertTrue(isWrapper, form.format(msgArgs1)); + assertEquals(ssconn.TRANSACTION_SNAPSHOT, ssconn.TRANSACTION_SNAPSHOT, TestResource.getResource("R_cantAccessSnapshot")); isWrapper = ssconn.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerConnection")); - assertTrue(isWrapper, "ISQLServerConnection supports unwrapping"); + Object[] msgArgs2 = {"ISQLServerConnection"}; + assertTrue(isWrapper, form.format(msgArgs2)); ISQLServerConnection iSql = (ISQLServerConnection) ssconn.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerConnection")); - assertEquals(iSql.TRANSACTION_SNAPSHOT, iSql.TRANSACTION_SNAPSHOT, "Cant access the TRANSACTION_SNAPSHOT "); + assertEquals(iSql.TRANSACTION_SNAPSHOT, iSql.TRANSACTION_SNAPSHOT, TestResource.getResource("R_cantAccessSnapshot")); ssconn.unwrap(Class.forName("java.sql.Connection")); } @@ -261,7 +267,7 @@ public void testIsWrapperFor() throws SQLException, ClassNotFoundException { @Test public void testNewConnection() throws SQLException { try(SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString)) { - assertTrue(conn.isValid(0), "Newly created connection should be valid"); + assertTrue(conn.isValid(0), TestResource.getResource("R_newConnectionShouldBeValid")); } } @@ -269,7 +275,7 @@ public void testNewConnection() throws SQLException { public void testClosedConnection() throws SQLException { SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString); conn.close(); - assertTrue(!conn.isValid(0), "Closed connection should be invalid"); + assertTrue(!conn.isValid(0), TestResource.getResource("R_closedConnectionShouldBeInvalid")); } @Test @@ -277,17 +283,20 @@ public void testNegativeTimeout() throws Exception { try (SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString)) { try { conn.isValid(-42); - throw new Exception("No exception thrown with negative timeout"); + throw new Exception(TestResource.getResource("R_noExceptionNegativeTimeout")); } catch (SQLException e) { - assertEquals(e.getMessage(), "The query timeout value -42 is not valid.", "Wrong exception message"); + MessageFormat form = new MessageFormat(TestResource.getResource("R_invalidQueryTimeout")); + Object[] msgArgs = {"-42"}; + + assertEquals(e.getMessage(), form.format(msgArgs), TestResource.getResource("R_wrongExceptionMessage")); } } } @Test public void testDeadConnection() throws SQLException { - assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), "Skipping test case on Azure SQL."); + assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)), TestResource.getResource("R_skipAzure")); try (SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString + ";responseBuffering=adaptive")) { @@ -307,27 +316,27 @@ public void testDeadConnection() throws SQLException { + " as x2; RAISERROR ('Oops', 21, 42) WITH LOG"); } catch (SQLException e) { - assertEquals(e.getMessage(), "Connection reset", "Unknown Exception"); + assertEquals(e.getMessage(), TestResource.getResource("R_connectionReset"), TestResource.getResource("R_unknownException")); } finally { DriverManager.getConnection(connectionString).createStatement().execute("drop table " + tableName); } - assertEquals(conn.isValid(5), false, "Dead connection should be invalid"); + assertEquals(conn.isValid(5), false, TestResource.getResource("R_deadConnection")); } } @Test public void testClientConnectionId() throws Exception { SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString); - assertTrue(conn.getClientConnectionId() != null, "ClientConnectionId is null"); + assertTrue(conn.getClientConnectionId() != null, TestResource.getResource("R_clientConnectionIdNull")); conn.close(); try { // Call getClientConnectionId on a closed connection, should raise exception conn.getClientConnectionId(); - throw new Exception("No exception thrown calling getClientConnectionId on a closed connection"); + throw new Exception(TestResource.getResource("R_noExceptionClosedConnection")); } catch (SQLException e) { - assertEquals(e.getMessage(), "The connection is closed.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_connectionIsClosed"), TestResource.getResource("R_wrongExceptionMessage")); } conn = null; @@ -340,7 +349,7 @@ public void testClientConnectionId() throws Exception { } catch (SQLException e) { assertTrue(e.getMessage().indexOf("ClientConnectionId") != -1, - "Unexpected: ClientConnectionId is not in exception message due to wrong DB"); + TestResource.getResource("R_unexpectedWrongDB")); } try { @@ -352,7 +361,7 @@ public void testClientConnectionId() throws Exception { } catch (SQLException e) { assertEquals(false, e.getMessage().indexOf("ClientConnectionId") != -1, - "Unexpected: ClientConnectionId is in exception message due to wrong host"); + TestResource.getResource("R_unexpectedWrongHost")); } } @@ -371,13 +380,16 @@ public void testIncorrectDatabase() throws SQLException { con = ds.getConnection(); } catch (Exception e) { - assertTrue(e.getMessage().contains("Cannot open database")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_cannotOpenDatabase"))); timerEnd = System.currentTimeMillis(); } long timeDiff = timerEnd - timerStart; - assertTrue(con == null, "Should not have connected."); - assertTrue(timeDiff <= milsecs, "Exited in more than " + (milsecs / 1000) + " seconds."); + assertTrue(con == null, TestResource.getResource("R_shouldNotConnect")); + + MessageFormat form = new MessageFormat(TestResource.getResource("R_exitedMoreSeconds")); + Object[] msgArgs = {milsecs / 1000}; + assertTrue(timeDiff <= milsecs, form.format(msgArgs)); } @Test @@ -395,13 +407,15 @@ public void testIncorrectUserName() throws SQLException { con = ds.getConnection(); } catch (Exception e) { - assertTrue(e.getMessage().contains("Login failed")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_loginFailed"))); timerEnd = System.currentTimeMillis(); } long timeDiff = timerEnd - timerStart; - assertTrue(con == null, "Should not have connected."); - assertTrue(timeDiff <= milsecs, "Exited in more than " + (milsecs / 1000) + " seconds."); + assertTrue(con == null, TestResource.getResource("R_shouldNotConnect")); + MessageFormat form = new MessageFormat(TestResource.getResource("R_exitedMoreSeconds")); + Object[] msgArgs = {milsecs / 1000}; + assertTrue(timeDiff <= milsecs, form.format(msgArgs)); } @Test @@ -419,13 +433,15 @@ public void testIncorrectPassword() throws SQLException { con = ds.getConnection(); } catch (Exception e) { - assertTrue(e.getMessage().contains("Login failed")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_loginFailed"))); timerEnd = System.currentTimeMillis(); } long timeDiff = timerEnd - timerStart; - assertTrue(con == null, "Should not have connected."); - assertTrue(timeDiff <= milsecs, "Exited in more than " + (milsecs / 1000) + " seconds."); + assertTrue(con == null, TestResource.getResource("R_shouldNotConnect")); + MessageFormat form = new MessageFormat(TestResource.getResource("R_exitedMoreSeconds")); + Object[] msgArgs = {milsecs / 1000}; + assertTrue(timeDiff <= milsecs, form.format(msgArgs)); } @Test @@ -444,13 +460,15 @@ public void testInvalidCombination() throws SQLException { con = ds.getConnection(); } catch (Exception e) { - assertTrue(e.getMessage().contains("Connecting to a mirrored")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_connectMirrored"))); timerEnd = System.currentTimeMillis(); } long timeDiff = timerEnd - timerStart; - assertTrue(con == null, "Should not have connected."); - assertTrue(timeDiff <= milsecs, "Exited in more than " + (milsecs / 1000) + " seconds."); + assertTrue(con == null, TestResource.getResource("R_shouldNotConnect")); + MessageFormat form = new MessageFormat(TestResource.getResource("R_exitedMoreSeconds")); + Object[] msgArgs = {milsecs / 1000}; + assertTrue(timeDiff <= milsecs, form.format(msgArgs)); } @Test @@ -473,8 +491,10 @@ public void testIncorrectDatabaseWithFailoverPartner() throws SQLException { } long timeDiff = timerEnd - timerStart; - assertTrue(con == null, "Should not have connected."); - assertTrue(timeDiff >= ((loginTimeOutInSeconds - 1) * 1000), "Exited in less than " + (loginTimeOutInSeconds - 1) + " seconds."); + assertTrue(con == null, TestResource.getResource("R_shouldNotConnect")); + MessageFormat form = new MessageFormat(TestResource.getResource("R_exitedLessSeconds")); + Object[] msgArgs = {loginTimeOutInSeconds - 1}; + assertTrue(timeDiff >= ((loginTimeOutInSeconds - 1) * 1000), form.format(msgArgs)); } @Test @@ -484,7 +504,7 @@ public void testAbortBadParam() throws SQLException { conn.abort(null); } catch (SQLException e) { - assertTrue(e.getMessage().contains("The argument executor is not valid")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_invalidArgumentExecutor"))); } } @@ -546,6 +566,6 @@ public void run() { executor.shutdownNow(); - assertTrue(isInterrupted, "Thread's interrupt status is not set."); + assertTrue(isInterrupted, TestResource.getResource("R_threadInterruptNotSet")); } } 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 b7d0edc3f..e8ac9164b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java @@ -28,6 +28,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; import com.microsoft.sqlserver.jdbc.SQLServerXADataSource; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; @RunWith(JUnitPlatform.class) @@ -71,7 +72,7 @@ public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLEx ds = testSerial(ds); try (Connection conn = ds.getConnection()) {} catch (SQLException e) { - assertEquals("The DataSource trustStore password needs to be set.", e.getMessage()); + assertEquals(TestResource.getResource("R_trustStorePasswordNotSet"), e.getMessage()); } } 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 428c7d0cf..cd58cac86 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java @@ -31,6 +31,7 @@ import com.microsoft.sqlserver.jdbc.ISQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerXADataSource; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.DBTable; @@ -71,11 +72,11 @@ public void testPooling() throws SQLException { } catch (SQLException e) { // make sure the temporary table is not found. - if (e.getMessage().startsWith("Invalid object name")) { + if (e.getMessage().startsWith(TestResource.getResource("R_invalidObjectName"))) { tempTableFileRemoved = true; } } - assertTrue(tempTableFileRemoved, "Temporary table is not removed."); + assertTrue(tempTableFileRemoved, TestResource.getResource("R_tempTAbleNotRemoved")); } @Test @@ -90,7 +91,7 @@ public void testConnectionPoolReget() throws SQLException { Connection con2 = pc.getConnection(); // assert that the first connection is closed. - assertTrue(con.isClosed(), "First connection is not closed"); + assertTrue(con.isClosed(), TestResource.getResource("R_firstConnectionNotClosed")); } @Test @@ -125,7 +126,7 @@ public void testConnectionPoolClose() throws SQLException { pc.close(); // assert that the first connection is closed. - assertTrue(con.isClosed(), "Connection is not closed with pool close"); + assertTrue(con.isClosed(), TestResource.getResource("R_connectionNotClosedWithPoolClose")); } @Test @@ -137,7 +138,7 @@ public void testConnectionPoolClientConnectionId() throws SQLException { ISQLServerConnection con = (ISQLServerConnection) pc.getConnection(); UUID Id1 = con.getClientConnectionId(); - assertTrue(Id1 != null, "Unexecepted: ClientConnectionId is null from Pool"); + assertTrue(Id1 != null, TestResource.getResource("R_connectionNotClosedWithPoolClose")); con.close(); // now reget the connection @@ -146,7 +147,7 @@ public void testConnectionPoolClientConnectionId() throws SQLException { UUID Id2 = con2.getClientConnectionId(); con2.close(); - assertEquals(Id1, Id2, "ClientConnection Ids from pool are not the same."); + assertEquals(Id1, Id2, TestResource.getResource("R_idFromPoolNotSame")); } /** 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 c1e7e3351..e5eced4ad 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java @@ -16,12 +16,15 @@ import java.sql.DriverManager; import java.sql.Statement; +import java.text.MessageFormat; + import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.StringUtils; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; /** @@ -51,7 +54,7 @@ public void testWithSupportedProtocols(String sslProtocol) throws Exception { // Some older versions of SQLServer might not have all the TLS protocol versions enabled. // Example, if the highest TLS version enabled in the server is TLSv1.1, // the connection will fail if we enable only TLSv1.2 - assertTrue(e.getMessage().contains("protocol version is not enabled or not supported by the client.")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_noProtocolVersion"))); } } @@ -66,12 +69,14 @@ public void testWithUnSupportedProtocols(String sslProtocol) throws Exception { try { String url = connectionString + ";sslProtocol=" + sslProtocol; con = DriverManager.getConnection(url); - assertFalse(true, "Any protocol other than TLSv1, TLSv1.1, and TLSv1.2 should throw Exception"); + assertFalse(true, TestResource.getResource("R_protocolVersion")); } catch (SQLServerException e) { - assertTrue(true, "Should throw exception"); - String errMsg = "SSL Protocol " + sslProtocol + " label is not valid. Only TLS, TLSv1, TLSv1.1, and TLSv1.2 are supported."; - assertTrue(errMsg.equals(e.getMessage()), "Message should be from SQL Server resources : " + e.getMessage()); + assertTrue(true, TestResource.getResource("R_shouldThrowException")); + MessageFormat form = new MessageFormat(TestResource.getResource("R_invalidProtocolLabel")); + Object[] msgArgs = {sslProtocol}; + String errMsg = form.format(msgArgs); + assertTrue(errMsg.equals(e.getMessage()), TestResource.getResource("R_SQLServerResourceMessage") + e.getMessage()); } } 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 8b9dc919e..2382dfeed 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java @@ -21,6 +21,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; import com.microsoft.sqlserver.testframework.util.RandomUtil; @@ -42,10 +43,10 @@ public void testDefaultLoginTimeout() { DriverManager.getConnection("jdbc:sqlserver://" + randomServer + ";user=sa;password=pwd;"); } catch (Exception e) { - assertTrue(e.getMessage().contains("The TCP/IP connection to the host")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_tcpipConnectionToHost"))); timerEnd = System.currentTimeMillis(); } - assertTrue(0 != timerEnd, "Should not have connected."); + assertTrue(0 != timerEnd, TestResource.getResource("R_shouldNotConnect")); long timeDiff = timerEnd - timerStart; assertTrue(timeDiff > 14000); @@ -62,10 +63,10 @@ public void testFailoverInstanceResolution() throws SQLException { + "\\foo;user=sa;password=pwd;"); } catch (Exception e) { - assertTrue(e.getMessage().contains("The TCP/IP connection to the host")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_tcpipConnectionToHost"))); timerEnd = System.currentTimeMillis(); } - assertTrue(0 != timerEnd, "Should not have connected."); + assertTrue(0 != timerEnd, TestResource.getResource("R_shouldNotConnect")); long timeDiff = timerEnd - timerStart; assertTrue(timeDiff > 14000); @@ -84,7 +85,7 @@ public void testFOInstanceResolution2() throws SQLException { catch (Exception e) { timerEnd = System.currentTimeMillis(); } - assertTrue(0 != timerEnd, "Should not have connected."); + assertTrue(0 != timerEnd, TestResource.getResource("R_shouldNotConnect")); long timeDiff = timerEnd - timerStart; assertTrue(timeDiff > 14000); @@ -105,18 +106,18 @@ public void testQueryTimeout() throws Exception { try { conn.createStatement().execute("exec " + waitForDelaySPName); - throw new Exception("Exception for queryTimeout is not thrown."); + throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof java.sql.SQLTimeoutException)) { throw e; } - assertEquals(e.getMessage(), "The query has timed out.", "Invalid exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_queryTimedOut"), TestResource.getResource("R_invalidExceptionMessage")); } try{ conn.createStatement().execute("SELECT @@version"); }catch (Exception e) { - fail("Unexpected error message occured! "+ e.toString() ); + fail(TestResource.getResource("R_unexpectedErrorMessage") + e.toString() ); } } @@ -136,18 +137,18 @@ public void testCancelQueryTimeout() throws Exception { try { SQLServerStatement statement = (SQLServerStatement) conn.createStatement(); statement.execute("exec " + waitForDelaySPName); - throw new Exception("Exception for queryTimeout is not thrown."); + throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof java.sql.SQLTimeoutException)) { throw e; } - assertEquals(e.getMessage(), "The query has timed out.", "Invalid exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_queryTimedOut"), TestResource.getResource("R_invalidExceptionMessage")); } try{ conn.createStatement().execute("SELECT @@version"); }catch (Exception e) { - fail("Unexpected error message occured! "+ e.toString() ); + fail(TestResource.getResource("R_unexpectedErrorMessage") + e.toString() ); } } @@ -169,18 +170,18 @@ public void testCancelQueryTimeoutOnStatement() throws Exception { statement.setQueryTimeout(waitForDelaySeconds/2); statement.setCancelQueryTimeout(waitForDelaySeconds); statement.execute("exec " + waitForDelaySPName); - throw new Exception("Exception for queryTimeout is not thrown."); + throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof java.sql.SQLTimeoutException)) { throw e; } - assertEquals(e.getMessage(), "The query has timed out.", "Invalid exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_queryTimedOut"), TestResource.getResource("R_invalidExceptionMessage")); } try{ conn.createStatement().execute("SELECT @@version"); }catch (Exception e) { - fail("Unexpected error message occured! "+ e.toString() ); + fail(TestResource.getResource("R_unexpectedErrorMessage") + e.toString() ); } } @@ -199,18 +200,18 @@ public void testSocketTimeout() throws Exception { try { conn.createStatement().execute("exec " + waitForDelaySPName); - throw new Exception("Exception for socketTimeout is not thrown."); + throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { throw e; } - assertEquals(e.getMessage(), "Read timed out", "Invalid exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_readTimedOut"), TestResource.getResource("R_invalidExceptionMessage")); } try{ conn.createStatement().execute("SELECT @@version"); }catch (SQLException e) { - assertEquals(e.getMessage(), "The connection is closed.", "Invalid exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_connectionIsClosed"), TestResource.getResource("R_invalidExceptionMessage")); } } 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 8b99699b1..6b3cccbf4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java @@ -22,6 +22,7 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.SQLServerConnection; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; @RunWith(JUnitPlatform.class) @@ -51,7 +52,7 @@ public void testWarnings() throws SQLException { break; } } - assertTrue(found, "warning : '" + warn.toString() + "' not found!"); + assertTrue(found, TestResource.getResource("R_warningsNotFound") + ": " + warn.toString()); warn = warn.getNextWarning(); found = false; } @@ -59,8 +60,8 @@ public void testWarnings() throws SQLException { conn.setClientInfo("prop7", ""); warn = conn.getWarnings(); - assertTrue(warn.toString().contains("prop7"), "Warnings not found!"); + assertTrue(warn.toString().contains("prop7"), TestResource.getResource("R_warningsNotFound")); warn = warn.getNextWarning(); - assertEquals(null, warn, "Warnings found!"); + assertEquals(null, warn, TestResource.getResource("R_warningsFound")); } } 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 01a683117..403d876e2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java @@ -25,6 +25,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -45,10 +46,6 @@ public class DatabaseMetaDataForeignKeyTest extends AbstractTest { private static String schema = null; private static String catalog = null; - private static final String EXPECTED_ERROR_MESSAGE = "An object or column name is missing or empty."; - private static final String EXPECTED_ERROR_MESSAGE2 = "The database name component of the object qualifier must be the name of the current database."; - - @BeforeAll private static void setupVariation() throws SQLException { conn = (SQLServerConnection) DriverManager.getConnection(connectionString); @@ -113,10 +110,10 @@ public void testGetImportedKeys() throws SQLException { try { dmd.getImportedKeys("", schema, table1); - fail("Exception is not thrown."); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertTrue(e.getMessage().startsWith(EXPECTED_ERROR_MESSAGE2)); + assertTrue(e.getMessage().startsWith(TestResource.getResource("R_dbNameIsCurrentDB"))); } } @@ -145,7 +142,7 @@ private void validateGetImportedKeysResults(SQLServerResultSet rs) throws SQLExc rowCount++; if(expectedRowCount != rowCount) { - assertEquals(expectedRowCount, rowCount, "number of foreign key entries is incorrect."); + assertEquals(expectedRowCount, rowCount, TestResource.getResource("R_numKeysIncorrect")); } } @@ -187,10 +184,10 @@ public void testGetExportedKeys() throws SQLException { try { dmd.getExportedKeys("", schema, pkTable); - fail("Exception is not thrown."); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertTrue(e.getMessage().startsWith(EXPECTED_ERROR_MESSAGE2)); + assertTrue(e.getMessage().startsWith(TestResource.getResource("R_dbNameIsCurrentDB"))); } } } @@ -234,11 +231,11 @@ public void testGetCrossReference() throws SQLException { try { dmd.getCrossReference("", schema, pkTable, "", schema, fkTable); - fail("Exception is not thrown."); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertEquals(EXPECTED_ERROR_MESSAGE2, e.getMessage()); + assertEquals(TestResource.getResource("R_dbNameIsCurrentDB"), e.getMessage()); } } } -} \ No newline at end of file +} 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 fdc3d917a..515dd9d62 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java @@ -25,6 +25,7 @@ import java.sql.SQLException; import java.util.jar.Attributes; import java.util.jar.Manifest; +import java.text.MessageFormat; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -32,6 +33,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData; import com.microsoft.sqlserver.jdbc.StringUtils; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -73,7 +75,7 @@ public void testDriverVersion() throws SQLException, IOException { File f = new File(manifestFile); - assumeTrue(f.exists(), "Manifest file does not exist on classpath so ignoring test"); + assumeTrue(f.exists(), TestResource.getResource("R_manifestNotFound")); InputStream in = new BufferedInputStream(new FileInputStream(f)); Manifest manifest = new Manifest(in); @@ -99,10 +101,11 @@ public void testDriverVersion() throws SQLException, IOException { if (isSnapshot) { assertTrue(intDriverVersion < intBuildVersion, - "In case of SNAPSHOT version, build version should be always greater than BuildVersion"); + TestResource.getResource("R_buildVersionError")); } else { - assertTrue(intDriverVersion == intBuildVersion, "For NON SNAPSHOT versions build & driver versions should match."); + assertTrue(intDriverVersion == intBuildVersion, + TestResource.getResource("R_buildVersionError")); } } @@ -117,7 +120,7 @@ public void testGetURL() throws SQLException { DatabaseMetaData databaseMetaData = connection.getMetaData(); String url = databaseMetaData.getURL(); url = url.toLowerCase(); - assertFalse(url.contains("password"), "Get URL should not have password attribute / property."); + assertFalse(url.contains("password"), TestResource.getResource("R_getURLContainsPwd")); } /** @@ -150,10 +153,10 @@ else if (connectionString.contains("user")) { String userFromConnectionString = connectionString.substring(startIndex, endIndex); String userName = databaseMetaData.getUserName(); - assertNotNull(userName, "databaseMetaData.getUserName() should not be null"); + assertNotNull(userName, TestResource.getResource("R_userNameNull")); assertTrue(userName.equalsIgnoreCase(userFromConnectionString), - "databaseMetaData.getUserName() should match with UserName from Connection String."); + TestResource.getResource("R_userNameNotMatch")); } /** @@ -166,8 +169,10 @@ public void testDBSchema() throws SQLException { ResultSet rs = databaseMetaData.getSchemas(); + MessageFormat form = new MessageFormat(TestResource.getResource("R_nameEmpty")); + Object[] msgArgs = {"Schema"}; while (rs.next()) { - assertTrue(!StringUtils.isEmpty(rs.getString(1)), "Schema Name should not be Empty"); + assertTrue(!StringUtils.isEmpty(rs.getString(1)), form.format(msgArgs)); } } @@ -182,13 +187,17 @@ public void testDBTables() throws SQLException { ResultSet rsCatalog = databaseMetaData.getCatalogs(); - assertTrue(rsCatalog.next(), "We should get atleast one catalog"); + MessageFormat form1 = new MessageFormat(TestResource.getResource("R_atLeastOneFound")); + Object[] msgArgs1 = {"catalog"}; + assertTrue(rsCatalog.next(), form1.format(msgArgs1)); String[] types = {"TABLE"}; ResultSet rs = databaseMetaData.getTables(rsCatalog.getString("TABLE_CAT"), null, "%", types); + MessageFormat form2 = new MessageFormat(TestResource.getResource("R_nameEmpty")); + Object[] msgArgs2 = {"Table"}; while (rs.next()) { - assertTrue(!StringUtils.isEmpty(rs.getString("TABLE_NAME")),"Table Name should not be Empty"); + assertTrue(!StringUtils.isEmpty(rs.getString("TABLE_NAME")), form2.format(msgArgs2)); } } @@ -208,22 +217,26 @@ public void testGetDBColumn() throws SQLException { ResultSet rs = databaseMetaData.getTables(null, null, "%", types); //Fetch one table - assertTrue(rs.next(), "At least one table should be found"); + MessageFormat form1 = new MessageFormat(TestResource.getResource("R_atLeastOneFound")); + Object[] msgArgs1 = {"table"}; + assertTrue(rs.next(), form1.format(msgArgs1)); //Go through all columns. ResultSet rs1 = databaseMetaData.getColumns(null, null, rs.getString("TABLE_NAME"), "%"); + MessageFormat form2 = new MessageFormat(TestResource.getResource("R_nameEmpty")); + Object[][] msgArgs2 = {{"Category"}, {"SCHEMA"}, {"Table"}, {"COLUMN"}, {"Data Type"}, {"Type"}, {"Column Size"}, {"Nullable value"}, {"IS_NULLABLE"}, {"IS_AUTOINCREMENT"}}; while (rs1.next()) { - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_CAT")), "Category Name should not be Empty"); // 1 - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_SCHEM")), "SCHEMA Name should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_NAME")), "Table Name should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_NAME")), "COLUMN NAME should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("DATA_TYPE")), "Data Type should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("TYPE_NAME")), "Data Type Name should not be Empty"); // 6 - assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_SIZE")), "Column Size should not be Empty"); // 7 - assertTrue(!StringUtils.isEmpty(rs1.getString("NULLABLE")), "Nullable value should not be Empty"); // 11 - assertTrue(!StringUtils.isEmpty(rs1.getString("IS_NULLABLE")), "Nullable value should not be Empty"); // 18 - assertTrue(!StringUtils.isEmpty(rs1.getString("IS_AUTOINCREMENT")), "Nullable value should not be Empty"); // 22 + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_CAT")), form2.format(msgArgs2[0])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_SCHEM")), form2.format(msgArgs2[1])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_NAME")), form2.format(msgArgs2[2])); + assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_NAME")), form2.format(msgArgs2[3])); + assertTrue(!StringUtils.isEmpty(rs1.getString("DATA_TYPE")), form2.format(msgArgs2[4])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TYPE_NAME")), form2.format(msgArgs2[5])); + assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_SIZE")), form2.format(msgArgs2[6])); + assertTrue(!StringUtils.isEmpty(rs1.getString("NULLABLE")), form2.format(msgArgs2[7])); // 11 + assertTrue(!StringUtils.isEmpty(rs1.getString("IS_NULLABLE")), form2.format(msgArgs2[8])); // 18 + assertTrue(!StringUtils.isEmpty(rs1.getString("IS_AUTOINCREMENT")), form2.format(msgArgs2[9])); // 22 } } @@ -242,21 +255,24 @@ public void testGetColumnPrivileges() throws SQLException { ResultSet rsTables = databaseMetaData.getTables(null, null, "%", types); //Fetch one table - assertTrue(rsTables.next(), "At least one table should be found"); + MessageFormat form1 = new MessageFormat(TestResource.getResource("R_atLeastOneFound")); + Object[] msgArgs1 = {"table"}; + assertTrue(rsTables.next(), form1.format(msgArgs1)); //Go through all columns. ResultSet rs1 = databaseMetaData.getColumnPrivileges(null, null, rsTables.getString("TABLE_NAME"), "%"); + MessageFormat form2 = new MessageFormat(TestResource.getResource("R_nameEmpty")); + Object[][] msgArgs2 = {{"Category"}, {"SCHEMA"}, {"Table"}, {"COLUMN"}, {"GRANTOR"}, {"GRANTEE"}, {"PRIVILEGE"}, {"IS_GRANTABLE"}}; while(rs1.next()) { - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_CAT")),"Category Name should not be Empty"); //1 - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_SCHEM")),"SCHEMA Name should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_NAME")),"Table Name should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_NAME")),"COLUMN NAME should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("GRANTOR")),"GRANTOR should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("GRANTEE")),"GRANTEE should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("PRIVILEGE")),"PRIVILEGE should not be Empty"); - assertTrue(!StringUtils.isEmpty(rs1.getString("IS_GRANTABLE")),"IS_GRANTABLE should be YES / NO"); - + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_CAT")), form2.format(msgArgs2[0])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_SCHEM")), form2.format(msgArgs2[1])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_NAME")), form2.format(msgArgs2[2])); + assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_NAME")), form2.format(msgArgs2[3])); + assertTrue(!StringUtils.isEmpty(rs1.getString("GRANTOR")), form2.format(msgArgs2[4])); + assertTrue(!StringUtils.isEmpty(rs1.getString("GRANTEE")), form2.format(msgArgs2[5])); + assertTrue(!StringUtils.isEmpty(rs1.getString("PRIVILEGE")), form2.format(msgArgs2[6])); + assertTrue(!StringUtils.isEmpty(rs1.getString("IS_GRANTABLE")), form2.format(msgArgs2[7])); } } @@ -271,8 +287,8 @@ public void testGetFunctionsWithWrongParams() throws SQLException { try { DatabaseMetaData databaseMetaData = connection.getMetaData(); databaseMetaData.getFunctions("", null, "xp_%"); - assertTrue(false,"As we are not supplying schema it should fail."); - }catch(Exception ae) { + assertTrue(false, TestResource.getResource("R_noSchemaShouldFail")); + } catch(Exception ae) { } } @@ -286,14 +302,16 @@ public void testGetFunctions() throws SQLException { DatabaseMetaData databaseMetaData = connection.getMetaData(); ResultSet rs = databaseMetaData.getFunctions(null, null, "xp_%"); + MessageFormat form = new MessageFormat(TestResource.getResource("R_nameNull")); + Object[][] msgArgs = {{"FUNCTION_CAT"}, {"FUNCTION_SCHEM"}, {"FUNCTION_NAME"}, {"NUM_INPUT_PARAMS"}, {"NUM_OUPUT_PARAMS"}, {"NUM_RESULT_SETS"}, {"FUNCTION_TYPE"}}; while(rs.next()) { - assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_CAT")),"FUNCTION_CAT should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_SCHEM")),"FUNCTION_SCHEM should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_NAME")),"FUNCTION_NAME should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("NUM_INPUT_PARAMS")),"NUM_INPUT_PARAMS should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("NUM_OUTPUT_PARAMS")),"NUM_OUTPUT_PARAMS should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("NUM_RESULT_SETS")),"NUM_RESULT_SETS should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_TYPE")),"FUNCTION_TYPE should not be NULL"); + assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_CAT")), form.format(msgArgs[0])); + assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_SCHEM")), form.format(msgArgs[1])); + assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_NAME")), form.format(msgArgs[2])); + assertTrue(!StringUtils.isEmpty(rs.getString("NUM_INPUT_PARAMS")), form.format(msgArgs[3])); + assertTrue(!StringUtils.isEmpty(rs.getString("NUM_OUTPUT_PARAMS")), form.format(msgArgs[4])); + assertTrue(!StringUtils.isEmpty(rs.getString("NUM_RESULT_SETS")), form.format(msgArgs[5])); + assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_TYPE")), form.format(msgArgs[6])); } rs.close(); } @@ -307,22 +325,26 @@ public void testGetFunctionColumns() throws SQLException{ DatabaseMetaData databaseMetaData = connection.getMetaData(); ResultSet rsFunctions = databaseMetaData.getFunctions(null, null, "%"); - //Fetch one Function - assertTrue(rsFunctions.next(), "At least one function should be found"); + //Fetch one Function + MessageFormat form1 = new MessageFormat(TestResource.getResource("R_atLeastOneFound")); + Object[] msgArgs1 = {"function"}; + assertTrue(rsFunctions.next(), form1.format(msgArgs1)); //Go through all columns. ResultSet rs = databaseMetaData.getFunctionColumns(null, null, rsFunctions.getString("FUNCTION_NAME"), "%"); + MessageFormat form2 = new MessageFormat(TestResource.getResource("R_nameNull")); + Object[][] msgArgs2 = {{"FUNCTION_CAT"}, {"FUNCTION_SCHEM"}, {"FUNCTION_NAME"}, {"COLUMN_NAME"}, {"COLUMN_TYPE"}, {"DATA_TYPE"}, {"TYPE_NAME"}, {"NULLABLE"}, {"IS_NULLABLE"}}; while(rs.next()) { - assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_CAT")),"FUNCTION_CAT should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_SCHEM")),"FUNCTION_SCHEM should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_NAME")),"FUNCTION_NAME should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("COLUMN_NAME")),"COLUMN_NAME should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("COLUMN_TYPE")),"COLUMN_TYPE should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("DATA_TYPE")),"DATA_TYPE should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("TYPE_NAME")),"TYPE_NAME should not be NULL"); - assertTrue(!StringUtils.isEmpty(rs.getString("NULLABLE")),"NULLABLE should not be NULL"); //12 - assertTrue(!StringUtils.isEmpty(rs.getString("IS_NULLABLE")),"IS_NULLABLE should not be NULL"); //19 + assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_CAT")), form2.format(msgArgs2[0])); + assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_SCHEM")), form2.format(msgArgs2[1])); + assertTrue(!StringUtils.isEmpty(rs.getString("FUNCTION_NAME")), form2.format(msgArgs2[2])); + assertTrue(!StringUtils.isEmpty(rs.getString("COLUMN_NAME")), form2.format(msgArgs2[3])); + assertTrue(!StringUtils.isEmpty(rs.getString("COLUMN_TYPE")), form2.format(msgArgs2[4])); + assertTrue(!StringUtils.isEmpty(rs.getString("DATA_TYPE")), form2.format(msgArgs2[5])); + assertTrue(!StringUtils.isEmpty(rs.getString("TYPE_NAME")), form2.format(msgArgs2[6])); + assertTrue(!StringUtils.isEmpty(rs.getString("NULLABLE")), form2.format(msgArgs2[7])); //12 + assertTrue(!StringUtils.isEmpty(rs.getString("IS_NULLABLE")), form2.format(msgArgs2[8])); //19 } } 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 71c2b68e3..886cb36cc 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -31,9 +31,11 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; + /** * Test Geometry / Geography classes * @@ -338,7 +340,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 14"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"14"); } //Too many closing bracket @@ -348,7 +350,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 91"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"91"); } //Too many opening bracket @@ -358,7 +360,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 15"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"15"); } //Too many coordinates @@ -368,7 +370,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 23"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"23"); } //Too little coordinates @@ -378,7 +380,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 17"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"17"); } //Incorrect data type @@ -388,7 +390,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 14"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"14"); } // too many commas @@ -398,7 +400,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 35"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"35"); } // too little commas @@ -408,7 +410,7 @@ public void testIllegalCases() throws SQLException { testWkt(geoWKT); } catch (IllegalArgumentException e) { - assertEquals(e.getMessage(), "Illegal character at wkt position 35"); + assertEquals(e.getMessage(), TestResource.getResource("R_illegalCharWkt")+"35"); } } 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 63dcfa18d..76701bba2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -30,6 +30,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; import com.microsoft.sqlserver.testframework.util.RandomData; @@ -831,7 +832,7 @@ public void testUnsupportedDatatype() throws SQLException { rs.next(); try { rs.getObject(1); - fail("Should have thrown unssuported tds type exception"); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { assertTrue(e.getMessage().equalsIgnoreCase("Unexpected TDS type DATETIMEOFFSETN in SQL_VARIANT.")); 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 d51d7455f..e62a18dce 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java @@ -31,6 +31,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; import com.microsoft.sqlserver.testframework.sqlType.SqlDate; @@ -302,7 +303,8 @@ public void testLongVarChar() throws SQLException { assertTrue(e.getMessage().contains("SQL_VARIANT does not support string values of length greater than 8000.")); } catch (Exception e) { - fail("Test should have failed! mistakenly inserted string value of more than 8000 in sql-variant"); + // Test should have failed! mistakenly inserted string value of more than 8000 in sql-variant + fail(TestResource.getResource("R_unexpectedException")); } finally { if (null != pstmt) { @@ -522,4 +524,4 @@ public static void afterAll() throws SQLException { } -} \ No newline at end of file +} 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 422a30d25..b21430515 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java @@ -13,6 +13,7 @@ import java.net.SocketTimeoutException; import java.sql.DriverManager; import java.sql.SQLException; +import java.text.MessageFormat; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -20,6 +21,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord; import com.microsoft.sqlserver.jdbc.SQLServerConnection; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -44,8 +46,10 @@ public void testBulkCSVFileRecordExceptionCause() throws Exception { throw e; } - assertTrue(null != e.getCause(), "Cause should not be null."); - assertTrue(e.getCause() instanceof UnsupportedEncodingException, "Cause should be instance of UnsupportedEncodingException."); + assertTrue(null != e.getCause(), TestResource.getResource("R_causeShouldNotBeNull")); + MessageFormat form = new MessageFormat(TestResource.getResource("R_causeShouldBeInstance")); + Object[] msgArgs = {"UnsupportedEncodingException"}; + assertTrue(e.getCause() instanceof UnsupportedEncodingException, form.format(msgArgs)); } } @@ -71,15 +75,17 @@ public void testSocketTimeoutExceptionCause() throws Exception { try { conn.createStatement().execute("exec " + waitForDelaySPName); - throw new Exception("Exception for socketTimeout is not thrown."); + throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { throw e; } - assertTrue(null != e.getCause(), "Cause should not be null."); - assertTrue(e.getCause() instanceof SocketTimeoutException, "Cause should be instance of SocketTimeoutException."); + assertTrue(null != e.getCause(), TestResource.getResource("R_causeShouldNotBeNull")); + MessageFormat form = new MessageFormat(TestResource.getResource("R_causeShouldBeInstance")); + Object[] msgArgs = {"SocketTimeoutException"}; + assertTrue(e.getCause() instanceof SocketTimeoutException, form.format(msgArgs)); } } finally { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java index 41ddfd4c9..0b9c25b3d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java @@ -25,6 +25,8 @@ import com.microsoft.sqlserver.testframework.Utils; +import com.microsoft.sqlserver.jdbc.TestResource;; + /** * Class which will useful for checking if FIPS env. set or not. * @@ -71,21 +73,21 @@ public static void populateProperties() { */ @Test public void testFIPSOnOracle() throws Exception { - assumeTrue(ORACLE_JVM.equals(currentJVM), "Aborting test: As this is not Oracle Env. "); + assumeTrue(ORACLE_JVM.equals(currentJVM), TestResource.getResource("R_wrongEnv") + ORACLE_JVM); - assumeTrue("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), "Aborting test case as FIPS_ENV property is not set. "); + assumeTrue("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), TestResource.getResource("R_fipsPropertyNotSet")); - assertTrue(isFIPS("SunJSSE"), "FIPS Should be enabled"); + assertTrue(isFIPS("SunJSSE"), "FIPS " + TestResource.getResource("R_shouldBeEnabled")); // As JDK 1.7 is not supporting lambda for time being commenting. /* * assumingThat("NSSFIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> assertTrue(isFIPS("SunJSSE"), - * "FIPS should be Enabled."), () -> assertTrue(isFIPS("SunPKCS11-NSS"), "Testing"))); + * TestResource.getResource("R_shouldBeEnabled")), () -> assertTrue(isFIPS("SunPKCS11-NSS"), "Testing"))); * * assumingThat("BCFIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> assertTrue(isFIPS("SunJSSE"), - * "FIPS should be Enabled."), () -> assertTrue(isFIPS("BCFIPS"), "Testing"))); + * TestResource.getResource("R_shouldBeEnabled")), () -> assertTrue(isFIPS("BCFIPS"), "Testing"))); * - * assumingThat("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), ()-> assertTrue(isFIPS("SunJSSE"), "FIPS Should be enabled")); + * assumingThat("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), ()-> assertTrue(isFIPS("SunJSSE"), TestResource.getResource("R_shouldBeEnabled"))); */ } @@ -96,11 +98,11 @@ public void testFIPSOnOracle() throws Exception { */ @Test public void testFIPSOnIBM() throws Exception { - assumeTrue(IBM_JVM.equals(currentJVM), "Aborting test: As this is not IBM Env. "); + assumeTrue(IBM_JVM.equals(currentJVM), TestResource.getResource("R_wrongEnv") + IBM_JVM); - assumeTrue("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), "Aborting test case as FIPS is not enabled. "); + assumeTrue("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), TestResource.getResource("R_fipsPropertyNotSet")); - assertTrue(isFIPS("IBMJCEFIP"), "FIPS Should be enabled"); + assertTrue(isFIPS("IBMJCEFIP"), "FIPS " + TestResource.getResource("R_shouldBeEnabled")); // As JDK 1.7 is not supporting lambda for time being commenting. /* @@ -120,7 +122,7 @@ public void testFIPSOnIBM() throws Exception { @Test @Disabled public void testFIPSEnv() { - assumeTrue("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), "Aborting test: This is FIPS Enabled JVM"); + assumeTrue("FIPS".equals(Utils.getConfiguredProperty("FIPS_ENV")), TestResource.getResource("R_fipsPropertyNotSet")); // As JDK 1.7 is not supporting lambda for time being commenting. /* 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 66b88933f..67378152c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java @@ -22,6 +22,8 @@ import com.microsoft.sqlserver.testframework.PrepUtil; import com.microsoft.sqlserver.testframework.Utils; +import com.microsoft.sqlserver.jdbc.TestResource;; + /** * Test class for testing FIPS property settings. */ @@ -48,12 +50,12 @@ public void fipsTrustServerCertificateTest() throws Exception { Properties props = buildConnectionProperties(); props.setProperty("TrustServerCertificate", "true"); Connection con = PrepUtil.getConnection(connectionString, props); - Assertions.fail("It should fail as we are not passing appropriate params"); + Assertions.fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { Assertions.assertTrue( - e.getMessage().contains("Unable to verify FIPS mode settings."), - "Should create exception for invalid TrustServerCertificate value"); + e.getMessage().contains(TestResource.getResource("R_invalidFipsConfig")), + TestResource.getResource("R_invalidTrustCert")); } } @@ -68,12 +70,12 @@ public void fipsEncryptTest() throws Exception { Properties props = buildConnectionProperties(); props.setProperty("encrypt", "false"); Connection con = PrepUtil.getConnection(connectionString, props); - Assertions.fail("It should fail as we are not passing appropriate params"); + Assertions.fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { Assertions.assertTrue( - e.getMessage().contains("Unable to verify FIPS mode settings."), - "Should create exception for invalid encrypt value"); + e.getMessage().contains(TestResource.getResource("R_invalidFipsConfig")), + TestResource.getResource("R_invalidEncrypt")); } } @@ -123,12 +125,12 @@ public void fipsDatSourceEncrypt() { ds.setEncrypt(false); Connection con = ds.getConnection(); - Assertions.fail("It should fail as we are not passing appropriate params"); + Assertions.fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { Assertions.assertTrue( - e.getMessage().contains("Unable to verify FIPS mode settings."), - "Should create exception for invalid encrypt value"); + e.getMessage().contains(TestResource.getResource("R_invalidFipsConfig")), + TestResource.getResource("R_invalidEncrypt")); } } @@ -144,12 +146,12 @@ public void fipsDataSourceTrustServerCertificateTest() throws Exception { setDataSourceProperties(ds); ds.setTrustServerCertificate(true); Connection con = ds.getConnection(); - Assertions.fail("It should fail as we are not passing appropriate params"); + Assertions.fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { Assertions.assertTrue( - e.getMessage().contains("Unable to verify FIPS mode settings."), - "Should create exception for invalid TrustServerCertificate value"); + e.getMessage().contains(TestResource.getResource("R_invalidFipsConfig")), + TestResource.getResource("R_invalidTrustCert")); } } 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 c1c12a8d9..4db2eec83 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java @@ -26,6 +26,7 @@ import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.Utils; @@ -80,14 +81,14 @@ public void testAddBatch2() throws SQLException { updateCount = pstmt.executeBatch(); updateCountlen += updateCount.length; - assertTrue(updateCountlen == 5, "addBatch does not add the SQL Statements to Batch ,call to addBatch failed"); + assertTrue(updateCountlen == 5, TestResource.getResource("R_addBatchFailed")); String sPrepStmt1 = "select count(*) from esimple"; pstmt1 = connection.prepareStatement(sPrepStmt1); rs = pstmt1.executeQuery(); rs.next(); - assertTrue(rs.getInt(1) == 5, "affected rows does not match with batch size. Insert failed"); + assertTrue(rs.getInt(1) == 5, TestResource.getResource("R_insertBatchFailed")); pstmt1.close(); } @@ -106,7 +107,7 @@ public void testAddbatch2AEOnConnection() throws SQLException { @BeforeEach public void testSetup() throws TestAbortedException, Exception { assumeTrue(13 <= new DBConnection(connectionString).getServerVersion(), - "Aborting test case as SQL Server version is not compatible with Always encrypted "); + TestResource.getResource("R_Incompat_SQLServerVersion")); connection = DriverManager.getConnection(connectionString); SQLServerStatement stmt = (SQLServerStatement) connection.createStatement(); @@ -139,4 +140,4 @@ public static void terminateVariation() throws SQLException { connection.close(); } } -} \ No newline at end of file +} 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 05f36bdee..880ed7ef7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java @@ -25,6 +25,7 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; +import com.microsoft.sqlserver.jdbc.TestResource; /** * Tests with sql queries using preparedStatement without parameters @@ -68,7 +69,7 @@ public void createViewTest() throws SQLException { pstmt2.execute(); } catch (SQLException e) { - fail("Create/drop view with preparedStatement failed! Error message: " + e.getMessage()); + fail(TestResource.getResource("R_createDropViewFailed") + TestResource.getResource("R_errorMessage") + e.getMessage()); } finally { @@ -95,7 +96,7 @@ public void createSchemaTest() throws SQLException { pstmt2.execute(); } catch (SQLException e) { - fail("Create/drop schema with preparedStatement failed! Error message:" + e.getMessage()); + fail(TestResource.getResource("R_createDropSchemaFailed") + TestResource.getResource("R_errorMessage") + e.getMessage()); } finally { @@ -122,7 +123,7 @@ public void createTableTest() throws SQLException { pstmt2.execute(); } catch (SQLException e) { - fail("Create/drop table with preparedStatement failed! Error message:" + e.getMessage()); + fail(TestResource.getResource("R_createDropTableFailed") + TestResource.getResource("R_errorMessage") + e.getMessage()); } finally { @@ -151,7 +152,7 @@ public void alterTableTest() throws SQLException { pstmt3.execute(); } catch (SQLException e) { - fail("Create/drop/alter table with preparedStatement failed! Error message:" + e.getMessage()); + fail(TestResource.getResource("R_createDropAlterTableFailed") + TestResource.getResource("R_errorMessage") + e.getMessage()); } finally { @@ -185,7 +186,7 @@ public void grantTest() throws SQLException { pstmt4.execute(); } catch (SQLException e) { - fail("grant with preparedStatement failed! Error message:" + e.getMessage()); + fail(TestResource.getResource("R_grantFailed") + TestResource.getResource("R_errorMessage") + e.getMessage()); } finally { @@ -433,4 +434,4 @@ public static void cleanup() throws SQLException { } -} \ No newline at end of file +} 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 41118d594..dfe8a5cd2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java @@ -29,6 +29,8 @@ import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; +import com.microsoft.sqlserver.jdbc.TestResource;; + @RunWith(JUnitPlatform.class) public class TVPIssuesTest extends AbstractTest { @@ -78,11 +80,11 @@ public void testExceptionWithInvalidStoredProcedureName() throws Exception { SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connection.prepareCall(sql); try { Cstmt.setObject(1, rs); - throw new Exception("Expected Exception for invalied stored procedure name is not thrown."); + throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (e instanceof SQLException) { - assertTrue(e.getMessage().contains("Could not find stored procedure"), "Invalid Error Message."); + assertTrue(e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound")), TestResource.getResource("R_invalidErrorMessage") + e.toString()); } else { throw e; @@ -114,7 +116,7 @@ public void tryTVPPrecisionmissedissue315() throws Exception { private void testCharDestTable() throws SQLException, IOException { ResultSet rs = connection.createStatement().executeQuery("select * from " + desTable_varcharMax); while (rs.next()) { - assertEquals(rs.getString(1).length(), 4001, " The inserted length is truncated or not correct!"); + assertEquals(rs.getString(1).length(), 4001, TestResource.getResource("R_lengthTruncated")); } if (null != rs) { rs.close(); @@ -124,7 +126,7 @@ private void testCharDestTable() throws SQLException, IOException { private void testTime6DestTable() throws SQLException, IOException { ResultSet rs = connection.createStatement().executeQuery("select * from " + desTable_time_6); while (rs.next()) { - assertEquals(rs.getString(1), expectedTime6value, " The time value is truncated or not correct!"); + assertEquals(rs.getString(1), expectedTime6value, TestResource.getResource("R_timeValueTruncated")); } if (null != rs) { rs.close(); 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 8dbd7e368..2557031fb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java @@ -27,6 +27,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -204,7 +205,7 @@ public void testInvalidTVPName() throws SQLException { pstmt.execute(); } catch (SQLException e) { - if (!e.getMessage().contains("Cannot find data type")) { + if (!e.getMessage().contains(TestResource.getResource("R_dataTypeNotFound"))) { throw e; } } @@ -251,7 +252,7 @@ public void testInvalidStoredProcedureName() throws SQLException { pstmt.execute(); } catch (SQLException e) { - if (!e.getMessage().contains("Could not find stored procedure")) { + if (!e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound"))) { throw e; } } @@ -420,4 +421,4 @@ private void terminateVariation() throws SQLException { } } -} \ No newline at end of file +} 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 7182646b3..dd029ee1b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java @@ -7,7 +7,7 @@ */ package com.microsoft.sqlserver.jdbc.tvp; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.sql.SQLException; @@ -167,14 +167,9 @@ private void verify(DBResultSet rs) throws SQLException { String actualValue2 = rs.getString(2); String actualValue3 = rs.getString(3); - assertTrue(actualValue1.trim().equals(expectecValue1), - "actual value does not match expected value." + "\n\tExpected value: " + expectecValue1 + "\n\tActual value: " + actualValue1); - - assertTrue(actualValue2.trim().equals(expectecValue2), - "actual value does not match expected value." + "\n\tExpected value: " + expectecValue2 + "\n\tActual value: " + actualValue2); - - assertTrue(actualValue3.trim().equals(expectecValue3), - "actual value does not match expected value." + "\n\tExpected value: " + expectecValue3 + "\n\tActual value: " + actualValue3); + assertEquals(actualValue1.trim(), expectecValue1); + assertEquals(actualValue2.trim(), expectecValue2); + assertEquals(actualValue3.trim(), expectecValue3); } } @@ -233,4 +228,4 @@ private void terminateVariation() throws SQLException { } } -} \ No newline at end of file +} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/TestSavepoint.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/TestSavepoint.java index 34db2491f..18e7d97bf 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/TestSavepoint.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/TestSavepoint.java @@ -15,12 +15,14 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.text.MessageFormat; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.SQLServerSavepoint; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.util.RandomUtil; @@ -44,14 +46,16 @@ public void testSavePointName() throws SQLException { connection.setAutoCommit(false); SQLServerSavepoint savePoint = (SQLServerSavepoint) connection.setSavepoint(savePointName); - assertTrue(savePointName.equals(savePoint.getSavepointName()), "Savepoint Name should be same."); + MessageFormat form = new MessageFormat(TestResource.getResource("R_savePointError")); + Object[][] msgArgs = {{"Name", "same"}, {"Label", "Savepoint Name"}, {"SQLServerSavepoint.isNamed", "true"}}; - assertTrue(savePointName.equals(savePoint.getLabel()), "Savepoint Label should be same as Savepoint Name."); + assertTrue(savePointName.equals(savePoint.getSavepointName()), form.format(msgArgs[0])); + assertTrue(savePointName.equals(savePoint.getLabel()), form.format(msgArgs[1])); + assertTrue(savePoint.isNamed(), form.format(msgArgs[2])); - assertTrue(savePoint.isNamed(), "SQLServerSavepoint.isNamed should be true"); try { savePoint.getSavepointId(); - assertTrue(false, "Expecting Exception as trying to get SavePointId when we created savepoint with name"); + assertTrue(false, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { } @@ -71,16 +75,21 @@ public void testSavePointId() throws SQLException { connection.setAutoCommit(false); SQLServerSavepoint savePoint = (SQLServerSavepoint) connection.setSavepoint(null); - assertNotNull(savePoint.getLabel(), "Savepoint Label should not be null."); + + MessageFormat form = new MessageFormat(TestResource.getResource("R_savePointError")); + Object[][] msgArgs = {{"label", "not null"}, {"id", "not 0"}}; + assertNotNull(savePoint.getLabel(), form.format(msgArgs[0])); try { + savePoint.getSavepointName(); - assertTrue(false, "Expecting Exception as trying to get SavePointname when we created savepoint without name"); + // Expecting Exception as trying to get SavePointname when we created savepoint without name + assertTrue(false, TestResource.getResource("R_shouldThrowException")); } catch (SQLException e) { } - assertTrue(savePoint.getSavepointId() != 0, "SavePoint should not be 0"); + assertTrue(savePoint.getSavepointId() != 0, form.format(msgArgs[1])); connection.rollback(); } @@ -97,7 +106,8 @@ public void testSavePointIsNamed() throws SQLException { SQLServerSavepoint savePoint = (SQLServerSavepoint) connection.setSavepoint(null); - assertFalse(savePoint.isNamed(), "SQLServerSavepoint.isNamed should be false as savePoint is created without name"); + // SQLServerSavepoint.isNamed should be false as savePoint is created without name" + assertFalse(savePoint.isNamed(), TestResource.getResource("R_shouldThrowException")); connection.rollback(); } @@ -115,7 +125,8 @@ public void testSavePointWithAutoCommit() throws SQLException { try { connection.setSavepoint(null); - assertTrue(false, "Expecting Exception as can not set SetPoint when AutoCommit mode is set to true."); + // Expecting Exception as can not set SetPoint when AutoCommit mode is set to true + assertTrue(false, TestResource.getResource("R_shouldThrowException")); } catch (SQLException e) { } 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 232eb49b7..6b44eb860 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 @@ -40,6 +40,8 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.TestResource; + import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBCoercion; @@ -183,8 +185,8 @@ else if (lobClass == Blob.class) // Case 1: Invalid length value is passed as LOB length if (streamLength < 0 || streamLength == Long.MAX_VALUE) { // Applies to all LOB types ("The length {0} is not valid} - assertTrue(e.getMessage().startsWith("The length"), "Unexpected message thrown : " + e.getMessage()); - assertTrue(e.getMessage().endsWith("is not valid."), "Unexpected message thrown : " + e.getMessage()); + assertTrue(e.getMessage().startsWith("The length"), TestResource.getResource("R_unexpectedExceptionContent") + ": " + e.getMessage()); + assertTrue(e.getMessage().endsWith("is not valid."), TestResource.getResource("R_unexpectedExceptionContent") + ": " + e.getMessage()); verified = true; } @@ -203,12 +205,12 @@ else if (lobClass == Blob.class) } if (!verified) { // Odd CharacterStream length will throw this exception - if (!e.getMessage().contains("The stream value is not the specified length. The specified length was")) + if (!e.getMessage().contains(TestResource.getResource("R_badStreamLength"))) { if (lobClass == DBCharacterStream.class || lobClass == DBBinaryStream.class) - assertTrue(e.getSQLState() != null, "SQLState should not be null"); - assertTrue(e.getMessage().contains("An error occurred while reading the value from the stream object. Error:")); + assertTrue(e.getSQLState() != null, TestResource.getResource("RSQLStateNull")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_streamReadError"))); } } @@ -258,14 +260,14 @@ private void testFreedBlobs(Class lobClass, try { stream = blob.getBinaryStream(); } catch (SQLException e) { - assertTrue(e.getMessage().contains("This Blob object has been freed.")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_blobFreed"))); } } rs.close(); try { stream = blob.getBinaryStream(); } catch (SQLException e) { - assertTrue(e.getMessage().contains("This Blob object has been freed.")); + assertTrue(e.getMessage().contains(TestResource.getResource("R_blobFreed"))); } } catch (Exception e) { @@ -308,7 +310,7 @@ private void testMultipleClose(Class streamClass) throws Exception { continue; Object stream = rs.getXXX(i + 1, streamClass); if (stream == null) { - assertEquals(stream, rs.getObject(i + 1), "Stream is null when data is not"); + assertEquals(stream, rs.getObject(i + 1), TestResource.getResource("R_streamNull")); } else { // close the stream twice @@ -652,7 +654,7 @@ else if (lob instanceof Clob) ps.setClob(index, (Clob) lob); else ps.setBlob(index, (Blob) lob); - assertEquals(ps.executeUpdate(), 1, "ExecuteUpdate did not return the correct updateCount"); + assertEquals(ps.executeUpdate(), 1, TestResource.getResource("R_incorrectUpdateCount")); } private void updateResultSet(ResultSet rs, @@ -729,4 +731,4 @@ private static void dropTables(DBTable table) throws SQLException { stmt.executeUpdate("if object_id('" + table.getEscapedTableName() + "','U') is not null" + " drop table " + table.getEscapedTableName()); } -} \ No newline at end of file +} 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 38c16ce95..1297446ca 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 @@ -28,6 +28,7 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; @@ -140,7 +141,7 @@ public void Repro47239() throws SQLException { log.fine("" + updateCount + ","); } log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), "Test interleaved inserts and warnings"); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_testInterleaved")); expectedUpdateCounts = new int[] {-3, 1, 1, 1}; stmt.addBatch(error); @@ -160,7 +161,7 @@ public void Repro47239() throws SQLException { log.fine("" + updateCount + ","); } log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), "Test error followed by inserts"); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollowInserts")); // 50280 expectedUpdateCounts = new int[] {1, -3}; stmt.addBatch(insertStmt); @@ -177,7 +178,7 @@ public void Repro47239() throws SQLException { log.fine("" + updateCount + ","); } log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), "Test insert followed by non-fatal error (50280)"); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollow50280")); // Test "soft" errors conn.setAutoCommit(false); @@ -187,12 +188,13 @@ public void Repro47239() throws SQLException { stmt.addBatch(insertStmt); try { stmt.executeBatch(); - assertEquals(true, false, "Soft error test: executeBatch unexpectedly succeeded"); + // 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(), "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"); + TestResource.getResource("R_incorrectUpdateCount")); } conn.rollback(); @@ -205,12 +207,12 @@ public void Repro47239() throws SQLException { stmt.executeBatch(); } catch (BatchUpdateException bue) { - assertThat(bue.getMessage(), containsString("Syntax error converting date")); + assertThat(bue.getMessage(), containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); // CTestLog.CompareStartsWith(bue.getMessage(), "Syntax error converting date", "Transaction rollback with conversion error threw wrong // BatchUpdateException"); } catch (SQLException e) { - assertThat(e.getMessage(), containsString("Conversion failed when converting date")); + 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"); } @@ -237,19 +239,22 @@ public void Repro47239() throws SQLException { stmt.addBatch(insertStmt); try { stmt.executeBatch(); - assertEquals(false, true, "Test fatal errors batch execution succeeded (should have failed)"); + // Test fatal errors batch execution succeeded (should have failed) + assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); } catch (BatchUpdateException bue) { - assertEquals(false, true, "Test fatal errors returned BatchUpdateException rather than SQLException"); + // 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"), "Test fatal errors"); + assertTrue(actualExceptionText.equalsIgnoreCase("Connection reset"), TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); } else { - assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), "Test fatal errors"); + assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); } } } @@ -272,7 +277,7 @@ public void Repro47239() throws SQLException { @DisplayName("Regression test for using 'large' methods") public void Repro47239large() throws Exception { - assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); + assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), TestResource.getResource("R_incompatJDBC")); // the DBConnection for detecting whether the server is SQL Azure or SQL Server. con = DriverManager.getConnection(connectionString); final String warning; @@ -344,7 +349,7 @@ public void Repro47239large() throws Exception { log.fine("" + updateCount + ","); } log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), "Test interleaved inserts and warnings"); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_testInterleaved")); expectedUpdateCounts = new long[] {-3, 1, 1, 1}; stmt.addBatch(error); @@ -364,7 +369,7 @@ public void Repro47239large() throws Exception { log.fine("" + updateCount + ","); } log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), "Test error followed by inserts"); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollowInserts")); // 50280 expectedUpdateCounts = new long[] {1, -3}; @@ -382,7 +387,7 @@ public void Repro47239large() throws Exception { log.fine("" + updateCount + ","); } log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), "Test insert followed by non-fatal error (50280)"); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollow50280")); // Test "soft" errors conn.setAutoCommit(false); @@ -392,12 +397,15 @@ public void Repro47239large() throws Exception { stmt.addBatch(insertStmt); try { stmt.executeLargeBatch(); - assertEquals(false, true, "Soft error test: executeLargeBatch unexpectedly succeeded"); + // Soft error test: executeLargeBatch unexpectedly succeeded + assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); } catch (BatchUpdateException bue) { - assertEquals("A result set was generated for update.", bue.getMessage(), "Soft error test: wrong error message in BatchUpdateException"); + // 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, - "Soft error test: wrong update counts in BatchUpdateException"); + TestResource.getResource("R_incorrectUpdateCount")); } conn.rollback(); @@ -410,10 +418,10 @@ public void Repro47239large() throws Exception { stmt.executeLargeBatch(); } catch (BatchUpdateException bue) { - assertThat(bue.getMessage(), containsString("Syntax error converting date")); + assertThat(bue.getMessage(), containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); } catch (SQLException e) { - assertThat(e.getMessage(), containsString("Conversion failed when converting date")); + assertThat(e.getMessage(), containsString(TestResource.getResource("R_dateConvertError"))); } conn.setAutoCommit(true); @@ -437,19 +445,21 @@ public void Repro47239large() throws Exception { stmt.addBatch(insertStmt); try { stmt.executeLargeBatch(); - assertEquals(false, true, "Test fatal errors batch execution succeeded (should have failed)"); + // Test fatal errors batch execution succeeded (should have failed) + assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); } catch (BatchUpdateException bue) { - assertEquals(false, true, "Test fatal errors returned BatchUpdateException rather than SQLException"); + // 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"), "Test fatal errors"); + assertTrue(actualExceptionText.equalsIgnoreCase("Connection reset"), TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); } else { - assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), "Test fatal errors"); + assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); } } 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 85eb4a91b..c9de04a67 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 @@ -27,6 +27,7 @@ import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.Utils; @@ -77,7 +78,7 @@ public void testAddBatch1() { int[] updateCount = pstmt.executeBatch(); int updateCountlen = updateCount.length; - assertTrue(updateCountlen == 3, "addBatch does not add the SQL Statements to Batch ,call to addBatch failed"); + assertTrue(updateCountlen == 3, TestResource.getResource("R_addBatchFailed") + ": " + TestResource.getResource("R_incorrectUpdateCount")); String sPrepStmt1 = "select count(*) from ctstable2 where TYPE_ID=?"; @@ -96,18 +97,18 @@ public void testAddBatch1() { for (int j = 0; j < updateCount.length; j++) { if (updateCount[j] != retValue[j] && updateCount[j] != Statement.SUCCESS_NO_INFO) { - fail("affected row count does not match with the updateCount value, Call to addBatch is Failed!"); + fail(TestResource.getResource("R_incorrectUpdateCount")); } } } catch (BatchUpdateException b) { - fail("BatchUpdateException : Call to addBatch is Failed!"); + fail(TestResource.getResource("R_addBatchFailed") + ": " + b.getMessage()); } catch (SQLException sqle) { - fail("Call to addBatch is Failed!"); + fail(TestResource.getResource("R_addBatchFailed") + ": " + sqle.getMessage()); } catch (Exception e) { - fail("Call to addBatch is Failed!"); + fail(TestResource.getResource("R_addBatchFailed") + ": " + e.getMessage()); } } @@ -118,7 +119,7 @@ public void testAddBatch1() { public void testExecuteBatch1() { int i = 0; int retValue[] = {0, 0, 0}; - int updCountLength = 0; + int updateCountlen = 0; try { String sPrepStmt = "update ctstable2 set PRICE=PRICE*20 where TYPE_ID=?"; @@ -133,9 +134,9 @@ public void testExecuteBatch1() { pstmt.addBatch(); int[] updateCount = pstmt.executeBatch(); - updCountLength = updateCount.length; + updateCountlen = updateCount.length; - assertTrue(updCountLength == 3, "executeBatch does not execute the Batch of SQL statements, Call to executeBatch is Failed!"); + assertTrue(updateCountlen == 3, TestResource.getResource("R_executeBatchFailed") + ": " + TestResource.getResource("R_incorrectUpdateCount")); String sPrepStmt1 = "select count(*) from ctstable2 where TYPE_ID=?"; @@ -152,18 +153,18 @@ public void testExecuteBatch1() { for (int j = 0; j < updateCount.length; j++) { if (updateCount[j] != retValue[j] && updateCount[j] != Statement.SUCCESS_NO_INFO) { - fail("executeBatch does not execute the Batch of SQL statements, Call to executeBatch is Failed!"); + fail(TestResource.getResource("R_executeBatchFailed") + ": " + TestResource.getResource("R_incorrectUpdateCount")); } } } catch (BatchUpdateException b) { - fail("BatchUpdateException : Call to executeBatch is Failed!"); + fail(TestResource.getResource("R_executeBatchFailed") + ": " + b.getMessage()); } catch (SQLException sqle) { - fail("Call to executeBatch is Failed!"); + fail(TestResource.getResource("R_executeBatchFailed") + ": " + sqle.getMessage()); } catch (Exception e) { - fail("Call to executeBatch is Failed!"); + fail(TestResource.getResource("R_executeBatchFailed") + ": " + e.getMessage()); } } @@ -192,7 +193,7 @@ private static void createTable() throws SQLException { @BeforeAll public static void testSetup() throws TestAbortedException, Exception { assumeTrue(13 <= new DBConnection(connectionString).getServerVersion(), - "Aborting test case as SQL Server version is not compatible with Always encrypted "); + TestResource.getResource("R_Incompat_SQLServerVersion")); connection = DriverManager.getConnection(connectionString + ";columnEncryptionSetting=Enabled;"); stmt = (SQLServerStatement) connection.createStatement(); dropTable(); @@ -225,4 +226,4 @@ public static void terminateVariation() throws SQLException { rs.close(); } } -} \ No newline at end of file +} 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 1abcf471c..5115a1f7f 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 @@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.fail; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -37,7 +38,6 @@ public class BatchTriggerTest extends AbstractTest { static Connection connection = null; static String tableName = "triggerTable"; static String triggerName = "triggerTest"; - static String customErrorMessage = "Custom error message, you should see me. col1 should be higher than 10"; static String insertQuery = "insert into " + tableName + " (col1, col2, col3, col4) values (1, '22-08-2017 17:30:00.000', 'R4760', 31)"; /** @@ -52,10 +52,10 @@ public void statementTest() throws SQLException { stmt = connection.createStatement(); stmt.addBatch(insertQuery); stmt.executeBatch(); - fail("Trigger Exception not thrown"); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { - assertTrue(e.getMessage().equalsIgnoreCase(customErrorMessage)); + assertTrue(e.getMessage().equalsIgnoreCase(TestResource.getResource("R_customErrorMessage"))); } finally { @@ -77,11 +77,11 @@ public void preparedStatementTest() throws SQLException { pstmt = connection.prepareStatement(insertQuery); pstmt.addBatch(); pstmt.executeBatch(); - fail("Trigger Exception not thrown"); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { - assertTrue(e.getMessage().equalsIgnoreCase(customErrorMessage)); + assertTrue(e.getMessage().equalsIgnoreCase(TestResource.getResource("R_customErrorMessage"))); } finally { if (pstmt != null) { @@ -99,7 +99,7 @@ public void preparedStatementTest() throws SQLException { private static void createTrigger(String triggerName) throws SQLException { String sql = "create trigger " + triggerName + " on " + tableName + " for insert " + "as " + "begin " + "if (select col1 from " + tableName + ") > 10 " + "begin " + "return " + "end " - + "RAISERROR ('Custom error message, you should see me. col1 should be higher than 10', 16, 0) " + "rollback transaction " + "end"; + + "RAISERROR ('" + TestResource.getResource("R_customErrorMessage") + "', 16, 0) " + "rollback transaction " + "end"; stmt.execute(sql); } @@ -158,4 +158,4 @@ public static void terminateVariation() throws SQLException { } } -} \ No newline at end of file +} 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 e93f1c150..ef0321af3 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 @@ -20,6 +20,7 @@ import org.junit.runner.RunWith; import static org.junit.jupiter.api.Assertions.assertEquals; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -66,21 +67,21 @@ public void datatypesTest() throws SQLException { ResultSet rs = callableStatement.executeQuery(); rs.next(); - assertEquals(rs.getInt(1), 0, "Received data not equal to setdata"); - assertEquals(callableStatement.getInt((int) 5), -5372, "Received data not equal to setdata"); + assertEquals(rs.getInt(1), 0, TestResource.getResource("R_setDataNotEqual")); + assertEquals(callableStatement.getInt((int) 5), -5372, TestResource.getResource("R_setDataNotEqual")); // do nothing and reexecute rs = callableStatement.executeQuery(); // get the param without getting the resultset rs = callableStatement.executeQuery(); - assertEquals(callableStatement.getInt((int) 1), -2147483648, "Received data not equal to setdata"); + assertEquals(callableStatement.getInt((int) 1), -2147483648, TestResource.getResource("R_setDataNotEqual")); rs = callableStatement.executeQuery(); rs.next(); - assertEquals(rs.getInt(1), 0, "Received data not equal to setdata"); - assertEquals(callableStatement.getInt((int) 1), -2147483648, "Received data not equal to setdata"); - assertEquals(callableStatement.getInt((int) 5), -5372, "Received data not equal to setdata"); + assertEquals(rs.getInt(1), 0, TestResource.getResource("R_setDataNotEqual")); + assertEquals(callableStatement.getInt((int) 1), -2147483648, TestResource.getResource("R_setDataNotEqual")); + assertEquals(callableStatement.getInt((int) 5), -5372, TestResource.getResource("R_setDataNotEqual")); rs = callableStatement.executeQuery(); rs.close(); } 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 6e3563101..f04a04131 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 @@ -31,6 +31,7 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -126,7 +127,7 @@ public void verifyTranslation() throws Exception { method.setAccessible(true); } Object str = method.invoke(innerInstance, inputSql); - assertEquals(str, outputSql, "Syntax tyranslation does not match for query: " + queryID); + assertEquals(str, outputSql, TestResource.getResource("R_syntaxMatchError") + ": " + queryID); } public void setverifyResult(boolean val) { @@ -145,7 +146,7 @@ void execute(Connection conn) throws Exception { catch (Exception e) { if (null != exceptionMsg) { // This query is to verify right exception is thrown for errors in syntax. - assertTrue(e.getMessage().equalsIgnoreCase(exceptionMsg), "Test fatal errors"); + assertTrue(e.getMessage().equalsIgnoreCase(exceptionMsg), TestResource.getResource("R_unexpectedExceptionContent") + e.getMessage()); // Exception message matched. Return as there is no result to verify. return; } @@ -158,28 +159,28 @@ void execute(Connection conn) throws Exception { } if (null == resultSet) { - assertEquals(false, true, "ResultSet is null"); + assertEquals(false, true, TestResource.getResource("R_resultsetNull")); } int rowCount = 0; while (resultSet.next()) { // The int and string columns should be retrieved in order, for example cannot run a query that retrieves col2 but not col1 - assertEquals(resultSet.getInt(1), idCols[rowCount], "ID value does not match for query: " + queryID + ", row: " + rowCount); + assertEquals(resultSet.getInt(1), idCols[rowCount], TestResource.getResource("R_valueNotMatch") + queryID + ", row: " + rowCount); for (int j = 0, colNumber = 1; null != intResultCols && j < intResultCols[rowCount].length; ++j) { String colName = "col" + colNumber; assertEquals(resultSet.getInt(colName), intResultCols[rowCount][j], - "Int value does not match for query: " + queryID + ", row: " + rowCount + ", column: " + colName); + TestResource.getResource("R_valueNotMatch") + queryID + ", row: " + rowCount + ", column: " + colName); colNumber++; } for (int j = 0, colNumber = 3; null != stringResultCols && j < stringResultCols[rowCount].length; ++j) { String colName = "col" + colNumber; assertEquals(resultSet.getString(colName), stringResultCols[rowCount][j], - "String value does not match for query: " + queryID + ", row: " + rowCount + ", column: " + colName); + TestResource.getResource("R_valueNotMatch") + queryID + ", row: " + rowCount + ", column: " + colName); colNumber++; } rowCount++; } - assertEquals(rowCount, rows, "Row Count does not match for query"); + assertEquals(rowCount, rows, TestResource.getResource("R_valueNotMatch") + "rowCount: " + rowCount + ", rows: " + rows); assertEquals(resultSet.getMetaData().getColumnCount(), columns, "Column Count does not match"); } } 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 41674e562..5f681796a 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 @@ -21,6 +21,7 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.DBStatement; @@ -62,7 +63,7 @@ public void runTest() throws Exception { stmt.executeUpdate(setupTables); stmt.executeUpdate(mergeCmd2); int updateCount = stmt.getUpdateCount(); - assertEquals(updateCount, 3, "Received the wrong update count!"); + assertEquals(updateCount, 3, TestResource.getResource("R_incorrectUpdateCount")); } } 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 2ee818313..62997ffcc 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 @@ -23,6 +23,7 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -61,7 +62,7 @@ public void update1() throws Exception { cs.registerOutParameter("p_out", Types.VARCHAR); cs.executeUpdate(); String data = cs.getString("p_out"); - assertEquals(data, dataPut, "Received data not equal to setdata"); + assertEquals(data, dataPut, TestResource.getResource("R_setDataNotEqual")); } } @@ -76,7 +77,7 @@ public void update2() throws Exception { cs.registerOutParameter("p_out", Types.VARCHAR); cs.executeUpdate(); Object data = cs.getObject("p_out"); - assertEquals(data, dataPut, "Received data not equal to setdata"); + assertEquals(data, dataPut, TestResource.getResource("R_setDataNotEqual")); } } @@ -93,7 +94,7 @@ public void update3() throws Exception { cs.registerOutParameter("p_out", Types.VARCHAR); cs.executeUpdate(); Object data = cs.getObject("p_out"); - assertEquals(data, dataPut, "Received data not equal to setdata"); + assertEquals(data, dataPut, TestResource.getResource("R_setDataNotEqual")); } } @@ -108,7 +109,7 @@ public void update4() throws Exception { cs.registerOutParameter("p_out", Types.VARCHAR); cs.executeUpdate(); Object data = cs.getObject("p_out"); - assertEquals(data, dataPut, "Received data not equal to setdata"); + assertEquals(data, dataPut, TestResource.getResource("R_setDataNotEqual")); } } @@ -123,7 +124,7 @@ public void update5() throws Exception { cs.registerOutParameter("p_out", Types.VARCHAR); cs.executeUpdate(); Object data = cs.getObject("p_out"); - assertEquals(data, dataPut, "Received data not equal to setdata"); + assertEquals(data, dataPut, TestResource.getResource("R_setDataNotEqual")); } } @@ -139,7 +140,7 @@ public void update6() throws Exception { cs.registerOutParameter("p_out", Types.VARCHAR); cs.executeUpdate(); Object data = cs.getObject("p_out"); - assertEquals(data, dataPut, "Received data not equal to setdata"); + assertEquals(data, dataPut, TestResource.getResource("R_setDataNotEqual")); } } 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 55acb2ca8..210dd264c 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 @@ -27,6 +27,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -227,7 +228,7 @@ private static void checkNumericMetaData() throws SQLException { ParameterMetaData pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 15, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 15, TestResource.getResource("R_paramNotRecognized")); compareParameterMetaData(pmd, 1, "java.math.BigDecimal", 3, "decimal", 18, 0); compareParameterMetaData(pmd, 2, "java.math.BigDecimal", 3, "decimal", 10, 5); @@ -250,7 +251,7 @@ private static void checkCharMetaData(int expectedParameterCount) throws SQLExce ParameterMetaData pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), expectedParameterCount, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), expectedParameterCount, TestResource.getResource("R_paramNotRecognized")); compareParameterMetaData(pmd, 1, "java.lang.String", 1, "char", 50, 0); compareParameterMetaData(pmd, 2, "java.lang.String", 12, "varchar", 20, 0); @@ -267,7 +268,7 @@ private static void checkBinaryMetaData() throws SQLException { ParameterMetaData pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 2, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 2, TestResource.getResource("R_paramNotRecognized")); compareParameterMetaData(pmd, 1, "[B", -2, "binary", 100, 0); compareParameterMetaData(pmd, 2, "[B", -3, "varbinary", 200, 0); @@ -276,7 +277,7 @@ private static void checkBinaryMetaData() throws SQLException { private static void checkDateAndTimeMetaData() throws SQLException { ParameterMetaData pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 9, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 9, TestResource.getResource("R_paramNotRecognized")); compareParameterMetaData(pmd, 1, "java.sql.Date", 91, "date", 10, 0); compareParameterMetaData(pmd, 2, "java.sql.Timestamp", 93, "datetime", 23, 3); @@ -306,7 +307,7 @@ private static void compareParameterMetaData(ParameterMetaData pmd, } try { assertTrue(pmd.getParameterType(index) == expectedType, - "Parameter Type error:\n" + "expected: " + expectedType + " \n" + "actual: " + pmd.getParameterType(index)); + "getParameterType: " + TestResource.getResource("R_valueNotMatch") + expectedType + ", " + pmd.getParameterType(index)); } catch (SQLException e) { fail(e.toString()); @@ -314,14 +315,14 @@ private static void compareParameterMetaData(ParameterMetaData pmd, try { assertTrue(pmd.getParameterTypeName(index).equalsIgnoreCase(expectedTypeName), - "Parameter Type Name error:\n" + "expected: " + expectedTypeName + " \n" + "actual: " + pmd.getParameterTypeName(index)); + "getParameterTypeName: " + TestResource.getResource("R_valueNotMatch") + expectedTypeName + ", " + pmd.getParameterTypeName(index)); } catch (SQLException e) { fail(e.toString()); } try { assertTrue(pmd.getPrecision(index) == expectedPrecision, - "Parameter Prcision error:\n" + "expected: " + expectedPrecision + " \n" + "actual: " + pmd.getPrecision(index)); + "getPrecision: " + TestResource.getResource("R_valueNotMatch") + expectedPrecision + ", " + pmd.getPrecision(index)); } catch (SQLException e) { fail(e.toString()); @@ -329,7 +330,7 @@ private static void compareParameterMetaData(ParameterMetaData pmd, try { assertTrue(pmd.getScale(index) == expectedScale, - "Parameter Prcision error:\n" + "expected: " + expectedScale + " \n" + "actual: " + pmd.getScale(index)); + "getScale: " + TestResource.getResource("R_valueNotMatch") + expectedScale + ", " + pmd.getScale(index)); } catch (SQLException e) { fail(e.toString()); @@ -744,7 +745,7 @@ public void testSubquery() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 3, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 3, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -777,7 +778,7 @@ public void testJoin() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 2, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 2, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -810,7 +811,7 @@ public void testMerge() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 2, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 2, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -863,7 +864,7 @@ private static void testInsertMultipleTypes() throws SQLException { ParameterMetaData pmd = null; try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 30, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 30, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -921,7 +922,7 @@ public void testNoParameter() throws SQLException { ParameterMetaData pmd = null; try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 0, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 0, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -955,7 +956,7 @@ private static void testMixedWithHardcodedValues() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 21, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 21, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -1004,7 +1005,7 @@ public void testOrderBy() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 4, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 4, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -1034,7 +1035,7 @@ private void testGroupBy() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 4, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 4, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -1063,7 +1064,7 @@ public void testLower() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 4, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 4, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -1091,7 +1092,7 @@ public void testPower() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 4, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 4, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); @@ -1126,7 +1127,7 @@ public void testAllInOneQuery() throws SQLException { try { pmd = pstmt.getParameterMetaData(); - assertEquals(pmd.getParameterCount(), 3, "Not all parameters are recognized by driver."); + assertEquals(pmd.getParameterCount(), 3, TestResource.getResource("R_paramNotRecognized")); } catch (Exception e) { fail(e.toString()); 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 7ce0773de..72fd663d5 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 @@ -26,6 +26,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Utils; @@ -49,17 +50,17 @@ public void poolableTest() throws SQLException, ClassNotFoundException { try { // First get the default values boolean isPoolable = ((SQLServerStatement) statement).isPoolable(); - assertEquals(isPoolable, false, "SQLServerStatement should not be Poolable by default"); + assertEquals(isPoolable, false, "SQLServerStatement: " + TestResource.getResource("R_incorrectDefault")); try (PreparedStatement prepStmt = connection.prepareStatement("select 1")) { isPoolable = ((SQLServerPreparedStatement) prepStmt).isPoolable(); - assertEquals(isPoolable, true, "SQLServerPreparedStatement should be Poolable by default"); + assertEquals(isPoolable, true, "SQLServerPreparedStatement: " + TestResource.getResource("R_incorrectDefault")); } try (CallableStatement callableStatement = connection.prepareCall("{ ? = CALL " + "ProcName" + " (?, ?, ?, ?) }");) { isPoolable = ((SQLServerCallableStatement) callableStatement).isPoolable(); - assertEquals(isPoolable, true, "SQLServerCallableStatement should be Poolable by default"); + assertEquals(isPoolable, true, "SQLServerCallableStatement: " + TestResource.getResource("R_incorrectDefault")); // Now do couple of sets and gets @@ -71,8 +72,10 @@ public void poolableTest() throws SQLException, ClassNotFoundException { assertEquals(((SQLServerStatement) statement).isPoolable(), true, "set did not work"); } catch (UnsupportedOperationException e) { - assertEquals(System.getProperty("java.specification.version"), "1.5", "PoolableTest should be supported in anything other than 1.5"); - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + // PoolableTest should be supported in anything other than 1.5 + assertEquals(System.getProperty("java.specification.version"), "1.5", "PoolableTest " + TestResource.getResource("R_shouldBeSupported")); + assertEquals(e.getMessage(), TestResource.getResource("R_operationNotSupported")); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedExceptionContent")); } } } 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 e4e0d09f0..acd661068 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 @@ -33,6 +33,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; @RunWith(JUnitPlatform.class) @@ -286,7 +287,7 @@ public void testStatementPooling() throws SQLException { } try { System.out.println(outer.getPreparedStatementHandle()); - fail("Error for invalid use of getPreparedStatementHandle() after statement close expected."); + fail(TestResource.getResource("R_invalidGetPreparedStatementHandle")); } catch(Exception e) { // Good! @@ -568,4 +569,4 @@ public void testStatementPoolingPreparedStatementExecAndUnprepareConfig() throws assertSame(0, con.getDiscardedServerPreparedStatementCount()); } } -} \ No newline at end of file +} 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 2eec0cd70..1efa1e25a 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 @@ -27,6 +27,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.Utils; @@ -83,10 +84,10 @@ public void testServerCursorPStmt() throws SQLException { // should return 1 row rs = pstmt.executeQuery(); rs.last(); - assertEquals(rs.getRow(), numRowsInResult, "getRow mismatch"); + assertEquals(rs.getRow(), numRowsInResult, TestResource.getResource("R_valueNotMatch") + rs.getRow() + ", " + numRowsInResult); rs.beforeFirst(); while (rs.next()) { - assertEquals(rs.getString(1), col3Value, "Value mismatch"); + assertEquals(rs.getString(1), col3Value, TestResource.getResource("R_valueNotMatch") + rs.getString(1) + ", " + col3Value); } if (null != stmt) @@ -120,7 +121,7 @@ public void testSelectIntoUpdateCount() throws SQLException { PreparedStatement ps = con.prepareStatement("SELECT * INTO #TMPTABLE FROM " + tableName + " WHERE col1 <= ?"); ps.setInt(1, numRowsToCopy); int updateCount = ps.executeUpdate(); - assertEquals(numRowsToCopy, updateCount, "Incorrect update count"); + assertEquals(numRowsToCopy, updateCount, TestResource.getResource("R_incorrectUpdateCount")); if (null != stmt) stmt.close(); @@ -136,7 +137,7 @@ public void testSelectIntoUpdateCount() throws SQLException { */ @Test public void testUpdateQuery() throws SQLException { - assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); + assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), TestResource.getResource("R_incompatJDBC")); SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(connectionString); String sql; @@ -197,7 +198,7 @@ public void testUpdateQuery() throws SQLException { */ @Test public void testXmlQuery() throws SQLException { - assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); + assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), TestResource.getResource("R_incompatJDBC")); Connection connection = DriverManager.getConnection(connectionString); 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 0a2abb2c1..224414a9f 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 @@ -18,6 +18,7 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; @RunWith(JUnitPlatform.class) @@ -59,7 +60,8 @@ public void run() { stmt.execute("WAITFOR DELAY '00:00:" + (DELAY_WAIT_MILLISECONDS / 1000) + "'"); } catch (SQLException e) { - assertTrue(e.getMessage().startsWith("The query was canceled"), "Unexpected error message."); + // The query was canceled"), "Unexpected error message + assertTrue(e.getMessage().startsWith(TestResource.getResource("R_queryCancelled")), TestResource.getResource("R_unexpectedExceptionContent")); } } } @@ -67,9 +69,9 @@ public void run() { finally { timeEnd = System.currentTimeMillis(); long timeDifference = timeEnd - timeStart; - assertTrue(timeDifference >= CANCEL_WAIT_MILLISECONDS, "Cancellation failed."); - assertTrue(timeDifference < DELAY_WAIT_MILLISECONDS, "Cancellation failed."); - assertTrue((timeDifference - CANCEL_WAIT_MILLISECONDS) < 1000, "Cancellation failed."); + assertTrue(timeDifference >= CANCEL_WAIT_MILLISECONDS, TestResource.getResource("R_cancellationFailed")); + assertTrue(timeDifference < DELAY_WAIT_MILLISECONDS, TestResource.getResource("R_cancellationFailed")); + assertTrue((timeDifference - CANCEL_WAIT_MILLISECONDS) < 1000, TestResource.getResource("R_cancellationFailed")); } } } 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 418068d90..2b322c47b 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 @@ -48,6 +48,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.SQLServerResultSetMetaData; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; @@ -121,7 +122,8 @@ public void testCancelBeforeExecute() throws Exception { while (rs.next()) ++numSelectedRows; - assertEquals(NUM_TABLE_ROWS, numSelectedRows, "Wrong number of rows returned"); + // Wrong number of rows returned + assertEquals(NUM_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); stmt.close(); con.close(); } @@ -154,7 +156,7 @@ public void testErrorInRequest() throws Exception { assertEquals( "The stream value is not the specified length. The specified length was " + (TEST_STRING.length() - 1) + ", the actual length is " + TEST_STRING.length() + ".", - e.getMessage(), "Unexpected exception executing batch update with bad value."); + e.getMessage(), TestResource.getResource("R_unexpectedException")); } // Successfully closing the PreparedStatement is verification enough that the connection is @@ -184,14 +186,15 @@ public void testQueryTimeout() throws Exception { try { ps.execute(); - assertEquals(false, true, "Execution did not timeout"); + assertEquals(false, true, TestResource.getResource("R_executionNotTimeout")); } catch (SQLException e) { - assertTrue("The query has timed out.".equalsIgnoreCase(e.getMessage()), "Unexpected exception on 1st execution"); + assertTrue(TestResource.getResource("R_queryTimedOut").equalsIgnoreCase(e.getMessage()), TestResource.getResource("R_unexpectedException")); + assertTrue("The query has timed out.".equalsIgnoreCase(e.getMessage()), TestResource.getResource("R_unexpectedException")); } elapsedMillis += System.currentTimeMillis(); if (elapsedMillis >= 3000) { - assertEquals(2000, (int) elapsedMillis, "1st execution took too long"); + assertEquals(2000, (int) elapsedMillis, TestResource.getResource("R_executionTooLong")); } // Second execution: @@ -205,7 +208,7 @@ public void testQueryTimeout() throws Exception { // Oddly enough, the server's idea of 7 seconds is actually slightly less than // 7000 milliseconds by our clock (!) so we have to allow some slack here. if (elapsedMillis < 6500) { - assertEquals(6500, (int) elapsedMillis, "2nd execution didn't take long enough."); + assertEquals(6500, (int) elapsedMillis, TestResource.getResource("R_executionNotLong")); } ps.close(); @@ -222,7 +225,7 @@ public void testQueryTimeout() throws Exception { */ @Test public void testCancelLongResponse() throws Exception { - assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); + assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), TestResource.getResource("R_incompatJDBC")); Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement(SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ((SQLServerStatement) stmt).setResponseBuffering("adaptive"); @@ -233,7 +236,7 @@ public void testCancelLongResponse() throws Exception { } catch (Exception e) { - throw new SQLException("testCancelLongResponse threw exception: ", e); + throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } @@ -245,7 +248,8 @@ public void testCancelLongResponse() throws Exception { ; // Verify that MIN_TABLE_ROWS rows were returned - assertEquals(MIN_TABLE_ROWS, numSelectedRows, "Wrong number of rows returned in first scan"); + // Wrong number of rows returned in first scan + assertEquals(MIN_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); // Cancel the statement and verify that the ResultSet // does NOT return all the remaining rows. @@ -255,16 +259,16 @@ public void testCancelLongResponse() throws Exception { while (rs.next()) ++numSelectedRows; - assertEquals(false, true, "Expected exception not thrown from ResultSet.next()"); + assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertEquals("The query was canceled.", e.getMessage(), "Unexpected exception from ResultSet.next()"); + assertEquals(TestResource.getResource("R_queryCancelled"), TestResource.getResource("R_unexpectedException")); } assertEquals(false, NUM_TABLE_ROWS * NUM_TABLE_ROWS == numSelectedRows, "All rows returned after cancel"); rs.close(); - assertEquals(stmt.isClosed(), true, "testCancelLongResponse: statement should be closed since resultset is closed."); + assertEquals(stmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); con.close(); } @@ -363,10 +367,10 @@ public void testCancelBlockedResponse() throws Exception { ++numSelectedRows; log.fine("numSelectedRows: " + numSelectedRows); - assertEquals(false, true, "Expected exception not thrown from ResultSet.next()"); + assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertTrue("The query was canceled.".equalsIgnoreCase(e.getMessage()), "Unexpected exception from ResultSet.next()"); + assertTrue(TestResource.getResource("R_queryCancelled").equalsIgnoreCase(e.getMessage()), TestResource.getResource("R_unexpectedException")); } elapsedMillis += System.currentTimeMillis(); @@ -375,14 +379,14 @@ public void testCancelBlockedResponse() throws Exception { // Note that we may actually get fewer rows than the number of rows before the blocked row // if SQL Server is a little slow in returning rows to us. if (numSelectedRows >= NUM_TABLE_ROWS - MIN_TABLE_ROWS) { - assertEquals(NUM_TABLE_ROWS - MIN_TABLE_ROWS, numSelectedRows, "Wrong number of rows returned"); + assertEquals(NUM_TABLE_ROWS - MIN_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); } // If we were able to iterate through all of the expected // rows without blocking, then something went wrong with our // efforts to block execution. if (elapsedMillis < 2500) { - assertEquals(2500, (int) elapsedMillis, "Statement executed too quickly."); + assertEquals(2500, (int) elapsedMillis, TestResource.getResource("R_executionNotLong")); } rs.close(); @@ -476,10 +480,10 @@ public void testCancelBlockedResponsePS() throws Exception { while (rs.next()) ++numSelectedRows; - assertEquals(false, true, "Expected exception not thrown from ResultSet.next()"); + assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertTrue("The query was canceled.".contains(e.getMessage()), "Unexpected exception from ResultSet.next()"); + assertTrue(TestResource.getResource("R_queryCancelled").contains(e.getMessage()), TestResource.getResource("R_unexpectedException")); } elapsedMillis += System.currentTimeMillis(); @@ -488,14 +492,14 @@ public void testCancelBlockedResponsePS() throws Exception { // Note that we may actually get fewer rows than the number of rows before the blocked row // if SQL Server is a little slow in returning rows to us. if (numSelectedRows >= NUM_TABLE_ROWS - MIN_TABLE_ROWS) { - assertEquals(NUM_TABLE_ROWS - MIN_TABLE_ROWS, numSelectedRows, "Wrong number of rows returned"); + assertEquals(NUM_TABLE_ROWS - MIN_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); } // If we were able to iterate through all of the expected // rows without blocking, then something went wrong with our // efforts to block execution. if (elapsedMillis < 2500) { - assertEquals(2500, (int) elapsedMillis, "Statement executed too quickly."); + assertEquals(2500, (int) elapsedMillis, TestResource.getResource("R_executionNotLong")); } rs.close(); @@ -587,7 +591,7 @@ public void testCancelBlockedCursoredResponse() throws Exception { while (numSelectedRows < MIN_TABLE_ROWS && rs.next()) ++numSelectedRows; - assertEquals(MIN_TABLE_ROWS, numSelectedRows, "Too few rows returned initially."); + assertEquals(MIN_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); // Now, try to grab the remaining rows from the result set. At some point the call // to ResultSet.next() should block until the statement is cancelled from the other @@ -596,17 +600,17 @@ public void testCancelBlockedCursoredResponse() throws Exception { while (rs.next()) ++numSelectedRows; - assertEquals(false, true, "Expected exception not thrown from ResultSet.next()"); + assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertTrue("The query was canceled.".contains(e.getMessage()), "Unexpected exception from ResultSet.next()"); + assertTrue(TestResource.getResource("R_queryCancelled").contains(e.getMessage()), TestResource.getResource("R_unexpectedException")); } elapsedMillis += System.currentTimeMillis(); // If we get here to early, then we were able to scan through the rows too fast. // There's some slop in the elapsed time due to imprecise timer resolution. if (elapsedMillis < 2500) { - assertEquals(2500, (int) elapsedMillis, "Statement executed too quickly."); + assertEquals(2500, (int) elapsedMillis, TestResource.getResource("R_executionNotLong")); } // Looks like we were canceled. Exception message matched. Time took as long @@ -614,7 +618,7 @@ public void testCancelBlockedCursoredResponse() throws Exception { // we initially asked for. If any rows beyond the locked row were returned // then something went wrong. assertEquals(true, (numSelectedRows <= NUM_TABLE_ROWS - MIN_TABLE_ROWS), - "Too many rows returned. " + "Expected: " + (NUM_TABLE_ROWS - MIN_TABLE_ROWS) + " " + "Actual: " + numSelectedRows); + TestResource.getResource("R_valueNotMatch")); } finally { if (null != con) @@ -649,7 +653,7 @@ public void testCancelAfterResponse() throws Exception { while (rs.next()) ++numSelectedRows; rs.close(); - assertEquals(NUM_TABLE_ROWS, numSelectedRows, "Wrong number of rows returned in 1st select"); + assertEquals(NUM_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); // "Cancel" the executed query stmt.cancel(); @@ -660,7 +664,7 @@ public void testCancelAfterResponse() throws Exception { while (rs.next()) ++numSelectedRows; rs.close(); - assertEquals(NUM_TABLE_ROWS, numSelectedRows, "Wrong number of rows returned in 2nd select"); + assertEquals(NUM_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); stmt.close(); con.close(); @@ -920,11 +924,11 @@ public void testIsCloseOnCompletion() throws Exception { } catch (Exception e) { - throw new SQLException("testIsCloseOnCompletion threw exception: ", e); + throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } - assertEquals(false, result, "isCloseOnCompletion default should be false."); + assertEquals(false, result, "isCloseOnCompletion: " + TestResource.getResource("R_incorrectDefault")); ps.close(); con.close(); @@ -941,8 +945,7 @@ public void testCloseOnCompletion() throws Exception { ps.closeOnCompletion(); } catch (Exception e) { - - throw new SQLException("testCloseOnCompletion threw exception: ", e); + throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } @@ -955,7 +958,7 @@ public void testCloseOnCompletion() throws Exception { log.fine("testIsCloseOnCompletion threw: " + e.getMessage()); } - assertEquals(ps.isClosed(), true, "testCloseOnCompletion: statement should be closed since resultset is closed."); + assertEquals(ps.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); con.close(); } @@ -986,11 +989,11 @@ public void testIsCloseOnCompletion() throws Exception { } catch (Exception e) { - throw new SQLException("testIsCloseOnCompletion threw exception: ", e); + throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } - assertEquals(true, stmt.isCloseOnCompletion(), "isCloseOnCompletion should have been enabled."); + assertEquals(true, stmt.isCloseOnCompletion(), "isCloseOnCompletion " + TestResource.getResource("R_shouldBeEnabled")); stmt.close(); con.close(); @@ -1010,18 +1013,18 @@ public void testCloseOnCompletion() throws Exception { } catch (Exception e) { - throw new SQLException("testCloseOnCompletion threw exception: ", e); + throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } ResultSet rs; rs = stmt.executeQuery("SELECT 1"); - assertEquals(stmt.isClosed(), false, "testCloseOnCompletion: statement should be open since resultset is open."); + assertEquals(stmt.isClosed(), false, TestResource.getResource("R_statementShouldBeOpened")); // now statement should be closed rs.close(); - assertEquals(stmt.isClosed(), true, "testCloseOnCompletion: statement should be closed since resultset is closed."); + assertEquals(stmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); con.close(); } @@ -1043,9 +1046,7 @@ public void testConsecutiveQueries() throws Exception { stmt.closeOnCompletion(); } catch (Exception e) { - - throw new SQLException("testCloseOnCompletion threw exception: ", e); - + throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } try { @@ -1068,9 +1069,7 @@ public void testConsecutiveQueries() throws Exception { ResultSet rs2 = stmt.executeQuery("SELECT * FROM " + table2Name); } catch (Exception e) { - - assertEquals(stmt.isClosed(), true, "testCloseOnCompletion: statement should be closed since previous resultset was closed."); - + assertEquals(stmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); } con.close(); @@ -1083,7 +1082,7 @@ public void testConsecutiveQueries() throws Exception { */ @Test public void testLargeMaxRowsJDBC41() throws Exception { - assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); + assumeTrue("JDBC41".equals(Utils.getConfiguredProperty("JDBC_Version")), TestResource.getResource("R_incompatJDBC")); Connection con = DriverManager.getConnection(connectionString); SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); @@ -1092,7 +1091,7 @@ public void testLargeMaxRowsJDBC41() throws Exception { try { stmt.getLargeMaxRows(); - throw new SQLException("ERROR: We should not be here."); + throw new SQLException(TestResource.getResource("R_unexpectedException")); } catch (Exception e) { fail(e.getMessage()); @@ -1101,7 +1100,7 @@ public void testLargeMaxRowsJDBC41() throws Exception { // testing exception for setLargeMaxRows method try { stmt.setLargeMaxRows(2015); - throw new SQLException("ERROR: We should not be here."); + throw new SQLException(TestResource.getResource("R_unexpectedException")); } catch (Exception e) { fail(e.getMessage()); @@ -1122,14 +1121,13 @@ public void testLargeMaxRowsJDBC41() throws Exception { */ @Test public void testLargeMaxRowsJDBC42() throws Exception { - assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), "Aborting test case as JDBC version is not compatible. "); - + assumeTrue("JDBC42".equals(Utils.getConfiguredProperty("JDBC_Version")), TestResource.getResource("R_incompatJDBC")); Connection dbcon = DriverManager.getConnection(connectionString); Statement dbstmt = dbcon.createStatement(); // Default value should return zero long actual = dbstmt.getLargeMaxRows(); - assertEquals(actual, (long) 0, "getLargeMaxRows() : default value is not zero"); + assertEquals(actual, (long) 0, "getLargeMaxRows():" + TestResource.getResource("R_incorrectDefault")); // Set a new value less than MAX_VALUE, and then get the modified value long newValue = 2012L; @@ -1149,7 +1147,7 @@ public void testLargeMaxRowsJDBC42() throws Exception { assertEquals( ("calling setLargeMaxRows failed : java.lang.UnsupportedOperationException: " + "The supported maximum row count for a result set is Integer.MAX_VALUE or less."), - (e.getMessage()), "Wring setLargeMaxRows() Exception"); + (e.getMessage()), TestResource.getResource("R_unexpectedException")); } // Set a negative value. If negative is accepted, throw exception @@ -1161,7 +1159,7 @@ public void testLargeMaxRowsJDBC42() throws Exception { 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(), "Wring setLargeMaxRows() Exception"); + e.getMessage(), TestResource.getResource("R_unexpectedException")); } if (null != dbstmt) { @@ -1362,31 +1360,30 @@ public void testStatementOutParamGetsTwice() throws Exception { ResultSet rs = stmt.getResultSet(); if (rs != null) { rs.close(); - assertEquals(stmt.isClosed(), true, "testStatementOutParamGetsTwice: statement should be closed since resultset is closed."); + assertEquals(stmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); } else { - assertEquals(stmt.isClosed(), false, "testStatementOutParamGetsTwice: statement should be open since no resultset."); + assertEquals(stmt.isClosed(), false, TestResource.getResource("R_statementShouldBeOpened")); } CallableStatement cstmt = con.prepareCall("{ ? = CALL " + procNameTemp + " (?,?)}"); cstmt.registerOutParameter(1, Types.INTEGER); cstmt.setObject(2, Short.valueOf("32"), Types.SMALLINT); cstmt.registerOutParameter(3, Types.SMALLINT); cstmt.execute(); - assertEquals(cstmt.getInt(1), 33, "Wrong value"); - assertEquals(cstmt.getInt(3), 32, "Wrong value"); + assertEquals(cstmt.getInt(1), 33, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(3), 32, TestResource.getResource("R_valueNotMatch")); cstmt.setObject(2, Short.valueOf("34"), Types.SMALLINT); cstmt.execute(); - assertEquals(cstmt.getInt(1), 35, "Wrong value"); - assertEquals(cstmt.getInt(3), 34, "Wrong value"); + assertEquals(cstmt.getInt(1), 35, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(3), 34, TestResource.getResource("R_valueNotMatch")); rs = cstmt.getResultSet(); if (rs != null) { rs.close(); - assertEquals(stmt.isClosed(), true, "testStatementOutParamGetsTwice: statement should be closed since resultset is closed."); - + assertEquals(stmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); } else { - assertEquals((stmt).isClosed(), false, "testStatementOutParamGetsTwice: statement should be open since no resultset."); + assertEquals(stmt.isClosed(), false, TestResource.getResource("R_statementShouldBeOpened")); } } @@ -1405,16 +1402,16 @@ public void testStatementOutManyParamGetsTwiceRandomOrder() throws Exception { cstmt.setObject(4, Short.valueOf("23"), Types.SMALLINT); cstmt.registerOutParameter(5, Types.INTEGER); cstmt.execute(); - assertEquals(cstmt.getInt(1), 33, "Wrong value"); - assertEquals(cstmt.getInt(5), 23, "Wrong value"); - assertEquals(cstmt.getInt(3), 32, "Wrong value"); + assertEquals(cstmt.getInt(1), 33, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(5), 23, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(3), 32, TestResource.getResource("R_valueNotMatch")); cstmt.setObject(2, Short.valueOf("34"), Types.SMALLINT); cstmt.setObject(4, Short.valueOf("24"), Types.SMALLINT); cstmt.execute(); - assertEquals(cstmt.getInt(3), 34, "Wrong value"); - assertEquals(cstmt.getInt(5), 24, "Wrong value"); - assertEquals(cstmt.getInt(1), 35, "Wrong value"); + assertEquals(cstmt.getInt(3), 34, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(5), 24, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(1), 35, TestResource.getResource("R_valueNotMatch")); } /** @@ -1436,13 +1433,13 @@ public void testStatementOutParamGetsTwiceInOut() throws Exception { cstmt.setObject(3, Short.valueOf("100"), Types.SMALLINT); cstmt.registerOutParameter(3, Types.SMALLINT); cstmt.execute(); - assertEquals(cstmt.getInt(1), 2, "Wrong value"); - assertEquals(cstmt.getInt(3), 101, "Wrong value"); + assertEquals(cstmt.getInt(1), 2, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(1), 2, TestResource.getResource("R_valueNotMatch")); cstmt.setObject(2, Short.valueOf("10"), Types.SMALLINT); cstmt.execute(); - assertEquals(cstmt.getInt(1), 11, "Wrong value"); - assertEquals(cstmt.getInt(3), 101, "Wrong value"); + assertEquals(cstmt.getInt(1), 11, TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getInt(3), 101, TestResource.getResource("R_valueNotMatch")); } /** @@ -1468,8 +1465,8 @@ public void testResultSetParams() throws Exception { cstmt.registerOutParameter(2, java.sql.Types.VARCHAR); ResultSet rs = cstmt.executeQuery(); rs.next(); - assertEquals(rs.getString(2), "hello", "Wrong value"); - assertEquals(cstmt.getString(2), "hi", "Wrong value"); + assertEquals(rs.getString(2), "hello", TestResource.getResource("R_valueNotMatch")); + assertEquals(cstmt.getString(2), "hi", TestResource.getResource("R_valueNotMatch")); } /** @@ -1563,7 +1560,7 @@ public void testResultSetErrors() throws Exception { } ; - assertEquals(null, cstmt.getString(2), "Wrong value"); + assertEquals(null, cstmt.getString(2), TestResource.getResource("R_valueNotMatch")); } /** @@ -1608,15 +1605,13 @@ public void testRowError() throws Exception { cstmt.closeOnCompletion(); } catch (Exception e) { - - throw new SQLException("testRowError threw exception: ", e); - + throw new SQLException(TestResource.getResource("R_unexpectedException")); } ResultSet rs = cstmt.executeQuery(); assertEquals(true, rs.next(), "Query returned no rows"); rs.close(); - assertEquals(cstmt.isClosed(), true, "testRowError: statement should be closed since resultset is closed."); + assertEquals(cstmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); // On a second connection, repeat the query, with an immediate // lock timeout to induce an error. @@ -1643,11 +1638,11 @@ public void testRowError() throws Exception { for (int i = 0; i < 2; i++) { try { rs.next(); - assertEquals(false, true, "Expected row lock timeout exception not thrown"); + assertEquals(false, true, "lock timeout" + TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { assertEquals(1222, // lock timeout - e.getErrorCode(), "Wrong exception from ResultSet.next: " + e.getMessage()); + e.getErrorCode(), TestResource.getResource("R_unexpectedException") + e.getMessage()); } } @@ -2052,10 +2047,10 @@ public void testActiveStatement() throws Exception { assertEquals(stmt.isClosed(), false, "Wrong return value from Statement.isClosed"); } catch (UnsupportedOperationException e) { - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedException"), e.getMessage()); } - assertEquals(stmt.isClosed(), false, "testActiveStatement: statement should be open since resultset is open."); + assertEquals(stmt.isClosed(), false, TestResource.getResource("R_statementShouldBeOpened")); stmt.close(); conn.close(); } @@ -2077,7 +2072,7 @@ public void testClosedStatement() throws Exception { assertEquals(stmt.isClosed(), true, "Wrong return value from Statement.isClosed"); } catch (UnsupportedOperationException e) { - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedException"), e.getMessage()); } conn.close(); @@ -2100,7 +2095,7 @@ public void testClosedConnection() throws Exception { assertEquals(stmt.isClosed(), true, "Wrong return value from Statement.isClosed"); } catch (UnsupportedOperationException e) { - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedException"), e.getMessage()); } } } @@ -2124,9 +2119,7 @@ public void testActiveResultSet() throws Exception { stmt.closeOnCompletion(); } catch (Exception e) { - - throw new SQLException("testActiveResultSet threw exception: ", e); - + throw new SQLException(TestResource.getResource("R_unexpectedException")); } SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("SELECT 1"); @@ -2135,11 +2128,11 @@ public void testActiveResultSet() throws Exception { assertEquals(rs.isClosed(), false, "Wrong return value from ResultSet.isClosed"); } catch (UnsupportedOperationException e) { - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedException"), e.getMessage()); } rs.close(); - assertEquals(stmt.isClosed(), true, "testActiveResultSet: statement should be closed since resultset is closed."); + assertEquals(stmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); conn.close(); } @@ -2161,9 +2154,7 @@ public void testClosedResultSet() throws Exception { stmt.closeOnCompletion(); } catch (Exception e) { - - throw new SQLException("testClosedResultSet threw exception: ", e); - + throw new SQLException(TestResource.getResource("R_unexpectedException")); } SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery("SELECT 1"); @@ -2173,9 +2164,9 @@ public void testClosedResultSet() throws Exception { assertEquals(rs.isClosed(), true, "Wrong return value from ResultSet.isClosed"); } catch (UnsupportedOperationException e) { - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedException"), e.getMessage()); } - assertEquals(stmt.isClosed(), true, "testClosedResultSet: statement should be closed since resultset is closed."); + assertEquals(stmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); conn.close(); } @@ -2198,7 +2189,7 @@ public void testClosedStatement() throws Exception { assertEquals(rs.isClosed(), true, "Wrong return value from ResultSet.isClosed"); } catch (UnsupportedOperationException e) { - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedException"), e.getMessage()); } conn.close(); @@ -2223,7 +2214,7 @@ public void testClosedConnection() throws Exception { assertEquals(rs.isClosed(), true, "Wrong return value from ResultSet.isClosed"); } catch (UnsupportedOperationException e) { - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(e.getMessage(), TestResource.getResource("R_unexpectedException"), e.getMessage()); } } } @@ -2426,9 +2417,7 @@ public void testUpdateCountAfterRaiseError() throws Exception { pstmt.closeOnCompletion(); } catch (Exception e) { - - throw new SQLException("testUpdateCountAfterRaiseError threw exception: ", e); - + throw new SQLException(TestResource.getResource("R_unexpectedException")); } boolean result = pstmt.execute(); @@ -2438,7 +2427,7 @@ public void testUpdateCountAfterRaiseError() throws Exception { try { result = pstmt.getMoreResults(); - assertEquals(true, false, "Second result: Expected SQLException not thrown"); + assertEquals(true, false, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { String expectedMessage; @@ -2464,7 +2453,7 @@ public void testUpdateCountAfterRaiseError() throws Exception { assertEquals(rowCount, NUM_ROWS, "Third result: wrong number of rows returned"); rs.close(); - assertEquals(pstmt.isClosed(), true, "testUpdateCountAfterRaiseError: statement should be closed since resultset is closed."); + assertEquals(pstmt.isClosed(), true, TestResource.getResource("R_statementShouldBeClosed")); con.close(); } @@ -2487,7 +2476,7 @@ public void testUpdateCountAfterErrorInTriggerLastUpdateCountFalse() throws Exce try { result = pstmt.getMoreResults(); - assertEquals(true, false, "Second result: Expected SQLException not thrown"); + assertEquals(true, false, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { String expectedMessage; @@ -2512,7 +2501,7 @@ public void testUpdateCountAfterErrorInTriggerLastUpdateCountFalse() throws Exce ++rowCount; assertEquals(rowCount, NUM_ROWS, "Wrong number of rows in table"); assertEquals(pstmt.isClosed(), false, - "testUpdateCountAfterErrorInTrigger_LastUpdateCountFalse: statement should be open since resultset is not closed."); + TestResource.getResource("R_statementShouldBeOpened")); rs.close(); pstmt.close(); @@ -2532,7 +2521,7 @@ public void testUpdateCountAfterErrorInTriggerLastUpdateCountTrue() throws Excep try { pstmt.executeUpdate(); - assertEquals(true, false, "First result: Expected SQLException not thrown"); + assertEquals(true, false, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { String expectedMessage; @@ -2595,15 +2584,13 @@ private void setup() throws Exception { stmt.closeOnCompletion(); } catch (Exception e) { - - throw new SQLException("setup threw exception: ", e); - + throw new SQLException(TestResource.getResource("R_unexpectedException"), e); } stmt.executeUpdate("CREATE TABLE " + tableName + " (col1 INT primary key)"); for (int i = 0; i < NUM_ROWS; i++) stmt.executeUpdate("INSERT INTO " + tableName + " (col1) VALUES (" + i + ")"); - assertEquals(stmt.isClosed(), false, "setup: statement should be open since resultset not closed."); + assertEquals(stmt.isClosed(), false, TestResource.getResource("R_statementShouldBeOpened")); stmt.close(); con.commit(); con.close(); 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 754ceca1d..8109eb551 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 @@ -15,6 +15,7 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.text.MessageFormat; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -23,6 +24,7 @@ import com.microsoft.sqlserver.jdbc.ISQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatement; +import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.DBConnection; @@ -46,25 +48,32 @@ public void wrapTest() throws Exception { try { // First make sure that a statement can be unwrapped boolean isWrapper = ((SQLServerStatement) stmt).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerStatement")); - assertEquals(isWrapper, true, "SQLServerStatement should be a wrapper for self"); + + MessageFormat form = new MessageFormat(TestResource.getResource("R_shouldBeWrapper")); + MessageFormat form2 = new MessageFormat(TestResource.getResource("R_shouldNotBeWrapper")); + Object[][] msgArgs = {{"SQLStatement", "self"}, {"SQLServerStatement", "ISQLServerStatement"}, {"SQLServerCallableStatement", "SQLServerStatement"}, {"SQLServerCallableStatement", "SQLServerStatement"}}; + + assertEquals(isWrapper, true, form.format(msgArgs[0])); + isWrapper = ((SQLServerStatement) stmt).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerStatement")); - assertEquals(isWrapper, true, "SQLServerStatement should be a wrapper for ISQLServerStatement"); + assertEquals(isWrapper, true, form.format(msgArgs[1])); isWrapper = ((SQLServerStatement) stmt).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnection")); - assertEquals(isWrapper, false, "SQLServerStatement should not be a wrapper for SQLServerConnection"); + assertEquals(isWrapper, false, form2.format(msgArgs[1])); // Now make sure that we can unwrap a SQLServerCallableStatement to a SQLServerStatement CallableStatement cs = con.prepareCall("{ ? = CALL " + "ProcName" + " (?, ?, ?, ?) }"); // Test the class first isWrapper = ((SQLServerCallableStatement) cs).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerStatement")); - assertEquals(isWrapper, true, "SQLServerCallableStatement should be a wrapper for SQLServerStatement"); + assertEquals(isWrapper, true, form.format(msgArgs[2])); // Now unwrap the Callable to a statement and call a SQLServerStatement specific function and make sure it succeeds. SQLServerStatement stmt2 = (SQLServerStatement) ((SQLServerCallableStatement) cs) .unwrap(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerStatement")); stmt2.setResponseBuffering("adaptive"); // now test the interface isWrapper = ((SQLServerCallableStatement) cs).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerCallableStatement")); - assertEquals(isWrapper, true, "SQLServerCallableStatement should be a wrapper for ISQLServerCallableStatement"); + assertEquals(isWrapper, true, form.format(msgArgs[1])); + // Now unwrap the Callable to a statement and call a SQLServerStatement specific function and make sure it succeeds. ISQLServerPreparedStatement stmt4 = (ISQLServerPreparedStatement) ((SQLServerCallableStatement) cs) .unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerPreparedStatement")); @@ -75,7 +84,7 @@ public void wrapTest() throws Exception { // Try Unwrapping CallableStatement to a callableStatement isWrapper = ((SQLServerCallableStatement) cs).isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerCallableStatement")); - assertEquals(isWrapper, true, "SQLServerCallableStatement should be a wrapper for SQLServerCallableStatement"); + assertEquals(isWrapper, true, form.format(msgArgs[3])); // Now unwrap the Callable to a SQLServerCallableStatement and call a SQLServerStatement specific function and make sure it succeeds. SQLServerCallableStatement stmt3 = (SQLServerCallableStatement) ((SQLServerCallableStatement) cs) .unwrap(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerCallableStatement")); @@ -92,8 +101,8 @@ public void wrapTest() throws Exception { } catch (UnsupportedOperationException e) { - assertEquals(System.getProperty("java.specification.version"), "1.5", "isWrapperFor should be supported in anything other than 1.5"); - assertTrue(e.getMessage().equalsIgnoreCase("This operation is not supported."), "Wrong exception message"); + assertEquals(System.getProperty("java.specification.version"), "1.5", "isWrapperFor " + TestResource.getResource("R_shouldBeSupported")); + assertTrue(e.getMessage().equalsIgnoreCase("This operation is not supported."), TestResource.getResource("R_unexpectedExceptionContent")); } finally { if (null != stmt) { @@ -122,7 +131,7 @@ public void unWrapFailureTest() throws Exception { stmt.unwrap(Class.forName(str)); assertEquals(isWrapper, false, "SQLServerStatement should not be a wrapper for string"); stmt.unwrap(Class.forName(str)); - assertTrue(false, "An exception should have been thrown. This code should not be reached"); + assertTrue(false, TestResource.getResource("R_exceptionNotThrown")); } catch (SQLException ex) { Throwable t = ex.getCause(); @@ -130,8 +139,8 @@ public void unWrapFailureTest() throws Exception { assertEquals(t.getClass(), exceptionClass, "The cause in the exception class does not match"); } catch (UnsupportedOperationException e) { - assertEquals(System.getProperty("java.specification.version"), "1.5", "isWrapperFor should be supported in anything other than 1.5"); - assertEquals(e.getMessage(), "This operation is not supported.", "Wrong exception message"); + assertEquals(System.getProperty("java.specification.version"), "1.5", "isWrapperFor " + TestResource.getResource("R_shouldBeSupported")); + assertEquals(e.getMessage(), "This operation is not supported.", TestResource.getResource("R_unexpectedExceptionContent")); } finally { if (null != stmt) { From 635a1f12a55ef363b67199da457738be72b7ec94 Mon Sep 17 00:00:00 2001 From: susanh Date: Wed, 16 May 2018 18:23:10 -0400 Subject: [PATCH 2/8] resource bundle for junit test error strings --- .gitattributes | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..eb5d74682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,33 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# +# The above will handle all files NOT found below +# +# These files are text and should be normalized (Convert crlf => lf) +*.css text +*.md text +*.htm text +*.html text +*.java text +*.js text +*.json text +*.properties text +*.sh text +*.svg text +*.txt text +*.xml text + +# These files are binary and should be left untouched +# (binary is a macro for -text -diff) +*.class binary +*.dll binary +*.ear binary +*.gif binary +*.ico binary +*.jar binary +*.jpg binary +*.jpeg binary +*.png binary +*.so binary +*.war binary From 1f47684f857afe9595f83de77bffc0ff63f34c3b Mon Sep 17 00:00:00 2001 From: susanh Date: Wed, 16 May 2018 19:11:50 -0400 Subject: [PATCH 3/8] fixed typo --- .../sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java | 2 +- .../java/com/microsoft/sqlserver/jdbc/unit/lobs/lobsTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 f426db0c9..31cc49b92 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -210,7 +210,7 @@ private void testGetString(ResultSet rs, values[index].contains(stringValue1) && stringValue2.equalsIgnoreCase("" + values[index]) && stringValue3.equalsIgnoreCase("" + values[index]), TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + TestResource.getResource("R_expected Value:") + values[index]); + + TestResource.getResource("R_expectedValue:") + values[index]); } } finally { 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 6b44eb860..2753a86a8 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 @@ -209,7 +209,7 @@ else if (lobClass == Blob.class) { if (lobClass == DBCharacterStream.class || lobClass == DBBinaryStream.class) - assertTrue(e.getSQLState() != null, TestResource.getResource("RSQLStateNull")); + assertTrue(e.getSQLState() != null, TestResource.getResource("R_SQLStateNull")); assertTrue(e.getMessage().contains(TestResource.getResource("R_streamReadError"))); } From 95065546e007c0600b31c2a4388dc0249cf97bca Mon Sep 17 00:00:00 2001 From: susanh Date: Wed, 16 May 2018 19:29:27 -0400 Subject: [PATCH 4/8] fixed typo --- .../sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 31cc49b92..958d01e42 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -210,7 +210,7 @@ private void testGetString(ResultSet rs, values[index].contains(stringValue1) && stringValue2.equalsIgnoreCase("" + values[index]) && stringValue3.equalsIgnoreCase("" + values[index]), TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + TestResource.getResource("R_expectedValue:") + values[index]); + + TestResource.getResource("R_expectedValue") + values[index]); } } finally { From 3d441d9bf5056cc7433fe28fde11bd59fee46c00 Mon Sep 17 00:00:00 2001 From: susanh Date: Wed, 16 May 2018 19:49:55 -0400 Subject: [PATCH 5/8] fixed typo --- .../sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 958d01e42..0ab415eac 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -202,8 +202,8 @@ private void testGetString(ResultSet rs, try { if (rs.getMetaData().getColumnTypeName(i).equalsIgnoreCase("time")) { assertTrue(stringValue2.equalsIgnoreCase("" + values[index]) && stringValue3.equalsIgnoreCase("" + values[index]), - TestResource.getResource("R_decryptionFailed" + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 - + ".\n" + TestResource.getResource("R_expectedValue") + ": " + values[index])); + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + + ".\n" + TestResource.getResource("R_expectedValue") + ": " + values[index]); } else { assertTrue( From 8e5ae2bee7773f2491d7cbe97c4ac23cd8d12664 Mon Sep 17 00:00:00 2001 From: susanh Date: Wed, 16 May 2018 20:08:01 -0400 Subject: [PATCH 6/8] fixed typo --- .../sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0ab415eac..0a28036f9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -328,8 +328,8 @@ private void testGetDate(ResultSet rs, assertTrue( stringValue1.equalsIgnoreCase(dates[index]) && stringValue2.equalsIgnoreCase(dates[index]) && stringValue3.equalsIgnoreCase(dates[index]), - TestResource.getResource("R_decryptionFailed" + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + "\n" + TestResource.getResource("R_expectedValue") + ": " - + dates[index])); + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + "\n" + TestResource.getResource("R_expectedValue") + ": " + + dates[index]); } finally { index++; From 1a7c573c1a674d0d92171379cee7278b8bd00fb3 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Thu, 24 May 2018 15:50:16 -0700 Subject: [PATCH 7/8] review updates --- .gitattributes | 33 +------------------ .../jdbc/AlwaysEncrypted/AESetup.java | 2 +- .../JDBCEncryptionDecryptionTest.java | 2 +- .../sqlserver/jdbc/TestResource.java | 1 + .../ISQLServerBulkRecordIssuesTest.java | 4 +-- 5 files changed, 6 insertions(+), 36 deletions(-) diff --git a/.gitattributes b/.gitattributes index eb5d74682..0abcfbee4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,33 +1,2 @@ # Auto detect text files and perform LF normalization -* text=auto - -# -# The above will handle all files NOT found below -# -# These files are text and should be normalized (Convert crlf => lf) -*.css text -*.md text -*.htm text -*.html text -*.java text -*.js text -*.json text -*.properties text -*.sh text -*.svg text -*.txt text -*.xml text - -# These files are binary and should be left untouched -# (binary is a macro for -text -diff) -*.class binary -*.dll binary -*.ear binary -*.gif binary -*.ico binary -*.jar binary -*.jpg binary -*.jpeg binary -*.png binary -*.so binary -*.war binary +* -text 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 72a8b2417..2bb77e477 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -141,7 +141,7 @@ private static void readFromFile(String inputFile, filePath = Utils.getCurrentClassPath(); try { File f = new File(filePath + inputFile); - assumeTrue(f.exists(), "R_noKeyStore"); + 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/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 471643012..36ec08da9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -570,7 +570,7 @@ private void testGetObject(ResultSet rs, if (("" + values[index]).length() >= 1000) { assertTrue(matches, TestResource.getResource("R_decryptionFailed") + "getObject(): " + i + ", " + (i + 1) + ", " + (i + 2) - + ".\n" + TestResource.getResource("R_expectedValue") + index); + + ".\n" + TestResource.getResource("R_expectedValueAtIndex") + index); } else { assertTrue(matches, TestResource.getResource("R_decryptionFailed") + "getObject(): " + objectValue1 + ", " + objectValue2 + ", " + objectValue3 diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java index 490120467..4d6e59dc4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -164,6 +164,7 @@ protected Object[][] getContents() { {"R_inputParamFailed", "Test for input parameter failed."}, {"R_decryptionFailed", "Decryption failed"}, {"R_expectedValue", "Expected value: "}, + {"R_expectedValueAtIndex", "Expected value at index: "}, {"R_switchFailed", "Switch case is not matched with data"}, {"R_resultsetNotInstance", "Result set is not instance of SQLServerResultSet"}, 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 276f62619..f030fc72d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java @@ -150,7 +150,7 @@ public void testBinaryColumnAsByte() throws Exception { try (SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(connectionString)) { bcOperation.setDestinationTableName(destTable); bcOperation.writeToServer(bData); - fail("R_expectedFailPassed"); + fail(TestResource.getResource("R_expectedFailPassed")); } catch (Exception e) { if (e instanceof SQLException) { @@ -177,7 +177,7 @@ public void testBinaryColumnAsString() throws Exception { try (SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(connectionString)) { bcOperation.setDestinationTableName(destTable); bcOperation.writeToServer(bData); - fail("R_expectedFailPassed"); + fail(TestResource.getResource("R_expectedFailPassed")); } catch (Exception e) { if (e instanceof SQLException) { From c33a3256b73dc2ff8ad5de0c39442719e927959d Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 29 May 2018 11:52:25 -0700 Subject: [PATCH 8/8] more review changes --- .../sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 84b0e20cf..91bff08c2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -2328,9 +2328,9 @@ private void testOutputProcedureDateInorderObject(String sql) throws SQLExceptio assertEquals(callableStatement.getObject(9), // actual plain callableStatement.getObject(10), // received expected enc TestResource.getResource("R_outputParamFailed")); + assertEquals(callableStatement.getObject(11), callableStatement.getObject(12), TestResource.getResource("R_outputParamFailed")); assertEquals(callableStatement.getObject(13), callableStatement.getObject(14), TestResource.getResource("R_outputParamFailed")); assertEquals(callableStatement.getObject(15), callableStatement.getObject(16), TestResource.getResource("R_outputParamFailed")); -TestResource.getResource("R_outputParamFailed"); assertEquals(callableStatement.getObject(17), callableStatement.getObject(18), TestResource.getResource("R_outputParamFailed")); }