Difference between revisions of "Run Junit Tests For Non Default SQL Adapter"
(→Configurations) |
(→SQL Scripts) |
||
Line 80: | Line 80: | ||
##: <code>0x00000000000000000000000000000001</code> to <code>E'\\x00000000000000000000000000000001'</code> | ##: <code>0x00000000000000000000000000000001</code> to <code>E'\\x00000000000000000000000000000001'</code> | ||
## '''dbname_setup.sql''' | ## '''dbname_setup.sql''' | ||
− | ##:This script is used to: | + | ##: This script is used to: |
− | ###Create the <code>test</code> user with the following permissions: | + | ### Create the <code>test</code> user with the following permissions: |
− | ####Full privileges for the test database | + | #### Full privileges for the test database |
− | ####Remote | + | #### Remote Login permission |
− | ###Create the <code>test</code> database with the follow specifications: | + | ### Create the <code>test</code> database with the follow specifications: |
− | ####Name: test | + | #### Name: test |
− | ####Encoding: utf-8 / unicode | + | #### Encoding: utf-8 / unicode |
− | ####(*Optional) Schema Name: test | + | #### (*Optional) Schema Name: test |
+ | |||
==== Unit Test Files ==== | ==== Unit Test Files ==== |
Revision as of 13:19, 26 February 2011
Contents
Debugging a Non-Default SQL Adapter
Summary
By default, NexJ Express Unit tests are configured to test the MySQL Adapter.
The instructions that follow outline instructions for configuring Unit tests to be run for other SQL Adapters.
For this manual, reference will be made to the PostgreSQL Adapter but it will work the same for other adapters
Prerequisites
The following files must exist for the new SQL Adapter:
src
nexj.core.persistence.sql.[DbName]SQLAdapter.java
extending nexj.core.persistence.sql.SQLAdapter
nexj.core.persistence.sql.[DbName]SQLSchemaManager.java
extending nexj.core.persistence.sql.SQLSchemaManager
test
nexj.core.persistence.sql.[DbName]SQLAdapterTest.java
extending nexj.core.persistence.sql.SQLAdapterTest
nexj.core.persistence.sql.[DbName]SQLSchemaManagerTest.java
extending nexj.core.persistence.sql.SQLSchemaManagerTest
The following files should be edited and entries for the new SQL Adapter added:
nexj.core.meta.persistence.sql.RelationalDatabase.java
nexj.core.meta.peristence.sql.RelationalDatabaseFragment.java
nexj.core.meta.sys.system.dstypes
nexj.core.persistence.sql.SQLSchemaManagerFactory.java
nexj.core.util.JDBCInfo.java
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 nexj
- Edit the files: default.config, filestorage.connections, filestoragefragment.connections
- In the
DataSourceConnections
elemement - Change all occurrences of
adapter="MySQL"
toadapter="DbName"
- Change all occurrences of
port="3306"
to the port on which the new DbName is configured to accept connections- For the PostgreSQL Adapter, the following configuration is used
- In the
<DataSourceConnections>
<RelationalDatabaseConnection adapter="PostgreSQL" dataSource="DefaultRelationalDatabase" database="test"
host="localhost" password="test" port="5432" unicode="true" user="test"/>
<RelationalDatabaseConnection adapter="PostgreSQL" dataSource="ExternalRelationalDatabase" database="test"
host="localhost" password="test" port="5432" unicode="true" user="test"/>
...
</DataSourceConnections>
- Create a connections file for the new adapter
- Create the file [DbName].connections in the
nexj
package in the test source folder - Copy and paste the contents of mysql.connections into the new connections file
- In the
DataSourceConnections
elemement - Change all occurrences of
adapter="MySQL"
toadapter="DbName"
- Change all occurrences of
port="3306"
to the port on which the new DbName is configured to accept connections- For the PostgreSQL Adapter, the following configuration is used
- Create the file [DbName].connections in the
<DataSourceConnections>
<RelationalDatabaseConnection adapter="PostgreSQL" dataSource="DefaultRelationalDatabase" database="test"
host="localhost" password="test" port="5432" unicode="true" user="test"/>
<RelationalDatabaseConnection adapter="PostgreSQL" dataSource="ExternalRelationalDatabase" database="test"
host="localhost" password="test" port="5432" unicode="true" user="test"/>
</DataSourceConnections>
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
nexj.core.persistence.sql.script
under the test source folder- dbname_drop.sql
- Copy and paste the contents of
mysql_drop.sql
into the new file
- Copy and paste the contents of
- dbname_insert.sql
- Copy and paste the contents of
mysql_insert.sql
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
-
0x00000000000000000000000000000001
toE'\\x00000000000000000000000000000001'
- Copy and paste the contents of
- dbname_setup.sql
- This script is used to:
- Create the
test
user with the following permissions:- Full privileges for the test database
- Remote Login permission
- Create the
test
database with the follow specifications:- Name: test
- Encoding: utf-8 / unicode
- (*Optional) Schema Name: test
- dbname_drop.sql