Search in sources :

Example 11 with DBConnection

use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.

the class bvtTest method testStmtSSScrollDynamicOptimisticCC.

/**
 * Create a statement TYPE_SS_SCROLL_DYNAMIC, CONCUR_SS_OPTIMISTIC_CC, executeQuery verify cursor by using next and previous and verify data
 *
 * @throws SQLException
 */
@Test
public void testStmtSSScrollDynamicOptimisticCC() throws SQLException {
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_DYNAMIC_CONCUR_OPTIMISTIC);
        DBResultSet rs = stmt.selectAll(table1)) {
        // Verify resultset behavior
        rs.next();
        rs.afterLast();
        rs.previous();
        rs.verify(table1);
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

Example 12 with DBConnection

use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.

the class bvtTest method testConnectionIsClosed.

/**
 * Verify isClosed()
 *
 * @throws SQLException
 */
@Test
public void testConnectionIsClosed() throws SQLException {
    try (DBConnection conn = new DBConnection(connectionString)) {
        assertTrue(!conn.isClosed(), "BVT connection should not be closed");
        conn.close();
        assertTrue(conn.isClosed(), "BVT connection should not be open");
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) Test(org.junit.jupiter.api.Test)

Example 13 with DBConnection

use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.

the class bvtTest method testTwoResultsetsSameStmt.

/**
 * Verify two concurrent resultsets from same connection, same statement
 *
 * @throws SQLException
 */
@Test
public void testTwoResultsetsSameStmt() throws SQLException {
    String query = "SELECT * FROM " + table1.getEscapedTableName();
    String query2 = "SELECT * FROM " + table2.getEscapedTableName();
    try (DBConnection conn = new DBConnection(connectionString);
        DBStatement stmt = conn.createStatement()) {
        DBResultSet rs1 = stmt.executeQuery(query);
        DBResultSet rs2 = stmt.executeQuery(query2);
        // Interleave resultset calls. rs is expected to be closed
        try {
            rs1.next();
        } catch (SQLException e) {
            assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed.");
        }
        rs2.next();
        rs2.verifyCurrentRow(table2);
        try {
            rs1.next();
        } catch (SQLException e) {
            assertEquals(e.toString(), "com.microsoft.sqlserver.jdbc.SQLServerException: The result set is closed.");
        }
        rs1.close();
        rs2.next();
        rs2.verify(table2);
        rs2.close();
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLException(java.sql.SQLException) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) Test(org.junit.jupiter.api.Test)

Example 14 with DBConnection

use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.

the class bvtTest method testDriverNameAndDriverVersion.

/**
 * Verify Driver Name and Version from MetaData
 *
 * @throws SQLException
 */
@Test
public void testDriverNameAndDriverVersion() throws SQLException {
    try (DBConnection conn = new DBConnection(connectionString)) {
        DatabaseMetaData metaData = conn.getMetaData();
        Pattern p = Pattern.compile(driverNamePattern);
        Matcher m = p.matcher(metaData.getDriverName());
        assertTrue(m.find(), "Driver name is not a correct format! ");
        String[] parts = metaData.getDriverVersion().split("\\.");
        if (parts.length != 4)
            assertTrue(true, "Driver version number should be four parts! ");
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.jupiter.api.Test)

Example 15 with DBConnection

use of com.microsoft.sqlserver.testframework.DBConnection in project mssql-jdbc by Microsoft.

the class BulkCopyTestUtil method performBulkCopy.

/**
 * perform bulk copy using source and destination tables
 *
 * @param wrapper
 * @param sourceTable
 * @param destTable
 * @param validateResult
 */
static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, DBTable destinationTable, boolean validateResult) {
    try (DBConnection con = new DBConnection(wrapper.getConnectionString());
        DBStatement stmt = con.createStatement();
        DBResultSet srcResultSet = stmt.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
        SQLServerBulkCopy bulkCopy = wrapper.isUsingConnection() ? new SQLServerBulkCopy((Connection) con.product()) : new SQLServerBulkCopy(wrapper.getConnectionString())) {
        if (wrapper.isUsingBulkCopyOptions()) {
            bulkCopy.setBulkCopyOptions(wrapper.getBulkOptions());
        }
        bulkCopy.setDestinationTableName(destinationTable.getEscapedTableName());
        if (wrapper.isUsingColumnMapping()) {
            for (int i = 0; i < wrapper.cm.size(); i++) {
                ColumnMap currentMap = wrapper.cm.get(i);
                if (currentMap.sourceIsInt && currentMap.destIsInt) {
                    bulkCopy.addColumnMapping(currentMap.srcInt, currentMap.destInt);
                } else if (currentMap.sourceIsInt && (!currentMap.destIsInt)) {
                    bulkCopy.addColumnMapping(currentMap.srcInt, currentMap.destString);
                } else if ((!currentMap.sourceIsInt) && currentMap.destIsInt) {
                    bulkCopy.addColumnMapping(currentMap.srcString, currentMap.destInt);
                } else if ((!currentMap.sourceIsInt) && (!currentMap.destIsInt)) {
                    bulkCopy.addColumnMapping(currentMap.srcString, currentMap.destString);
                }
            }
        }
        bulkCopy.writeToServer((ResultSet) srcResultSet.product());
        if (validateResult) {
            validateValues(con, sourceTable, destinationTable);
        }
    } catch (SQLException ex) {
        fail(ex.getMessage());
    }
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) ColumnMap(com.microsoft.sqlserver.jdbc.bulkCopy.BulkCopyTestWrapper.ColumnMap) SQLException(java.sql.SQLException) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) Connection(java.sql.Connection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBResultSet(com.microsoft.sqlserver.testframework.DBResultSet) SQLServerBulkCopy(com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)

Aggregations

DBConnection (com.microsoft.sqlserver.testframework.DBConnection)38 DBStatement (com.microsoft.sqlserver.testframework.DBStatement)25 Test (org.junit.jupiter.api.Test)16 DBResultSet (com.microsoft.sqlserver.testframework.DBResultSet)14 SQLException (java.sql.SQLException)8 DBTable (com.microsoft.sqlserver.testframework.DBTable)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 Connection (java.sql.Connection)5 Statement (java.sql.Statement)5 ResultSet (java.sql.ResultSet)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)3 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)3 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)2 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)2 SQLServerStatement (com.microsoft.sqlserver.jdbc.SQLServerStatement)2 DBColumn (com.microsoft.sqlserver.testframework.DBColumn)2 DBPreparedStatement (com.microsoft.sqlserver.testframework.DBPreparedStatement)2 DisplayName (org.junit.jupiter.api.DisplayName)2 SQLServerColumnEncryptionJavaKeyStoreProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider)1