diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyMoneyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyMoneyTest.java index 5f6c4bc4d..d4b6f1608 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyMoneyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyMoneyTest.java @@ -3,9 +3,9 @@ import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.ResultSet; @@ -14,15 +14,17 @@ import java.util.HashMap; import java.util.Map; -import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord; -import com.microsoft.sqlserver.jdbc.TestResource; -import com.microsoft.sqlserver.jdbc.TestUtils; -import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import com.microsoft.sqlserver.jdbc.RandomUtil; +import com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord; +import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; +import com.microsoft.sqlserver.jdbc.TestResource; +import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Constants; @@ -38,15 +40,14 @@ public class BulkCopyMoneyTest extends AbstractTest { static String delimiter = Constants.COMMA; static String destTableName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("moneyBulkCopyDest")); static String destTableName2 = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("moneyBulkCopyDest")); + @Test public void testMoneyWithBulkCopy() throws SQLException { - beforeEachSetup(); - try (Connection conn = PrepUtil.getConnection(connectionString)) { - testMoneyLimits(-214799.3648, 922337203685387.5887, conn); // SMALLMONEY MIN - testMoneyLimits(214799.3698, 922337203685387.5887, conn); // SMALLMONEY MAX - testMoneyLimits(214719.3698, -922337203685497.5808, conn); // MONEY MIN - testMoneyLimits(214719.3698, 922337203685478.5807, conn); // MONEY MAX + testMoneyLimits(-214799.3648, 922337203685387.5887, conn); // SMALLMONEY MIN + testMoneyLimits(214799.3698, 922337203685387.5887, conn); // SMALLMONEY MAX + testMoneyLimits(214719.3698, -922337203685497.5808, conn); // MONEY MIN + testMoneyLimits(214719.3698, 922337203685478.5807, conn); // MONEY MAX } } @@ -57,8 +58,7 @@ private void testMoneyLimits(double smallMoneyVal, double moneyVal, Connection c testMoneyWithBulkCopy(conn, fileRecord); fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_valueOutOfRange")), - e.getMessage()); + assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_valueOutOfRange")), e.getMessage()); } } @@ -70,8 +70,7 @@ private SQLServerBulkCSVFileRecord constructFileRecord(double smallMoneyVal, dou stringBuilder.append("smallmoneycol, moneycol\n"); for (Map.Entry entry : data.entrySet()) { - stringBuilder.append( - String.format("%s,%s\n", entry.getKey(), entry.getValue())); + stringBuilder.append(String.format("%s,%s\n", entry.getKey(), entry.getValue())); } byte[] bytes = stringBuilder.toString().getBytes(StandardCharsets.UTF_8); @@ -99,7 +98,8 @@ private void testMoneyWithBulkCopy(Connection conn, SQLServerBulkCSVFileRecord f } } - private void beforeEachSetup() throws SQLException { + @BeforeAll + public static void setupTests() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(destTableName, stmt); TestUtils.dropTableIfExists(destTableName2, stmt); @@ -110,4 +110,12 @@ private void beforeEachSetup() throws SQLException { stmt.execute(table); } } + + @AfterAll + public static void cleanUp() throws Exception { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + TestUtils.dropTableIfExists(destTableName, stmt); + TestUtils.dropTableIfExists(destTableName2, stmt); + } + } }