xmlBlaster 2.2.0 API

org.xmlBlaster.test.contrib.replication
Class TestDbBasics

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.custommonkey.xmlunit.XMLTestCase
              extended by org.xmlBlaster.test.contrib.replication.TestDbBasics
All Implemented Interfaces:
java.util.EventListener, junit.framework.Test, org.custommonkey.xmlunit.XMLConstants, org.custommonkey.xmlunit.XSLTConstants, I_ChangePublisher, I_ContribPlugin

public class TestDbBasics
extends org.custommonkey.xmlunit.XMLTestCase
implements I_ChangePublisher

Test basic functionality of the database. It does need a database conntected but does not need any xmlBlaster running.

To run most of the tests you need to have a database (for example Postgres).

The connection configuration (url, password etc.) is configured as JVM property or in #createTest(I_Info, Map) and #setUpDbPool(I_Info)

Author:
Michele Laghi

Field Summary
private  DbMetaHelper dbHelper
           
private  I_DbSpecific dbSpecific
           
private  I_Info info
           
private static java.util.logging.Logger log
           
private  I_DbPool pool
           
private  java.lang.String replPrefix
           
private  SpecificHelper specificHelper
           
 
Fields inherited from interface org.custommonkey.xmlunit.XSLTConstants
XSLT_END, XSLT_IDENTITY_TEMPLATE, XSLT_START, XSLT_STRIP_WHITESPACE, XSLT_XML_OUTPUT_NOINDENT
 
Fields inherited from interface org.custommonkey.xmlunit.XMLConstants
CLOSE_NODE, END_CDATA, END_COMMENT, END_PROCESSING_INSTRUCTION, OPEN_END_NODE, OPEN_START_NODE, START_CDATA, START_COMMENT, START_DOCTYPE, START_PROCESSING_INSTRUCTION, XML_DECLARATION, XMLNS_PREFIX, XPATH_ATTRIBUTE_IDENTIFIER, XPATH_CHARACTER_NODE_IDENTIFIER, XPATH_COMMENT_IDENTIFIER, XPATH_NODE_INDEX_END, XPATH_NODE_INDEX_START, XPATH_PROCESSING_INSTRUCTION_IDENTIFIER, XPATH_SEPARATOR
 
Constructor Summary
TestDbBasics()
          Default ctor.
TestDbBasics(java.lang.String arg0)
          Constructor for TestDbBasics.
 
Method Summary
private  void changesToReplTables(java.sql.Connection conn, java.lang.String catalog, java.lang.String schema, java.lang.String tableName, boolean doReplicate)
          Used by testChangesToReplTables
private  java.lang.String extractBase64Part(java.lang.String txt)
           
 XBSession getJmsSession()
          Only used in replication, can return null if not used.
 java.util.Set getUsedPropertyKeys()
          Gets all property keys which may be used by this object.
 void init(I_Info info)
          After creation this method is called.
static void main(java.lang.String[] args)
          Start the test.
 java.lang.String publish(java.lang.String changeKey, byte[] message, java.util.Map attrMap)
          Send the message to the MoM.
 boolean registerAlertListener(I_Update momCb, java.util.Map attrs)
          Register for alerts when the data source has changed.
protected  void setUp()
          Configure database access.
 void shutdown()
          Cleanup resources.
protected  void tearDown()
           
 void testAddToReplTablesThenCreate()
          Testing if the metadata contains the correct information on how to write table names (if upper- lower or mixedcase), A table which does not exist yet is added to the repl_tables.
 void testAdhoc()
           
 void testBasicPerformance()
           
 void testChangesToReplTables()
          This method tests adding and removing of entries to repl_tables.
 void testCreateThenAddToReplTables()
          Testing if the metadata contains the correct information on how to write table names (if upper- lower or mixedcase), A new table is created.
 void testFunctions()
          This method makes some calls to system functions.
 void testInternalFunctions()
          This method makes some calls to system functions which are specific to oracle.
 
Methods inherited from class org.custommonkey.xmlunit.XMLTestCase
assertNodeTestPasses, assertNodeTestPasses, assertNotXpathExists, assertNotXpathExists, assertXMLEqual, assertXMLEqual, assertXMLEqual, assertXMLEqual, assertXMLEqual, assertXMLEqual, assertXMLEqual, assertXMLEqual, assertXMLEqual, assertXMLIdentical, assertXMLIdentical, assertXMLIdentical, assertXMLNotEqual, assertXMLNotEqual, assertXMLNotEqual, assertXMLNotEqual, assertXMLNotEqual, assertXMLNotEqual, assertXMLValid, assertXMLValid, assertXMLValid, assertXMLValid, assertXpathEvaluatesTo, assertXpathEvaluatesTo, assertXpathExists, assertXpathExists, assertXpathNotExists, assertXpathNotExists, assertXpathsEqual, assertXpathsEqual, assertXpathsEqual, assertXpathsEqual, assertXpathsNotEqual, assertXpathsNotEqual, assertXpathsNotEqual, assertXpathsNotEqual, assertXpathValuesEqual, assertXpathValuesEqual, assertXpathValuesEqual, assertXpathValuesEqual, assertXpathValuesNotEqual, assertXpathValuesNotEqual, assertXpathValuesNotEqual, assertXpathValuesNotEqual, compareXML, compareXML, compareXML, compareXML, compareXML, setControlParser, setIgnoreWhitespace, setTestParser
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

info

private I_Info info

pool

private I_DbPool pool

dbSpecific

private I_DbSpecific dbSpecific

dbHelper

private DbMetaHelper dbHelper

specificHelper

private SpecificHelper specificHelper

replPrefix

private java.lang.String replPrefix
Constructor Detail

TestDbBasics

public TestDbBasics()
Default ctor.


TestDbBasics

public TestDbBasics(java.lang.String arg0)
Constructor for TestDbBasics.

Parameters:
arg0 -
Method Detail

main

public static void main(java.lang.String[] args)
Start the test.
  java -Ddb=oracle junit.swingui.TestRunner -noloading org.xmlBlaster.test.contrib.replication.TestDbBasics
 

Parameters:
args - Command line settings

setUp

protected void setUp()
              throws java.lang.Exception
Configure database access.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception
See Also:
TestCase#setUp()

tearDown

protected void tearDown()
                 throws java.lang.Exception
Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception

testBasicPerformance

public final void testBasicPerformance()
                                throws java.lang.Exception
Throws:
java.lang.Exception

testInternalFunctions

public final void testInternalFunctions()
                                 throws java.lang.Exception
This method makes some calls to system functions which are specific to oracle. The tested functions are: CHAR(8) repl_base64_helper(val INTEGER) (this is only tested for no exception thrown) CLOB repl_base64_enc_raw(msg RAW) CLOB repl_base64_enc_blob(msg BLOB) CLOB repl_base64_enc_clob(msg CLOB)

Throws:
java.lang.Exception - Any type is possible

extractBase64Part

private java.lang.String extractBase64Part(java.lang.String txt)

testFunctions

public final void testFunctions()
                         throws java.lang.Exception
This method makes some calls to system functions.

Throws:
java.lang.Exception - Any type is possible

changesToReplTables

private void changesToReplTables(java.sql.Connection conn,
                                 java.lang.String catalog,
                                 java.lang.String schema,
                                 java.lang.String tableName,
                                 boolean doReplicate)
                          throws java.lang.Exception
Used by testChangesToReplTables

Parameters:
conn - The jdbc connection to use
catalog - the catalog (can be null)
schema - the name of the schema (db specific). Can be null.
tableName - The table name to add. Can NOT be null.
doReplicate - the flag indicating it has to be replicated.
Throws:
java.lang.Exception

testChangesToReplTables

public final void testChangesToReplTables()
                                   throws java.lang.Exception
This method tests adding and removing of entries to repl_tables. It checks if a table which has been added is correctly written in the repl_tables table (case sensitivity is checked replicate' flag is checked and null and empty catalog and schema are checked.

Throws:
java.lang.Exception - Any type is possible

testCreateThenAddToReplTables

public final void testCreateThenAddToReplTables()
                                         throws java.lang.Exception
Testing if the metadata contains the correct information on how to write table names (if upper- lower or mixedcase), A new table is created. A check is made to see if this generates an entry in the repl_items table (it should not). It is then added to the repl_tables table. Checks are made to detect if the CREATE operation as been detected (first create and then add to repl_tables), if it is correctly stored in the repl_items table. Then Business Function and Trigger is added to that table manually (this is normally done by the replication mechanism). Again it is checked if the operation has been detected by the PL/SQL code (trigger and function) added to the business table. If the table does not exist we expect a null ResultSet

Throws:
java.lang.Exception - Any type is possible

testAddToReplTablesThenCreate

public final void testAddToReplTablesThenCreate()
                                         throws java.lang.Exception
Testing if the metadata contains the correct information on how to write table names (if upper- lower or mixedcase), A table which does not exist yet is added to the repl_tables. A check is made to see if the action generated an entry in repl_items (it should not). It is then created. Checks are made to detect if the CREATE operation as been detected (first create and then add to repl_tables), if it is correctly stored in the repl_items table. Then Business Function and Trigger is added to that table manually (this is normally done by the replication mechanism). Again it is checked if the operation has been detected by the PL/SQL code (trigger and function) added to the business table. If the table does not exist we expect a null ResultSet

Throws:
java.lang.Exception - Any type is possible

getUsedPropertyKeys

public java.util.Set getUsedPropertyKeys()
Description copied from interface: I_ContribPlugin
Gets all property keys which may be used by this object.

Specified by:
getUsedPropertyKeys in interface I_ContribPlugin
Returns:
See Also:
I_ContribPlugin.getUsedPropertyKeys()

init

public void init(I_Info info)
          throws java.lang.Exception
Description copied from interface: I_ChangePublisher
After creation this method is called. The plugin must register itself into global scope with info.setObject("org.xmlBlaster.contrib.dbwatcher.mom.I_ChangePublisher", this) to be available for others.

Specified by:
init in interface I_ChangePublisher
Specified by:
init in interface I_ContribPlugin
Parameters:
info - The configuration environment
Throws:
java.lang.Exception - MoM specific

publish

public java.lang.String publish(java.lang.String changeKey,
                                byte[] message,
                                java.util.Map attrMap)
                         throws java.lang.Exception
Description copied from interface: I_ChangePublisher
Send the message to the MoM.

Specified by:
publish in interface I_ChangePublisher
Parameters:
changeKey - Can be used to create the topic name
message - The message content to send
attrMap - An optional map with attributes or null
Returns:
A unique identifier of the sent message
Throws:
java.lang.Exception - On sending problems

registerAlertListener

public boolean registerAlertListener(I_Update momCb,
                                     java.util.Map attrs)
                              throws java.lang.Exception
Description copied from interface: I_ChangePublisher
Register for alerts when the data source has changed.

This funtionality is plugin depending, for example the xmlBlaster plugin has a configuration option to subscribe on a alert topic and listens if somebody publishes a message to it. If such a message arrives we trigger a new database poll.

Specified by:
registerAlertListener in interface I_ChangePublisher
Parameters:
momCb - The callback interface to receive the notification
attrs - extra parameters to pass for the registration. For example if one implementation wants to do a specific extra subscription it would pass the quality of service in the attributes.
Returns:
true if a notification is available (is configured)
Throws:
java.lang.Exception - The MoM specific exception

shutdown

public void shutdown()
Description copied from interface: I_ChangePublisher
Cleanup resources.

Can be called multiple times if instance is reused from different plugins.

Specified by:
shutdown in interface I_ChangePublisher
Specified by:
shutdown in interface I_ContribPlugin
See Also:
I_Plugin

testAdhoc

public final void testAdhoc()
                     throws java.lang.Exception
Throws:
java.lang.Exception

getJmsSession

public XBSession getJmsSession()
Description copied from interface: I_ChangePublisher
Only used in replication, can return null if not used.

Specified by:
getJmsSession in interface I_ChangePublisher
Returns:
See Also:
I_ChangePublisher.getJmsSession()

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.