-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests | Added more datatype tests to increase code coverage (#878)
* ported tests from VSO and added tests to increase code coverage * moved resultset tests to resultset * removed unused import * added tests to increase code coverage * fixed issue with timezone * fixed issue with timezone * modified testWithThaiLocale to use current time * fixed issue with timezone * fixed issue with timezone * fixed issue with timezone * added SparseTest and BigIntegerTest and cleaned up with try-with-resources * review changes * review comments * more review updates * review updates * removed dummy file * review udpates * more cleanup * updated isSqlAzure * review updates * more review updates * fixed imports * updated failed error strings with more detail * added locale to time format * format date for comparision * 1 more timezone fix * cleanup leaded stream resources * manually merged with #903 changes for now * more cleanup on assertEqual checks * more cleanup on assertEqual checks * cosmetic changes from review * updated all assertEquals params to proper expected, actual order * fixed comments and leaked resultsets
- Loading branch information
Showing
10 changed files
with
2,413 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.