From ddc6f118a40ba36a47b22a5a03015aef4e91fed8 Mon Sep 17 00:00:00 2001 From: machavan Date: Mon, 13 Jan 2025 17:17:21 +0530 Subject: [PATCH 1/4] Fixed exception type to SQLfeatureNotSupported --- .../sqlserver/jdbc/SQLServerConnection.java | 5 ++++- .../sqlserver/jdbc/unit/SavepointTest.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 42ae6647d..a6cdc4951 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -22,6 +22,7 @@ import java.sql.ResultSet; import java.sql.SQLClientInfoException; import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLPermission; import java.sql.SQLWarning; import java.sql.SQLXML; @@ -7196,7 +7197,9 @@ public PreparedStatement prepareStatement(String sql, String[] columnNames, @Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { loggerExternal.entering(loggingClassName, "releaseSavepoint", savepoint); - SQLServerException.throwNotSupportedException(this, null); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_featureNotSupported")); + Object[] msgArgs = {"releaseSavepoint"}; + throw new SQLFeatureNotSupportedException(form.format(msgArgs)); } final private Savepoint setNamedSavepoint(String sName) throws SQLServerException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java index 63a9c9567..342e3cfca 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java @@ -10,6 +10,7 @@ import java.sql.Connection; import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; import java.text.MessageFormat; import com.microsoft.sqlserver.jdbc.TestUtils; @@ -136,4 +137,21 @@ public void testSavePointWithAutoCommit() throws SQLException { } catch (SQLException e) {} } } + + /** + * Test releaseSavepoint. + * + * @throws SQLException + */ + @Test + public void testReleaseSavepoint() throws SQLException { + try (Connection connection = getConnection()) { + try { + connection.releaseSavepoint(null); + } catch (SQLException e) { + assertTrue(e instanceof SQLFeatureNotSupportedException); + } + } + } + } From 85f525dea541e8cf64b529700e268630628e4db9 Mon Sep 17 00:00:00 2001 From: machavan Date: Mon, 13 Jan 2025 17:42:32 +0530 Subject: [PATCH 2/4] Improved test --- .../com/microsoft/sqlserver/jdbc/TestResource.java | 3 ++- .../microsoft/sqlserver/jdbc/unit/SavepointTest.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java index 29a5e21dd..b6d63825f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -216,5 +216,6 @@ protected Object[][] getContents() { {"R_expectedClassDoesNotMatchActualClass", "Expected column class {0} does not match actual column class {1} for column {2}."}, {"R_loginFailedMI", "Login failed for user ''"}, - {"R_MInotAvailable", "Managed Identity authentication is not available"},}; + {"R_MInotAvailable", "Managed Identity authentication is not available"}, + {"R_featureNotSupported", "{0} is not supported."},}; } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java index 342e3cfca..b5de47fbd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java @@ -4,6 +4,7 @@ */ package com.microsoft.sqlserver.jdbc.unit; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -13,7 +14,6 @@ import java.sql.SQLFeatureNotSupportedException; import java.text.MessageFormat; -import com.microsoft.sqlserver.jdbc.TestUtils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -149,7 +149,13 @@ public void testReleaseSavepoint() throws SQLException { try { connection.releaseSavepoint(null); } catch (SQLException e) { - assertTrue(e instanceof SQLFeatureNotSupportedException); + assertEquals(e.getClass(), SQLFeatureNotSupportedException.class, "Expected exception type " + SQLFeatureNotSupportedException.class.getName() + ", but received " + e.getClass().getName()); + + MessageFormat form = new MessageFormat(TestResource.getResource("R_featureNotSupported")); + Object[] msgArgs = {"releaseSavepoint"}; + String expectedExceptionMsg = form.format(msgArgs); + String receivedExceptionMsg = e.getMessage(); + assertEquals(expectedExceptionMsg, receivedExceptionMsg, "Expected exception message " + expectedExceptionMsg + ", but received " + receivedExceptionMsg);; } } } From 001bfd2e7e7d892d7e739a1b155a6b56bbb5ee92 Mon Sep 17 00:00:00 2001 From: machavan Date: Wed, 15 Jan 2025 10:10:46 +0530 Subject: [PATCH 3/4] Simplified checking of expected exception --- .../java/com/microsoft/sqlserver/jdbc/TestResource.java | 3 +-- .../com/microsoft/sqlserver/jdbc/unit/SavepointTest.java | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java index b6d63825f..29a5e21dd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -216,6 +216,5 @@ protected Object[][] getContents() { {"R_expectedClassDoesNotMatchActualClass", "Expected column class {0} does not match actual column class {1} for column {2}."}, {"R_loginFailedMI", "Login failed for user ''"}, - {"R_MInotAvailable", "Managed Identity authentication is not available"}, - {"R_featureNotSupported", "{0} is not supported."},}; + {"R_MInotAvailable", "Managed Identity authentication is not available"},}; } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java index b5de47fbd..ed2b64a3b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java @@ -23,6 +23,7 @@ import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerSavepoint; import com.microsoft.sqlserver.jdbc.TestResource; +import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Constants; @@ -151,11 +152,7 @@ public void testReleaseSavepoint() throws SQLException { } catch (SQLException e) { assertEquals(e.getClass(), SQLFeatureNotSupportedException.class, "Expected exception type " + SQLFeatureNotSupportedException.class.getName() + ", but received " + e.getClass().getName()); - MessageFormat form = new MessageFormat(TestResource.getResource("R_featureNotSupported")); - Object[] msgArgs = {"releaseSavepoint"}; - String expectedExceptionMsg = form.format(msgArgs); - String receivedExceptionMsg = e.getMessage(); - assertEquals(expectedExceptionMsg, receivedExceptionMsg, "Expected exception message " + expectedExceptionMsg + ", but received " + receivedExceptionMsg);; + assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_featureNotSupported"))); } } } From 0bb9238f8883840d36f89bd1c473d5f7e7583de0 Mon Sep 17 00:00:00 2001 From: machavan Date: Wed, 15 Jan 2025 10:13:12 +0530 Subject: [PATCH 4/4] Removed unnecessary change --- .../java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java index ed2b64a3b..9dad4703f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java @@ -14,6 +14,7 @@ import java.sql.SQLFeatureNotSupportedException; import java.text.MessageFormat; +import com.microsoft.sqlserver.jdbc.TestUtils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -23,7 +24,6 @@ import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerSavepoint; import com.microsoft.sqlserver.jdbc.TestResource; -import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Constants;