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

Tests | Added more datatype tests to increase code coverage #878

Merged
merged 39 commits into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
eb3df3a
ported tests from VSO and added tests to increase code coverage
lilgreenbird Nov 13, 2018
c31b1f3
moved resultset tests to resultset
lilgreenbird Nov 14, 2018
145ee72
removed unused import
lilgreenbird Nov 14, 2018
fd123b2
added tests to increase code coverage
lilgreenbird Nov 16, 2018
3275750
fixed issue with timezone
lilgreenbird Nov 17, 2018
45eeef5
fixed issue with timezone
lilgreenbird Nov 17, 2018
c5f4a9d
modified testWithThaiLocale to use current time
lilgreenbird Nov 19, 2018
d93e0fe
fixed issue with timezone
lilgreenbird Nov 19, 2018
27702d3
fixed issue with timezone
lilgreenbird Nov 19, 2018
a48c810
fixed issue with timezone
lilgreenbird Nov 20, 2018
9c697cf
added SparseTest and BigIntegerTest and cleaned up with try-with-reso…
lilgreenbird Nov 20, 2018
83b6ddc
review changes
lilgreenbird Nov 23, 2018
b3c5ac5
review comments
lilgreenbird Nov 23, 2018
8f71ce6
more review updates
lilgreenbird Nov 23, 2018
c46db9f
review updates
lilgreenbird Nov 26, 2018
e9556dd
Merge remote-tracking branch 'upstream/dev' into cov
lilgreenbird Nov 26, 2018
3a0703d
removed dummy file
lilgreenbird Nov 26, 2018
d507114
review udpates
lilgreenbird Nov 27, 2018
2994200
more cleanup
lilgreenbird Nov 27, 2018
e3512f9
updated isSqlAzure
lilgreenbird Nov 28, 2018
e4cb7f2
Merge branch 'cov' of https://github.com/lilgreenbird/mssql-jdbc into…
lilgreenbird Dec 13, 2018
5217270
review updates
lilgreenbird Dec 13, 2018
79ac177
more review updates
lilgreenbird Dec 13, 2018
ada91ae
fixed imports
lilgreenbird Dec 13, 2018
36838a8
updated failed error strings with more detail
lilgreenbird Dec 13, 2018
a196be9
added locale to time format
lilgreenbird Dec 13, 2018
c7df1ed
format date for comparision
lilgreenbird Dec 13, 2018
dbcc0a3
1 more timezone fix
lilgreenbird Dec 14, 2018
f36c132
Merge remote-tracking branch 'upstream/dev' into cov
lilgreenbird Dec 14, 2018
bcc8732
cleanup leaded stream resources
lilgreenbird Dec 17, 2018
a5ee49f
Merge remote-tracking branch 'upstream/dev' into cov
lilgreenbird Dec 17, 2018
62f615b
Merge remote-tracking branch 'upstream/dev' into cov
lilgreenbird Dec 18, 2018
fe01b41
manually merged with #903 changes for now
lilgreenbird Dec 18, 2018
d72eccc
merged
lilgreenbird Dec 18, 2018
238b66f
more cleanup on assertEqual checks
lilgreenbird Dec 18, 2018
dc1a721
more cleanup on assertEqual checks
lilgreenbird Dec 18, 2018
6eac22c
cosmetic changes from review
lilgreenbird Dec 19, 2018
72956ed
updated all assertEquals params to proper expected, actual order
lilgreenbird Dec 19, 2018
db38827
fixed comments and leaked resultsets
lilgreenbird Dec 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ protected Object[][] getContents() {
{"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"},
{"R_noJRESupport", "No JRE support for {0}"},
{"R_incorrectColumnNum", "Column name or number of supplied values does not match table definition."},
{"R_incorrectColumnNumInsert",
"There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement."},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.MessageFormat;
import java.util.concurrent.ThreadLocalRandom;

Expand All @@ -22,6 +23,7 @@

import com.microsoft.sqlserver.jdbc.ComparisonUtil;
import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.DBConnection;
import com.microsoft.sqlserver.testframework.DBResultSet;
import com.microsoft.sqlserver.testframework.DBStatement;
Expand Down Expand Up @@ -56,7 +58,7 @@ public static void closeConnection() throws SQLException {

@Test
@DisplayName("BulkCopy:test no explicit column mapping")
public void testNoExplicitCM() {
public void testNoExplicitCM() throws SQLException {
DBTable destTable = null;
try {
// create dest table
Expand All @@ -68,16 +70,13 @@ public void testNoExplicitCM() {
bulkWrapper.setUsingConnection((0 == ThreadLocalRandom.current().nextInt(2)) ? true : false);
BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTable, destTable);
} finally {
if (null != destTable) {
// drop dest table
stmt.dropTable(destTable);
}
TestUtils.dropTableIfExists(destTable.getEscapedTableName(), (Statement) stmt.product());
}
}

@Test
@DisplayName("BulkCopy:test explicit column mapping")
public void testExplicitCM() {
public void testExplicitCM() throws SQLException {
DBTable destTable = null;
try {
// create dest table
Expand Down Expand Up @@ -110,16 +109,13 @@ public void testExplicitCM() {
}
BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTable, destTable);
} finally {
// drop dest table
if (null != destTable) {
stmt.dropTable(destTable);
}
TestUtils.dropTableIfExists(destTable.getEscapedTableName(), (Statement) stmt.product());
}
}

@Test
@DisplayName("BulkCopy:test unicode column mapping")
public void testUnicodeCM() {
public void testUnicodeCM() throws SQLException {
DBTable sourceTableUnicode = null;
DBTable destTableUnicode = null;
try {
Expand Down Expand Up @@ -158,18 +154,14 @@ public void testUnicodeCM() {
}
BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTableUnicode, destTableUnicode);
} finally {
if (null != sourceTableUnicode) {
dropTable(sourceTableUnicode.getEscapedTableName());
}
if (null != destTableUnicode) {
dropTable(destTableUnicode.getEscapedTableName());
}
TestUtils.dropTableIfExists(sourceTableUnicode.getEscapedTableName(), (Statement) stmt.product());
TestUtils.dropTableIfExists(destTableUnicode.getEscapedTableName(), (Statement) stmt.product());
}
}

@Test
@DisplayName("BulkCopy:test repetitive column mapping")
public void testRepetitiveCM() {
public void testRepetitiveCM() throws SQLException {
DBTable sourceTable1 = null;
DBTable destTable = null;
try {
Expand Down Expand Up @@ -225,18 +217,14 @@ public void testRepetitiveCM() {
fail(form.format(msgArgs) + "\n" + destTable.getTableName() + "\n" + e.getMessage());
}
} finally {
if (null != sourceTable1) {
dropTable(sourceTable1.getEscapedTableName());
}
if (null != destTable) {
dropTable(destTable.getEscapedTableName());
}
TestUtils.dropTableIfExists(sourceTable1.getEscapedTableName(), (Statement) stmt.product());
TestUtils.dropTableIfExists(destTable.getEscapedTableName(), (Statement) stmt.product());
}
}

@Test
@DisplayName("BulkCopy:test implicit mismatched column mapping")
public void testImplicitMismatchCM() {
public void testImplicitMismatchCM() throws SQLException {
DBTable destTable = null;
try {
// create non unicode dest table with different schema from source table
Expand Down Expand Up @@ -269,15 +257,13 @@ public void testImplicitMismatchCM() {
}
BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTable, destTable, true, true);
} finally {
if (null != destTable) {
stmt.dropTable(destTable);
}
TestUtils.dropTableIfExists(destTable.getEscapedTableName(), (Statement) stmt.product());
}
}

@Test
@DisplayName("BulkCopy:test invalid column mapping")
public void testInvalidCM() {
public void testInvalidCM() throws SQLException {
DBTable destTable = null;
try {
// create dest table
Expand Down Expand Up @@ -360,9 +346,7 @@ public void testInvalidCM() {
bulkWrapper.setColumnMapping(Integer.MIN_VALUE, Integer.MAX_VALUE);
BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTable, destTable, true, true);
} finally {
if (null != destTable) {
stmt.dropTable(destTable);
}
TestUtils.dropTableIfExists(destTable.getEscapedTableName(), (Statement) stmt.product());
}
}

Expand Down Expand Up @@ -411,15 +395,4 @@ private void validateValuesRepetitiveCM(DBConnection con, DBTable sourceTable,
assertTrue(destinationTable.getTotalRows() == numRows);
}
}

private void dropTable(String tableName) {

String dropSQL = "DROP TABLE [dbo]." + tableName;
try {
stmt.execute(dropSQL);
} catch (SQLException e) {
fail(tableName + " " + TestResource.getResource("R_tableNotDropped") + "\n" + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.microsoft.sqlserver.jdbc.callablestatement;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

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.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
import com.microsoft.sqlserver.testframework.AbstractTest;


@RunWith(JUnitPlatform.class)
public class CallableMixedTest extends AbstractTest {

@Test
public void datatypestest() throws Exception {
String tableName = RandomUtil.getIdentifier("TFOO3");
String escapedTableName = AbstractSQLGenerator.escapeIdentifier(tableName);
String procName = RandomUtil.getIdentifier("SPFOO3");
String escapedProcName = AbstractSQLGenerator.escapeIdentifier(procName);

try (Connection conn = DriverManager.getConnection(connectionString)) {
try (Statement stmt = conn.createStatement()) {
TestUtils.dropTableIfExists(escapedTableName, stmt);

String createSQL = "create table " + escapedTableName + "(c1_int int primary key, col2 int)";
stmt.executeUpdate(createSQL);

stmt.executeUpdate("Insert into " + escapedTableName + " values(0, 1)");

stmt.executeUpdate("CREATE PROCEDURE " + escapedProcName
+ " (@p2_int int, @p2_int_out int OUTPUT, @p4_smallint smallint, @p4_smallint_out smallint OUTPUT) AS begin transaction SELECT * FROM "
+ escapedTableName
+ " ; SELECT @p2_int_out=@p2_int, @p4_smallint_out=@p4_smallint commit transaction RETURN -2147483648");
}

try (CallableStatement cstmt = conn.prepareCall("{ ? = CALL " + escapedProcName + " (?, ?, ?, ?) }")) {
cstmt.registerOutParameter((int) 1, (int) 4);
cstmt.setObject((int) 2, Integer.valueOf("31"), (int) 4);
cstmt.registerOutParameter((int) 3, (int) 4);

// Test OUT param re-registration
cstmt.registerOutParameter((int) 5, java.sql.Types.BINARY);
cstmt.registerOutParameter((int) 5, (int) 5);
cstmt.setObject((int) 4, Short.valueOf("-5372"), (int) 5);

// get results and a value
try (ResultSet rs = cstmt.executeQuery()) {
rs.next();
assertEquals(0, rs.getInt(1));
assertEquals(-5372, cstmt.getInt((int) 5));
}

// get the param without getting the resultset
try (ResultSet rs = cstmt.executeQuery()) {
assertEquals(-2147483648, cstmt.getInt((int) 1));
}

try (ResultSet rs = cstmt.executeQuery()) {
rs.next();
assertEquals(0, rs.getInt(1));
assertEquals(-2147483648, cstmt.getInt((int) 1));
assertEquals(-5372, cstmt.getInt((int) 5));
}
}
} finally {
try (Connection conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement()) {
TestUtils.dropTableIfExists(escapedTableName, stmt);
} catch (SQLException e) {
fail(e.toString());
}
}
}
}
Loading