Adding MySQL Support to the QFTest Jython Client ################################################ :title: Adding MySQL Support to the QFTest Jython Client :date: 2014-02-17 :category: Software :tags: qftest, testing, automation, jython :slug: adding-mysql-support-to-the-qftest-jython-client :author: Chris Ramsay :status: published :language: en :show_source: True .. contents :: Abstract -------- .. PELICAN_BEGIN_SUMMARY So, you want to be able to get QFTest to talk to your MySQL database server during test execution; just a small matter of getting the Jython client to play ball - easy when you know how. This shows how to add MySQL support to the QFTest Jython client. It requires the installation of MySQL Connector/J on to the host system and a small amount of hacking of the QFTest code. .. PELICAN_END_SUMMARY MySQL Connector/J ----------------- From the package information for *libmysql-java*: .. code-block:: bash MySQL Connector/J is a JDBC-3.0 Type 4 driver, which means that it is pure Java, implements version 3.0 of the JDBC specification, and communicates directly with the MySQL server using the MySQL protocol. Sounds ideal, so let's go ahead and install it. Installation ------------ Firstly, download and install the latest MySQL Connector/J or install it through your usual package management system. Next, link to the installed jar files (mysql-connector-java-5.1.10.jar and mysql-5.1.10.jar) in */usr/share/java* to your QFTest installation library directory; in my case */usr/share/qfest/qftest-3.4.7/lib/*. .. code-block:: bash $ sudo ln -s /usr/share/java/mysql-5.1.10.jar mysql.jar $ sudo ln -s /usr/share/java/mysql-connector-java-5.1.10.jar \ > mysql-connector-java.jar Now to check that the links are correctly in place: .. code-block:: bash $ ls -al /usr/share/qftest/qftest-3.4.7/lib/ \ > | awk '/mysql/ {print $8$9$10}' mysql-connector-java.jar -> /usr/share/java/mysql-connector-java-5.1.10.jar mysql.jar -> /usr/share/java/mysql-5.1.10.jar Next you need to edit the *fixcp* file at */usr/share/qftest/qftest-n.n.n/bin/* as this file is in charge of specifying the libraries to be used by QFTest at load time. Change the lines: .. code-block:: bash 15 # libjars for server and client 16 libjars="bsf gnu groovy-all jansi jline jniwrapper jython png" To: .. code-block:: bash 15 # EXTRA JARS FOR MYSQL 16 mysqljars="mysql-connector-java mysql" 17 # libjars for server and client 18 libjars="$mysqljars bsf gnu groovy-all jansi jline jniwrapper jython png" Checking -------- Run the qftest shell file with debug arguments to see if the new libs are loading: .. code-block:: bash $ sh qftest -dbg You should see something such as the following (some elements truncated with [...]): .. code-block:: bash ------------------------------------------- This is qftest Java executable: java Java arguments: qftest arguments: [...] libjars: mysql-connector-java mysql bsf gnu groovy-all jansi jline jniwrapper jython png commons jide-oss junit jxl looks poi truezip libdir: /usr/share/qftest/qftest-3.4.7/lib qflibdir: /usr/share/qftest/qftest-3.4.7/qflib plugindir: /usr/share/qftest/plugin Logging internal output to /usr/share/qftest/log/qftest.log executing "java" -Xbootclasspath/p [...] /usr/share/qftest/qftest-3.4.7/lib/jide-oss.jar:/usr/share/qftest/ qftest-3.4.7/lib/mysql.jar:/usr/share/qftest/qftest-3.4.7/lib/ mysql-connector-java.jar: [...] de.qfs.apps.qftest.start.QFTest -shellarg=-c -shell=/bin/sh "-options=/usr/share/qftest/qftest-3.4.7/bin/qftest.options" "-logfile=/usr/share/qftest/log/qftest.log" ------------------------------------------- Essentially, you are looking to see the two mysql jars are amongst all the jars listed in the output above. Testing ------- Fire up QFTest, open a Jython terminal window and run the following: .. code-block:: python Jython 2.5.1+ (Release_2_5_1:13409M, Mrz 9 2011, 15:05:52) [OpenJDK Server VM (Sun Microsystems Inc.)] on java1.6.0_22 >>> from com.ziclix.python.sql import zxJDBC >>> conn = zxJDBC.connect('jdbc:mysql://testing.local', 'user', 'passwd', \ ... 'com.mysql.jdbc.Driver') >>> print conn >>>