Skip to content

Commit

Permalink
More review + format
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffery-Wasty committed Apr 4, 2024
1 parent 70812b9 commit fa906bb
Showing 1 changed file with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
}
}

Expand All @@ -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());
}
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}

0 comments on commit fa906bb

Please sign in to comment.