Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hardcoded names in junit tests #809

Merged
merged 37 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
69fad37
tests cleanup
lilgreenbird Aug 30, 2018
893d09e
resolved conflict
lilgreenbird Aug 30, 2018
4a3e6f8
Merge branch 'dev' into dev
lilgreenbird Aug 30, 2018
ded037b
fixed typo
lilgreenbird Aug 30, 2018
7d79eea
fixes
lilgreenbird Aug 30, 2018
bdea814
fixes
lilgreenbird Aug 30, 2018
a50d513
fixed
lilgreenbird Aug 30, 2018
a640351
review comments
lilgreenbird Aug 31, 2018
524143d
review updates
lilgreenbird Sep 4, 2018
6837404
review update
lilgreenbird Sep 5, 2018
6b43e4c
more review changes
lilgreenbird Sep 12, 2018
f5a97de
more try-with-resources changes
lilgreenbird Sep 14, 2018
6b10eec
more
lilgreenbird Sep 17, 2018
e1038ba
spacing change only
lilgreenbird Sep 17, 2018
fad3cdb
use shared statement in Abstract test again, this will be removed in …
lilgreenbird Sep 18, 2018
b4060e6
try-with-resources for Stream types
lilgreenbird Sep 18, 2018
0fec0c8
Merge remote-tracking branch 'upstream/dev' into cleanup2
lilgreenbird Sep 21, 2018
49159d8
remove hardcoded table names
lilgreenbird Sep 24, 2018
2041c35
remove shared AE vars
lilgreenbird Sep 25, 2018
0d310e4
remove hardcoded table names
lilgreenbird Sep 27, 2018
e037a70
added comment on driver bug
lilgreenbird Sep 27, 2018
d05329e
add missing escape characters
lilgreenbird Sep 28, 2018
415c3ec
get rid of unnecessary bvtTestSetup
lilgreenbird Sep 28, 2018
8389701
more hardcode
lilgreenbird Sep 28, 2018
6eca59f
Merge branch 'dev' of https://github.com/Microsoft/mssql-jdbc into cl…
lilgreenbird Sep 28, 2018
9234af9
fixed issue with AE tests
lilgreenbird Sep 29, 2018
3bc3ec7
fixed issue with AE tests
lilgreenbird Sep 29, 2018
9b118f6
removed more hardcoded values and modified BatchExecutionWithBulkCopy…
lilgreenbird Oct 1, 2018
786c966
drop all tables after tests
lilgreenbird Oct 2, 2018
ba66968
format
lilgreenbird Oct 2, 2018
f230da5
remove unused imports
lilgreenbird Oct 2, 2018
2b44b56
cleanup procedures
lilgreenbird Oct 4, 2018
4880dbf
Merge branch 'dev' into cleanup2
cheenamalhotra Oct 5, 2018
b9507ca
resolve conflicts
lilgreenbird Oct 5, 2018
7e1c1e3
Fix compilation error
cheenamalhotra Oct 5, 2018
58052ba
fix merge errors
lilgreenbird Oct 5, 2018
6495313
merge conflicts
lilgreenbird Oct 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 160 additions & 107 deletions src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

32 changes: 0 additions & 32 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,38 +380,6 @@ static byte CharToHex(char value) throws SQLException {
return ret;
}

/**
* Utility function for safely closing open resultset/statement/connection
*
* @param ResultSet
* @param Statement
* @param Connection
*/
public static void close(ResultSet rs, Statement stmt, Connection con) {
if (rs != null) {
try {
rs.close();

} catch (SQLException e) {
System.out.println("The result set cannot be closed.");
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
System.out.println("The statement cannot be closed.");
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
System.out.println("The data source connection cannot be closed.");
}
}
}

/**
* Utility method for a callable statement
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testNoExplicitCM() {
// create dest table
destTable = sourceTable.cloneSchema();
stmt.createTable(destTable);

// set up bulkCopy without explicit column mapping
BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString);
bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
Expand All @@ -82,7 +82,7 @@ public void testExplicitCM() {
// create dest table
destTable = sourceTable.cloneSchema();
stmt.createTable(destTable);

// set up bulkCopy with explicit column mapping
BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString);
bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
Expand Down Expand Up @@ -120,13 +120,14 @@ public void testExplicitCM() {
@DisplayName("BulkCopy:test unicode column mapping")
public void testUnicodeCM() {
DBTable sourceTableUnicode = null;
DBTable destTableUnicode = null;
try {
// create source unicode table
sourceTableUnicode = new DBTable(true, true);
stmt.createTable(sourceTableUnicode);

// create destination unicode table with same schema as source
DBTable destTableUnicode = sourceTableUnicode.cloneSchema();
destTableUnicode = sourceTableUnicode.cloneSchema();
stmt.createTable(destTableUnicode);

// set up bulkCopy with explicit column mapping
Expand Down Expand Up @@ -159,6 +160,9 @@ public void testUnicodeCM() {
if (null != sourceTableUnicode) {
dropTable(sourceTableUnicode.getEscapedTableName());
}
if (null != destTableUnicode) {
dropTable(destTableUnicode.getEscapedTableName());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy;
import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
import com.microsoft.sqlserver.testframework.AbstractTest;


Expand All @@ -43,8 +44,8 @@ public class BulkCopyResultSetCursorTest extends AbstractTest {
static String[] expectedTimestampStrings = {"2015-06-03 13:35:33.4610000", "2442-09-19 01:59:43.9990000",
"2017-04-02 08:58:53.0000000"};

private static String srcTable = null;
private static String desTable = null;
private static String srcTable = RandomUtil.getIdentifier("BulkCopyResultSetCursorTest_SourceTable");
private static String desTable = RandomUtil.getIdentifier("BulkCopyResultSetCursorTest_DestinationTable");

/**
* Test a previous failure when using server cursor and using the same connection to create Bulk Copy and result
Expand All @@ -68,9 +69,10 @@ private void serverCursorsTest(int resultSetType, int resultSetConcurrency) thro
populateSourceTable();

try (Statement stmt2 = conn.createStatement(resultSetType, resultSetConcurrency);
ResultSet rs = stmt2.executeQuery("select * from " + srcTable);
ResultSet rs = stmt2
.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable));
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(conn)) {
bulkCopy.setDestinationTableName(desTable);
bulkCopy.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(desTable));
bulkCopy.writeToServer(rs);

verifyDestinationTableData(expectedBigDecimals.length);
Expand All @@ -94,10 +96,10 @@ public void testSelectMethodSetToCursor() throws SQLException {
createTables(stmt);
populateSourceTable();

try (ResultSet rs = stmt.executeQuery("select * from " + srcTable);
try (ResultSet rs = stmt.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable));
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(conn)) {

bulkCopy.setDestinationTableName(desTable);
bulkCopy.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(desTable));
bulkCopy.writeToServer(rs);

verifyDestinationTableData(expectedBigDecimals.length);
Expand All @@ -119,28 +121,29 @@ public void testMultiplePreparedStatementAndResultSet() throws SQLException {
populateSourceTable();

try (Statement stmt1 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt1.executeQuery("select * from " + srcTable)) {
ResultSet rs = stmt1
.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable))) {
try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(conn)) {
bulkCopy.setDestinationTableName(desTable);
bulkCopy.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(desTable));
bulkCopy.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length);
}

rs.beforeFirst();
try (SQLServerBulkCopy bulkCopy1 = new SQLServerBulkCopy(conn)) {
bulkCopy1.setDestinationTableName(desTable);
bulkCopy1.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(desTable));
bulkCopy1.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length * 2);
}

rs.beforeFirst();
try (SQLServerBulkCopy bulkCopy2 = new SQLServerBulkCopy(conn)) {
bulkCopy2.setDestinationTableName(desTable);
bulkCopy2.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(desTable));
bulkCopy2.writeToServer(rs);
verifyDestinationTableData(expectedBigDecimals.length * 3);
}

String sql = "insert into " + desTable + " values (?,?,?,?)";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(desTable) + " values (?,?,?,?)";
Calendar calGMT = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
try (SQLServerPreparedStatement pstmt1 = (SQLServerPreparedStatement) conn.prepareStatement(sql)) {
for (int i = 0; i < expectedBigDecimals.length; i++) {
Expand All @@ -153,9 +156,11 @@ public void testMultiplePreparedStatementAndResultSet() throws SQLException {
verifyDestinationTableData(expectedBigDecimals.length * 4);
}
try (Statement stmt2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE); ResultSet rs2 = stmt2.executeQuery("select * from " + srcTable);
ResultSet.CONCUR_UPDATABLE);
ResultSet rs2 = stmt2
.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable));
SQLServerBulkCopy bulkCopy3 = new SQLServerBulkCopy(conn)) {
bulkCopy3.setDestinationTableName(desTable);
bulkCopy3.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(desTable));
bulkCopy3.writeToServer(rs2);
verifyDestinationTableData(expectedBigDecimals.length * 5);
}
Expand All @@ -164,8 +169,8 @@ public void testMultiplePreparedStatementAndResultSet() throws SQLException {
}

private static void verifyDestinationTableData(int expectedNumberOfRows) throws SQLException {
try (Connection conn = DriverManager.getConnection(connectionString);
ResultSet rs = conn.createStatement().executeQuery("select * from " + desTable)) {
try (Connection conn = DriverManager.getConnection(connectionString); ResultSet rs = conn.createStatement()
.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(desTable))) {

int expectedArrayLength = expectedBigDecimals.length;

Expand All @@ -187,7 +192,7 @@ private static void verifyDestinationTableData(int expectedNumberOfRows) throws
}

private static void populateSourceTable() throws SQLException {
String sql = "insert into " + srcTable + " values (?,?,?,?)";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(srcTable) + " values (?,?,?,?)";
Calendar calGMT = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

try (Connection conn = DriverManager.getConnection(connectionString);
Expand All @@ -205,26 +210,18 @@ private static void populateSourceTable() throws SQLException {

private static void dropTables(Statement stmt) throws SQLException {
if (null != srcTable) {
TestUtils.dropTableIfExists(srcTable, stmt);
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(srcTable), stmt);
}
if (null != desTable) {
TestUtils.dropTableIfExists(desTable, stmt);
TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(desTable), stmt);
}
}

private static void createTables(Statement stmt) throws SQLException {

if (null == srcTable) {
srcTable = "[BulkCopyResultSetCursorTest_Source_" + RandomUtil.getIdentifier("table") + "]";
}
if (null == desTable) {
desTable = "[BulkCopyResultSetCursorTest_Destination_" + RandomUtil.getIdentifier("table") + "]";
}

String sql = "create table " + srcTable
String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(srcTable)
+ " (c1 decimal(10,5) null, c2 nchar(50) null, c3 datetime2(7) null, c4 char(7000));";
stmt.execute(sql);
sql = "create table " + desTable
sql = "create table " + AbstractSQLGenerator.escapeIdentifier(desTable)
+ " (c1 decimal(10,5) null, c2 nchar(50) null, c3 datetime2(7) null, c4 char(7000));";
stmt.execute(sql);
}
Expand Down
Loading