Difference between revisions of "Run Junit Tests For Non Default SQL Adapter"

From CDOT Wiki
Jump to: navigation, search
(Prerequisites)
 
(8 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Debugging a Non-Default SQL Adapter ==
+
{{Admon/obsolete}}
  
=== Summary ===
+
[[category: Debugging]][[category: NexJ Express Development]][[category: NexJ Express]]
 +
 
 +
== Summary ==
  
 
By default, NexJ Express Unit tests are configured to test the MySQL Adapter.<br>
 
By default, NexJ Express Unit tests are configured to test the MySQL Adapter.<br>
Line 7: Line 9:
 
''For this manual, reference will be made to the PostgreSQL Adapter but it will work the same for other adapters''<br>
 
''For this manual, reference will be made to the PostgreSQL Adapter but it will work the same for other adapters''<br>
  
=== Prerequisites ===
+
== Prerequisites ==
The following files must exist for the new SQL Adapter:<br>
+
#The following files must exist for the new SQL Adapter:<br>
'''src'''
+
##'''src''' folder
:<code>nexj.core.persistence.sql.[DbName]SQLAdapter.java</code> extending <code>nexj.core.persistence.sql.SQLAdapter</code>
+
##:<code>nexj.core.persistence.sql.[DbName]SQLAdapter.java</code> extending <code>nexj.core.persistence.sql.SQLAdapter</code>
:<code>nexj.core.persistence.sql.[DbName]SQLSchemaManager.java</code> extending <code>nexj.core.persistence.sql.SQLSchemaManager</code>
+
##:<code>nexj.core.persistence.sql.[DbName]SQLSchemaManager.java</code> extending <code>nexj.core.persistence.sql.SQLSchemaManager</code>
'''test'''
+
##'''test''' folder
:<code>nexj.core.persistence.sql.[DbName]SQLAdapterTest.java</code> extending <code>nexj.core.persistence.sql.SQLAdapterTest</code>
+
##:<code>nexj.core.persistence.sql.[DbName]SQLAdapterTest.java</code> extending <code>nexj.core.persistence.sql.SQLAdapterTest</code>
:<code>nexj.core.persistence.sql.[DbName]SQLSchemaManagerTest.java</code> extending <code>nexj.core.persistence.sql.SQLSchemaManagerTest</code>
+
##:<code>nexj.core.persistence.sql.[DbName]SQLSchemaManagerTest.java</code> extending <code>nexj.core.persistence.sql.SQLSchemaManagerTest</code>
 +
#The following files should be edited and entries for the new SQL Adapter added:
 +
#:<code>nexj.core.meta.persistence.sql.RelationalDatabase.java</code>
 +
#:<code>nexj.core.meta.peristence.sql.RelationalDatabaseFragment.java</code>
 +
#:<code>nexj.core.meta.sys.system.dstypes</code>
 +
#:<code>nexj.core.persistence.sql.SQLSchemaManagerFactory.java</code>
 +
#:<code>nexj.core.util.JDBCInfo.java</code>
 +
For postgreSQL see [[NexJ_Express_Connecting_to_PostgreSQL]]
  
The following files should be edited and entries for the new SQL Adapter added:
+
== Configurations ==
:<code>nexj.core.meta.persistence.sql.RelationalDatabase.java</code>
 
:<code>nexj.core.meta.peristence.sql.RelationalDatabaseFragment.java</code>
 
:<code>nexj.core.meta.sys.system.dstypes</code>
 
:<code>nexj.core.persistence.sql.SQLSchemaManagerFactory.java</code>
 
:<code>nexj.core.util.JDBCInfo.java</code>
 
 
 
=== Configurations ===
 
  
 
The following will configure the unit tests to run for [DbName]SQLAdapter and [DbName]SQLSchemaManager
 
The following will configure the unit tests to run for [DbName]SQLAdapter and [DbName]SQLSchemaManager
  
==== Environment/Connection Files ====
+
=== Environment/Connection Files ===
  
 
These files are located in the ''test'' source folder in the package <code>nexj</code>
 
These files are located in the ''test'' source folder in the package <code>nexj</code>
Line 36: Line 38:
 
## Change all occurrences of <code>port="3306"</code> to the port on which the new DbName is configured to accept connections
 
## 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
 
##: For the PostgreSQL Adapter, the following configuration is used
 
 
<source lang="xml">
 
<source lang="xml">
 
<DataSourceConnections>
 
<DataSourceConnections>
Line 46: Line 47:
 
  </DataSourceConnections>
 
  </DataSourceConnections>
 
</source>
 
</source>
 
 
#Create a connections file for the new adapter
 
#Create a connections file for the new adapter
 
## Create the file '''[DbName].connections''' in the <code>nexj</code> package in the ''test'' source folder
 
## Create the file '''[DbName].connections''' in the <code>nexj</code> package in the ''test'' source folder
Line 54: Line 54:
 
## Change all occurrences of <code>port="3306"</code> to the port on which the new DbName is configured to accept connections
 
## 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
 
##: For the PostgreSQL Adapter, the following configuration is used
 
 
<source lang="xml">
 
<source lang="xml">
 
<DataSourceConnections>
 
<DataSourceConnections>
Line 64: Line 63:
 
</source>
 
</source>
  
==== SQL Scripts ====
+
=== SQL Scripts ===
  
 
These scripts are used to:
 
These scripts are used to:
Line 71: Line 70:
 
* Drop test tables that the unit tests create
 
* 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
+
Create the files in the package <code>nexj.core.persistence.sql.script</code> under the ''test'' source folder
 
## '''dbname_drop.sql'''
 
## '''dbname_drop.sql'''
 
##* Copy and paste the contents of <code>mysql_drop.sql</code> into the new file
 
##* Copy and paste the contents of <code>mysql_drop.sql</code> into the new file
Line 79: Line 78:
 
##: For exampe, for the PostgreSQL Adapter (9.0), modify the values for binary literals into postgresql's binary literal by changing
 
##: 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>
 
##: <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'''
 
## '''dbname_setup.sql'''
 
##: This script is used to:
 
##: This script is used to:
Line 91: Line 96:
 
#### (*Optional) Schema Name: test
 
#### (*Optional) Schema Name: test
  
==== SQL Test Suite ====
+
=== SQL Test Suite ===
 
The following will add the new unittests to the SQL 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
 
#Edit the file <code>nexj.core.persistence.sql.AllTests.java</code> and add an entry for the new SQL adapter
Line 107: Line 112:
 
</source>
 
</source>
  
==== Run Unit Tests====
+
=== Run Unit Tests===
 
# '''Create the test database'''
 
# '''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 <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
 
# Run the unit tests using Eclipse's junit test runner

Latest revision as of 20:39, 26 January 2014

Important.png
This page may be obsolete.
It contains historical information.

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

  1. The following files must exist for the new SQL Adapter:
    1. src folder
      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
    2. test folder
      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
  2. 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

For postgreSQL see NexJ_Express_Connecting_to_PostgreSQL

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

  1. Edit the files: default.config, filestorage.connections, filestoragefragment.connections
    1. In the DataSourceConnections elemement
    2. Change all occurrences of adapter="MySQL" to adapter="DbName"
    3. 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
<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>
  1. Create a connections file for the new adapter
    1. Create the file [DbName].connections in the nexj package in the test source folder
    2. Copy and paste the contents of mysql.connections into the new connections file
    3. In the DataSourceConnections elemement
    4. Change all occurrences of adapter="MySQL" to adapter="DbName"
    5. 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
<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

    1. dbname_drop.sql
      • Copy and paste the contents of mysql_drop.sql into the new file
    2. 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 to E'\\x00000000000000000000000000000001'
    3. dbname_upd_addr.sql
      • Copy and paste the contents of mysql_upd_addr.sql into the new file
      • Modify the script to conform to the sql syntax for the new database
    4. dbname_upd_cont.sql
      • Copy and paste the contents of mysql_upd_cont.sql into the new file
      • Modify the script to conform to the sql syntax for the new database
    5. dbname_setup.sql
      This script is used to:
      1. Create the test user with the following permissions:
        1. Username: test
        2. Password: test
        3. Full privileges for the test database
        4. Remote Login permission
      2. Create the test database with the follow specifications:
        1. Database name: test
        2. Encoding: utf-8 / unicode
        3. (*Optional) Schema Name: test

SQL Test Suite

The following will add the new unittests to the SQL test suite

  1. Edit the file nexj.core.persistence.sql.AllTests.java and add an entry for the new SQL adapter
    For the PostgreSQL Adapter the following is added
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;
   }

Run Unit Tests

  1. Create the test database
    Run the dbname_setup.sql script that was created above to create the test database and user
  2. Run the unit tests using Eclipse's junit test runner