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

Add ability to perform JUnit testing against Azure DW #903

Merged
merged 22 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.platform.version>1.3.1</junit.platform.version>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
<testGroup></testGroup>
</properties>

<dependencies>
Expand Down Expand Up @@ -197,6 +198,7 @@
<properties>
<excludeTags>${skipTestTag}</excludeTags>
</properties>
<groups>${testGroup}</groups>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -266,6 +268,7 @@
<properties>
<excludeTags>${skipTestTag}</excludeTags>
</properties>
<groups>${testGroup}</groups>
</configuration>
</plugin>
</plugins>
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protected Object[][] getContents() {
{"R_conversionFailed", "Conversion failed when converting {0} to {1} data type"},
{"R_invalidQueryTimeout", "The query timeout value {0} is not valid."},
{"R_skipAzure", "Skipping test case on Azure SQL."},
{"R_issueAzureDW", "This is a known failure in DW for now."},
{"R_spatialDWNotSupported", "Geometry/Geography is not supported for DW."},
{"R_expectedExceptionNotThrown", "Expected exception is not thrown."},
{"R_errorNotCalled", "Error occurred is not called."}, {"R_errorCalled", "Error occurred is called."},
{"R_supportUnwrapping", "{0} supports unwrapping."},
Expand Down Expand Up @@ -127,6 +129,7 @@ protected Object[][] getContents() {
{"R_errorFollowInserts", "Test error followed by inserts"},
{"R_errorFollow50280", "Test insert followed by non-fatal error (50280)"},
{"R_syntaxErrorDateConvert", "Syntax error converting date"},
{"R_syntaxErrorDateConvertDW", "Conversion failed when converting date and/or time from character string."},
{"R_dateConvertError", "Conversion failed when converting date"},
{"R_incompatJDBC", "Aborting test case as JDBC version is not compatible."},
{"R_unexpectedException", "Unexpected exception occurred"}, {"R_addBatchFailed", "addBatch failed"},
Expand All @@ -152,7 +155,5 @@ protected Object[][] getContents() {
{"R_inputParamFailed", "Test for input parameter failed."}, {"R_decryptionFailed", "Decryption failed"},
{"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_resultsetNotInstance", "Result set is not instance of SQLServerResultSet"},};
}
1 change: 1 addition & 0 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class TestUtils {
// 'SQL' represents SQL Server, while 'SQLAzure' represents SQL Azure.
public static final String SERVER_TYPE_SQL_SERVER = "SQL";
public static final String SERVER_TYPE_SQL_AZURE = "SQLAzure";

// private static SqlType types = null;
private static ArrayList<SqlType> types = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ public class BulkCopyAllTypesTest extends AbstractTest {
*/
@Test
public void testTVPResultSet() throws SQLException {
testBulkCopyResultSet(false, null, null);
testBulkCopyResultSet(true, null, null);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
if (AbstractTest.isSqlAzureDW()) {
testBulkCopyResultSet(false, null, null);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
} else {
testBulkCopyResultSet(false, null, null);
testBulkCopyResultSet(true, null, null);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
}
}

private void testBulkCopyResultSet(boolean setSelectMethod, Integer resultSetType,
Expand Down
19 changes: 13 additions & 6 deletions src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import java.math.BigDecimal;
import java.sql.DatabaseMetaData;
Expand All @@ -15,26 +16,27 @@
import java.util.regex.Pattern;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;

import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractTest;
import com.microsoft.sqlserver.testframework.DBConnection;
import com.microsoft.sqlserver.testframework.DBStatement;
import com.microsoft.sqlserver.testframework.DBTable;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.testframework.DBPreparedStatement;
import com.microsoft.sqlserver.testframework.DBResultSet;
import com.microsoft.sqlserver.testframework.DBResultSetTypes;


@RunWith(JUnitPlatform.class)
@DisplayName("BVT Test")
@Tag("AzureDWTest")
public class BvtTest extends AbstractTest {
private static String driverNamePattern = "Microsoft JDBC Driver \\d.\\d for SQL Server";
static DBTable table1;
Expand Down Expand Up @@ -147,6 +149,7 @@ public void testStmtForwardOnlyReadOnly() throws SQLException, ClassNotFoundExce
*/
@Test
public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFoundException {
assumeFalse(AbstractTest.isSqlAzureDW(), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_INSENSITIVE_CONCUR_READ_ONLY);
DBResultSet rs = stmt.selectAll(table1)) {
Expand All @@ -167,6 +170,7 @@ public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFou
*/
@Test
public void testStmtScrollSensitiveReadOnly() throws SQLException {
assumeFalse(AbstractTest.isSqlAzureDW(), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY);
DBResultSet rs = stmt.selectAll(table1)) {
Expand All @@ -189,6 +193,7 @@ public void testStmtScrollSensitiveReadOnly() throws SQLException {
*/
@Test
public void testStmtForwardOnlyUpdateable() throws SQLException {
assumeFalse(AbstractTest.isSqlAzureDW(), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_UPDATABLE);
DBResultSet rs = stmt.selectAll(table1)) {
Expand Down Expand Up @@ -216,6 +221,7 @@ public void testStmtForwardOnlyUpdateable() throws SQLException {
*/
@Test
public void testStmtScrollSensitiveUpdatable() throws SQLException {
assumeFalse(AbstractTest.isSqlAzureDW(), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE);
DBResultSet rs = stmt.selectAll(table1)) {
Expand All @@ -239,7 +245,7 @@ public void testStmtScrollSensitiveUpdatable() throws SQLException {
*/
@Test
public void testStmtSSScrollDynamicOptimisticCC() throws SQLException {

assumeFalse(AbstractTest.isSqlAzureDW(), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_DYNAMIC_CONCUR_OPTIMISTIC);
DBResultSet rs = stmt.selectAll(table1)) {
Expand Down Expand Up @@ -412,6 +418,7 @@ public void testResultSetAndCloseStmt() throws SQLException {
*/
@Test
public void testResultSetSelectMethod() throws SQLException {
assumeFalse(AbstractTest.isSqlAzureDW(), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString + ";selectMethod=cursor;");
DBStatement stmt = conn.createStatement(); DBResultSet rs = stmt.selectAll(table1)) {
rs.verify(table1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
import com.microsoft.sqlserver.testframework.AbstractTest;
import com.microsoft.sqlserver.testframework.DBConnection;


@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class ConnectionDriverTest extends AbstractTest {
// If no retry is done, the function should at least exit in 5 seconds
static int threshHoldForNoRetryInMilliseconds = 5000;
Expand Down Expand Up @@ -165,8 +165,7 @@ public void connectionErrorOccurred(ConnectionEvent event) {
*/
@Test
public void testConnectionEvents() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));
assumeTrue(!isSqlAzure(), TestResource.getResource("R_skipAzure"));

SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource();
mds.setURL(connectionString);
Expand Down Expand Up @@ -197,8 +196,7 @@ public void testConnectionEvents() throws SQLException {

@Test
public void testConnectionPoolGetTwice() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));
assumeTrue(!isSqlAzure(), TestResource.getResource("R_skipAzure"));

SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource();
mds.setURL(connectionString);
Expand All @@ -211,7 +209,7 @@ public void testConnectionPoolGetTwice() throws SQLException {
try (Connection con = pooledConnection.getConnection();
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
// raise a non severe exception and make sure that the connection is not closed.
stmt.executeUpdate("RAISERROR ('foo', 3,1) WITH LOG");
stmt.executeUpdate("RAISERROR ('foo', 3,1)");
// not a serious error there should not be any errors.
assertTrue(!myE.errorOccurred, TestResource.getResource("R_errorCalled"));
// check to make sure that connection is not closed.
Expand All @@ -225,8 +223,7 @@ public void testConnectionPoolGetTwice() throws SQLException {

@Test
public void testConnectionClosed() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));
assumeTrue(!isSqlAzure(), TestResource.getResource("R_skipAzure"));

SQLServerDataSource mds = new SQLServerDataSource();
mds.setURL(connectionString);
Expand Down Expand Up @@ -304,8 +301,7 @@ public void testNegativeTimeout() throws Exception {

@Test
public void testDeadConnection() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));
assumeTrue(!isSqlAzure(), TestResource.getResource("R_skipAzure"));

String tableName = RandomUtil.getIdentifier("ConnectionTestTable");
try (SQLServerConnection conn = (SQLServerConnection) DriverManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand All @@ -27,6 +28,7 @@
*
*/
@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class ConnectionWrapper43Test extends AbstractTest {
static Connection connection = null;
double javaVersion = Double.parseDouble(System.getProperty("java.specification.version"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Arrays;
import java.util.Random;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand All @@ -27,6 +28,7 @@
*
*/
@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class DriverVersionTest extends AbstractTest {
Random rand = new Random();
int major = rand.nextInt(256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.sql.Connection;
import java.sql.SQLException;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand All @@ -29,17 +30,18 @@
import com.microsoft.sqlserver.testframework.AbstractTest;


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

@Test
@Tag("AzureDWTest")
public void testNativeMSSQLDataSource() throws SQLException {
SQLServerXADataSource ds = new SQLServerXADataSource();
ds.setLastUpdateCount(true);
assertTrue(ds.getLastUpdateCount());
}

@Test
@Tag("AzureDWTest")
public void testSerialization() throws IOException {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutput objectOutput = new ObjectOutputStream(outputStream)) {
Expand All @@ -52,6 +54,7 @@ public void testSerialization() throws IOException {
}

@Test
@Tag("AzureDWTest")
public void testDSNormal() throws ClassNotFoundException, IOException, SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
Expand All @@ -74,6 +77,7 @@ public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLEx
}

@Test
@Tag("AzureDWTest")
public void testInterfaceWrapping() throws ClassNotFoundException, SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
assertEquals(true, ds.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apache.commons.dbcp2.BasicDataSource;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand All @@ -35,7 +36,6 @@
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
import com.microsoft.sqlserver.testframework.AbstractTest;
import com.microsoft.sqlserver.testframework.DBConnection;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

Expand All @@ -45,14 +45,14 @@
*
*/
@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class PoolingTest extends AbstractTest {
static String tempTableName = RandomUtil.getIdentifier("#poolingtest");
static String tableName = RandomUtil.getIdentifier("PoolingTestTable");

@Test
public void testPooling() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
"Skipping test case on Azure SQL.");
assumeTrue(!isSqlAzure(), TestResource.getResource("R_skipAzure"));

SQLServerXADataSource XADataSource1 = new SQLServerXADataSource();
XADataSource1.setURL(connectionString);
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testConnectionPoolConnFunctions() throws SQLException {
String sql1 = "if exists (select * from dbo.sysobjects where name = '" + TestUtils.escapeSingleQuotes(tableName)
+ "' and type = 'U')\n" + "drop table " + AbstractSQLGenerator.escapeIdentifier(tableName) + "\n"
+ "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + "\n" + "(\n"
+ "wibble_id int primary key not null,\n" + "counter int null\n" + ");";
+ "wibble_id int not null,\n" + "counter int null\n" + ");";
String sql2 = "if exists (select * from dbo.sysobjects where name = '" + TestUtils.escapeSingleQuotes(tableName)
+ "' and type = 'U')\n" + "drop table " + AbstractSQLGenerator.escapeIdentifier(tableName) + "\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.sql.DriverManager;
import java.text.MessageFormat;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand All @@ -27,6 +28,7 @@
* Tests new connection property sslProtocol
*/
@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class SSLProtocolTest extends AbstractTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;
import java.util.Properties;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand All @@ -25,6 +26,7 @@


@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class WarningTest extends AbstractTest {
@Test
public void testWarnings() throws SQLException {
Expand Down
Loading