Logo Search packages:      
Sourcecode: mysql-connector-java version File versions  Download package

ConnectionRegressionTest.java

/**
 * JDBC4 connection regression tests
 */
00004 package testsuite.regression.jdbc4;

import java.sql.PreparedStatement;
import java.util.Properties;

import com.mysql.jdbc.MySQLConnection;
import com.mysql.jdbc.NonRegisteringDriver;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;

import testsuite.BaseTestCase;

/**
 * @author Tonci
 */
00018 public class ConnectionRegressionTest extends BaseTestCase {

      /**
       * @param name
       */
00023       public ConnectionRegressionTest(String name) {
            super(name);
            // TODO Auto-generated constructor stub
      }

      /**
       * Runs all test cases in this test suite
       * 
       * @param args
       */
00033       public static void main(String[] args) {
            junit.textui.TestRunner.run(ConnectionRegressionTest.class);
      }

      /**
       * @author Tonci
       * Bypassing the server protocol bug where DB should be null-terminated
       * whether it exists or not. Affects COM_CHANGE_USER.
       */
00042       public void testBug54425() throws Exception {
            Properties parsedProps = new NonRegisteringDriver().parseURL(dbUrl,
                        null);
            String host = parsedProps
                        .getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY);
            String port = parsedProps
                        .getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY);
            String user = parsedProps
                        .getProperty(NonRegisteringDriver.USER_PROPERTY_KEY);
            String password = parsedProps
                        .getProperty(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);

            String newUrl = String
                        .format("jdbc:mysql://address=(protocol=tcp)(host=%s)(port=%s)(user=%s)(password=%s)/",
                                    host, port, user != null ? user : "",
                                    password != null ? password : "");
            
            MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
            pds.setUrl(newUrl);

            ((MySQLConnection) pds.getPooledConnection().getConnection().unwrap(com.mysql.jdbc.MySQLConnection.class)).changeUser(user, password);
      }
}

Generated by  Doxygen 1.6.0   Back to index