Search in sources :

Example 16 with SQLServerDataSource

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

the class ConnectionDriverTest method testIncorrectDatabase.

@Test
public void testIncorrectDatabase() throws SQLException {
    long timerStart = 0;
    long timerEnd = 0;
    Connection con = null;
    final long milsecs = threshHoldForNoRetryInMilliseconds;
    try {
        SQLServerDataSource ds = new SQLServerDataSource();
        ds.setURL(connectionString);
        ds.setLoginTimeout(loginTimeOutInSeconds);
        ds.setDatabaseName(RandomUtil.getIdentifier("DataBase"));
        timerStart = System.currentTimeMillis();
        con = ds.getConnection();
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("Cannot open database"));
        timerEnd = System.currentTimeMillis();
    }
    long timeDiff = timerEnd - timerStart;
    assertTrue(con == null, "Should not have connected.");
    assertTrue(timeDiff <= milsecs, "Exited in more than " + (milsecs / 1000) + " seconds.");
}
Also used : SQLServerDataSource(com.microsoft.sqlserver.jdbc.SQLServerDataSource) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 17 with SQLServerDataSource

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

the class ConnectionDriverTest method testJdbcDataSourceMethod.

@Test
public void testJdbcDataSourceMethod() throws SQLFeatureNotSupportedException {
    SQLServerDataSource fxds = new SQLServerDataSource();
    Logger logger = fxds.getParentLogger();
    assertEquals(logger.getName(), "com.microsoft.sqlserver.jdbc", "Parent Logger name is wrong");
}
Also used : SQLServerDataSource(com.microsoft.sqlserver.jdbc.SQLServerDataSource) Logger(java.util.logging.Logger) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 18 with SQLServerDataSource

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

the class ConnectionDriverTest method testIncorrectUserName.

@Test
public void testIncorrectUserName() throws SQLException {
    long timerStart = 0;
    long timerEnd = 0;
    Connection con = null;
    final long milsecs = threshHoldForNoRetryInMilliseconds;
    try {
        SQLServerDataSource ds = new SQLServerDataSource();
        ds.setURL(connectionString);
        ds.setLoginTimeout(loginTimeOutInSeconds);
        ds.setUser(RandomUtil.getIdentifier("User"));
        timerStart = System.currentTimeMillis();
        con = ds.getConnection();
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("Login failed"));
        timerEnd = System.currentTimeMillis();
    }
    long timeDiff = timerEnd - timerStart;
    assertTrue(con == null, "Should not have connected.");
    assertTrue(timeDiff <= milsecs, "Exited in more than " + (milsecs / 1000) + " seconds.");
}
Also used : SQLServerDataSource(com.microsoft.sqlserver.jdbc.SQLServerDataSource) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Example 19 with SQLServerDataSource

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

the class ConnectionDriverTest method testIncorrectDatabaseWithFailoverPartner.

@Test
@Tag("slow")
public void testIncorrectDatabaseWithFailoverPartner() throws SQLException {
    long timerStart = 0;
    long timerEnd = 0;
    Connection con = null;
    try {
        SQLServerDataSource ds = new SQLServerDataSource();
        ds.setURL(connectionString);
        ds.setLoginTimeout(loginTimeOutInSeconds);
        ds.setDatabaseName(RandomUtil.getIdentifierForDB("DB"));
        ds.setFailoverPartner(RandomUtil.getIdentifier("FailoverPartner"));
        timerStart = System.currentTimeMillis();
        con = ds.getConnection();
    } catch (Exception e) {
        timerEnd = System.currentTimeMillis();
    }
    long timeDiff = timerEnd - timerStart;
    assertTrue(con == null, "Should not have connected.");
    assertTrue(timeDiff >= ((loginTimeOutInSeconds - 1) * 1000), "Exited in less than " + (loginTimeOutInSeconds - 1) + " seconds.");
}
Also used : SQLServerDataSource(com.microsoft.sqlserver.jdbc.SQLServerDataSource) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 20 with SQLServerDataSource

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

the class ConnectionDriverTest method testEncryptedConnection.

@Test
public void testEncryptedConnection() throws SQLException {
    SQLServerDataSource ds = new SQLServerDataSource();
    ds.setApplicationName("User");
    ds.setURL(connectionString);
    ds.setEncrypt(true);
    ds.setTrustServerCertificate(true);
    ds.setPacketSize(8192);
    try (Connection con = ds.getConnection()) {
    }
}
Also used : SQLServerDataSource(com.microsoft.sqlserver.jdbc.SQLServerDataSource) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) SQLServerConnection(com.microsoft.sqlserver.jdbc.SQLServerConnection) ISQLServerConnection(com.microsoft.sqlserver.jdbc.ISQLServerConnection) DBConnection(com.microsoft.sqlserver.testframework.DBConnection) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest) Test(org.junit.jupiter.api.Test)

Aggregations

SQLServerDataSource (com.microsoft.sqlserver.jdbc.SQLServerDataSource)26 Test (org.junit.jupiter.api.Test)22 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)19 Connection (java.sql.Connection)19 SQLException (java.sql.SQLException)14 SQLServerConnection (com.microsoft.sqlserver.jdbc.SQLServerConnection)9 ISQLServerConnection (com.microsoft.sqlserver.jdbc.ISQLServerConnection)7 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)7 Statement (java.sql.Statement)7 PooledConnection (javax.sql.PooledConnection)7 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)6 ISQLServerDataSource (com.microsoft.sqlserver.jdbc.ISQLServerDataSource)5 ResultSet (java.sql.ResultSet)5 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 CallableStatement (java.sql.CallableStatement)3 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectOutput (java.io.ObjectOutput)2 ObjectOutputStream (java.io.ObjectOutputStream)2