Changes

Jump to: navigation, search

Run Junit Tests For Non Default SQL Adapter

2,496 bytes added, 20:39, 26 January 2014
no edit summary
== Debugging a Non-Default SQL Adapter =={{Admon/obsolete}}
=[[category: Debugging]][[category: NexJ Express Development]][[category: NexJ Express]] == Summary ===
By default, NexJ Express Unit tests are configured to test the MySQL Adapter.<br>
''For this manual, reference will be made to the PostgreSQL Adapter but it will work the same for other adapters''<br>
=== Prerequisites ===#The following files must exist for the new SQL Adapter:<br>##'''src'''folder<br>##:<code>nexj.core.persistence.sql.[DbName]SQLAdapter.java</code> extending <code>nexj.core.persistence.sql.SQLAdapter</code><br>##:<code>nexj.core.persistence.sql.[DbName]SQLSchemaManager.java</code> extending <code>nexj.core.persistence.sql.SQLSchemaManager</code><br>##'''test'''folder<br>##:<code>nexj.core.persistence.sql.[DbName]SQLAdapterTest.java</code> extending <code>nexj.core.persistence.sql.SQLAdapterTest</code><br>##:<code>nexj.core.persistence.sql.[DbName]SQLSchemaManagerTest.java</code> extending <code>nexj.core.persistence.sql.SQLSchemaManagerTest</code><br><br>#The following files should be edited and entries for the new SQL Adapter added:<br>#:<code>nexj.core.meta.persistence.sql.RelationalDatabase.java</code><br>#:<code>nexj.core.meta.peristence.sql.RelationalDatabaseFragment.java</code><br>#:<code>nexj.core.meta.sys.system.dstypes</code><br>#:<code>nexj.core.persistence.sql.SQLSchemaManagerFactory.java</code><br>#:<code>nexj.core.util.JDBCInfo.java</code>For postgreSQL see [[NexJ_Express_Connecting_to_PostgreSQL]] == Configurations ==
=== Configurations ===
The following will configure the unit tests to run for [DbName]SQLAdapter and [DbName]SQLSchemaManager
==== Environment/Connection Files ==== 
These files are located in the ''test'' source folder in the package <code>nexj</code>
*# Edit the files: '''default.config, filestorage.connections, filestoragefragment.connections'''##In the <code>DataSourceConnections</code> elemement##Change all occurrences of <code>adapter="MySQL"</code> to <code>adapter="DbName"</code>##Change all occurrences of <code>port="3306"</code> to the port on which the new DbName is configured to accept connections:::##:For the PostgreSQL Adapter, the following configuration is used
<source lang="xml">
<DataSourceConnections>
</DataSourceConnections>
</source>
*#Create a connections file for the new adapter##Create the file '''[DbName].connections''' in the <code>nexj</code> package in the ''test'' source folder##Copy and paste the contents of '''mysql.connections''' into the new connections file##In the <code>DataSourceConnections</code> elemement##Change all occurrences of <code>adapter="MySQL"</code> to <code>adapter="DbName"</code>##Change all occurrences of <code>port="3306"</code> to the port on which the new DbName is configured to accept connections:::##:For the PostgreSQL Adapter, the following configuration is used
<source lang="xml">
<DataSourceConnections>
</source>
=== SQL Scripts === These scripts are used to: * Initialize the database with test data before a unittest is run* Drop test tables that the unit tests create Create the files in the package <code>nexj.core.persistence.sql.script</code> under the ''test'' source folder## '''dbname_drop.sql'''##* Copy and paste the contents of <code>mysql_drop.sql</code> into the new file## '''dbname_insert.sql'''##* Copy and paste the contents of <code>mysql_insert.sql</code> into the new file##* Modify the sql script to conform to the sql syntax for the new database##: For exampe, for the PostgreSQL Adapter (9.0), modify the values for binary literals into postgresql's binary literal by changing##: <code>0x00000000000000000000000000000001</code> to <code>E'\\x00000000000000000000000000000001'</code>## '''dbname_upd_addr.sql'''##* Copy and paste the contents of <code>mysql_upd_addr.sql</code> into the new file##* Modify the script to conform to the sql syntax for the new database## '''dbname_upd_cont.sql'''##* Copy and paste the contents of <code>mysql_upd_cont.sql</code> into the new file##* Modify the script to conform to the sql syntax for the new database## '''dbname_setup.sql'''##: This script is used to:### Create the <code>test</code> user with the following permissions:#### Username: test#### Password: test#### Full privileges for the test database#### Remote Login permission### Create the <code>test</code> database with the follow specifications:#### Database name: test#### Encoding: utf-8 / unicode#### (*Optional) Schema Name: test === SQL Scripts Test Suite ===The following will add the new unittests to the SQL test suite#Edit the file <code>nexj.core.persistence.sql.AllTests.java</code> and add an entry for the new SQL adapter#:For the PostgreSQL Adapter the following is added<source lang="java">public static Test suite() { SQLTestSuite suite =new SQLTestSuite("Test for nexj.core.persistence.sql");  suite.addTestSuite(SQLWriterConnectionTest.class); ... suite.addSQLTests("nexj.core.persistence.sql.PostgreSQLAdapterTest", "nexj.core.persistence.sql.PostgreSQLSchemaManagerTest"); return suite; }</source> === Run Unit Test Files =Tests===# '''Create the test database'''#: Run the <code>dbname_setup.sql</code> script that was created above to create the test database and user# Run the unit tests using Eclipse's junit test runner

Navigation menu