org.osesb.transporthandlers.test.deployabletestpackage1
Class TransportHandlerSynchronousUnitTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.osesb.utilities.junit.OSESBTestCase
              extended by org.osesb.transporthandlers.test.deployabletestpackage1.TransportHandlerSynchronousUnitTest
All Implemented Interfaces:
junit.framework.Test

public class TransportHandlerSynchronousUnitTest
extends OSESBTestCase

This class contains unit tests for synchronous request/reply interactions with the transport handlers that are deployed with the MessagePipeline(s) in deployabletestpackage1/transporthandler-config:

There is a test method for each of the deployed MessagePipelines.

The tests use two test files attachments-1.xml and cdcatalog.xml as the test messages for the MessagePipeline(s) configured in deployabletestpackage1/transporthandler-config.

The test methods in this class are re-used by ThreadedTransportHandlerSynchronousTest, which randomly selects one of the test methods to run in a thread. When testing with ThreadedTransportHandlerSynchronousTest, make sure that the 'runningThreadedTest' property in Test.properties is set to 'true'. When true, the setUp() and tearDown() methods of the non-threaded tests return immediately. setUp() and tearDown() is accomplished by the threaded test. 'false' is the default value for 'runningThreadedTest'..

Note that deployabletestpackage1/transporthandler-config/message-router-test-config.xml maps different 'cdOrder' messageTypes to five different MessagePipeline(s), so the tests modify the 'messageType' attribute in cdcatalog.xml depending on the MessagePipleine that is being tested.

The tests use a pool of ClientGateway(s) configured by keyed-pooled-clientgateway-test-config.xml, where each poolKey configures a client-side MessagePipeline that sends test messages to a different transport handler as follows:

The tests are run for each poolKey in clientGatewayPoolKeys. Each poolKey corresponds to a different transport handler. Comment and uncomment poolKey entries to run the tests against a set of transport handlers.

Transport handlers use a pool of org.osesb.msgrouting.MessageRouter(s) to route messages to a org.osesb.messagepipeline.MessagePipeline for processing. The MessageRouter selects the MessagePipeline based on the message's messageType. The MessageRouter uses the <messagetype-to-messagepipeline-map> configuration element of a MessageRouterConfiguration to map message types to MessagePipelines.

There are two ways that the message type for an incoming message is determined:

  1. A transport handler can be configured with a static messageType. In this case all messages arriving at that transport handler will be assigned the same message type.
  2. If a transport handler is not configured with a static message type, then it uses a XMLMessageTypeHelper to extract a message type from the incoming XML message.

DefaultXMLMessageTypeHelper is the default XMLMessageTypeHelper class and is constructed with a XMLMessageTypeXPathExpressionListConfiguration. DefaultXMLMessageTypeHelper applies the configured XPath expressions to a XML message until a messageType is determined. DefaultXMLMessageTypeHelper#getMessagetype() returns the messageType as a QName, where the namespaceURI is the XML document namespace (if any) and the localPart is the value for the element or attribute that is given by a XPath expression.

To configure a MessageRouter with a different XMLMessageTypeHelper, create a class that extends AbstractXMLMessageTypeHelper and use the <xmlMessagetypeHelperConfiguration> content model element of the MessageRouterConfiguration.

Notes on test assetions for JMS message correlation and SOAP ws-addressing.

For JMS transport, the tests check that the 'messageID' and 'correlationID' properties of the EAIMessage returned from the ClientGateway are not null. Functionally, this test is superfluous because the JMS connector matches the JMSCorrelationID of the reply against the JMSMessageID of the of the request message. Testing that the EAIMessage properties are not null verfies that the JMSMessageID and JMSCorrelationID are propagated back to the ClientGateway.

For SOAP transport, the 'messageID' and 'correlationID' properties of the EAIMessage returned from the ClientGateway are not checked because ws-addressing SOAPHeader entries are not in the SOAP response and therefore the 'messageID' and 'correlationID' properties of the EAIMessage returned from the ClientGateway are not populated. In fact, the client and server side addressing handlers, JAXRPCClientAddressingHandler and JAXRPCServerAddressingHandler do not have handleResponse() methods that could add ws-addressing entries to the SOAP response.


Field Summary
 
Fields inherited from class org.osesb.utilities.junit.OSESBTestCase
configFile, log, reader, testDataDirectory, testProperties, thisClassName
 
Constructor Summary
TransportHandlerSynchronousUnitTest(java.lang.String name)
          Construct a new instance.
 
Method Summary
static void main(java.lang.String[] args)
          The main method runs all the tests in the text ui
 void setUp()
          This method is called before a test is executed.
static junit.framework.Test suite()
          The suite method runs all the tests
 void tearDown()
          This method is called after a test is executed.
 void testMessagePipeline_1()
          Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-1-test-config.xml, which configures a MessagePipeline as follows:

1.

 void testMessagePipeline_2()
          Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-2-test-config.xml, which configures a MessagePipeline as follows:

A XMLNodeExtractorPipelineStage named SumCDElementPricesPipelineStage extracts all <cd> elements from a 'cdcatalog' XML message and sets the MessagePipeline result as XML that contains a root element named 'totalPrice' with a value that is the sum of all <price> elements.

 void testMessagePipeline_3()
          Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-3-test-config.xml, which configures a MessagePipeline as follows:

DoubleSumCDElementPricesPipelineStage is a FlowControlPipelineStage that configures two branches, each with a single SumCDElementPricesPipelineStage, which extracts all <cd> elements from a 'cdcatalog' XML message and sets the MessagePipeline result as XML that contains a root element named 'totalPrice' with a value that is the sum of all <price> elements.

 void testMessagePipeline_4()
          Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-4-test-config.xml, which configures a MessagePipeline as follows:

The test MessagePipeline is configured with a single PipelineStage, EchoMessageWithRandomPipelineStageExceptionPipelineStage, with a runStage() method that generates a random number.

 void testMessagePipeline_5()
          Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-5-test-config.xml, which configures a MessagePipeline as follows:

The test MessagePipeline is configured with a single PipelineStage, FCEchoMessageWithRandomPipelineStageExceptionPipelineStage, which is a is a FlowControlPipelineStage that configures two EchoMessageWithRandomPipelineStageExceptionPipelineStage branches that are run in parallel.

 void testMessagePipeline_6()
          Unit test of transport handlers deployed with the MessagePipelineconfigured by deployabletestpackage1/transporthandler-config/message-pipeline-6-test-config.xml, which configures a MessagePipeline as follows:

A TestBrokerAcknowledgementMessagePipelineStage is configured to test the correct receipt of a BrokerAcknowledgementMessage from a transport handler.

 void testMessagePipeline_7()
          Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-7-test-config.xml, which configures a MessagePipeline as follows:

1.

 
Methods inherited from class org.osesb.utilities.junit.OSESBTestCase
getBooleanTestProperty, getIntTestProperty, getLongTestProperty, getTestResourcesAsStreams, getTestResourcesAsText, getTestResourcesFiles, loadTestProperties, readTestFilesAsStreams
 
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, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransportHandlerSynchronousUnitTest

public TransportHandlerSynchronousUnitTest(java.lang.String name)
Construct a new instance.

OSESBTestCase (ancestor) constructor does the following:

  1. Instantiates a logging implementation.
  2. Instantiates an instance of ClassLoaderFileReader for reading test files from the ClassPath (not the file system).
  3. Loads Test.properties into ResourceBundle testProperties.
  4. Sets the testDataDirectory property using the testDataDirectory entry from Test.properties.

Method Detail

suite

public static junit.framework.Test suite()
The suite method runs all the tests


setUp

public void setUp()
           throws java.lang.Exception
This method is called before a test is executed.

Overrides:
setUp in class OSESBTestCase
Throws:
java.lang.Exception

tearDown

public void tearDown()
              throws java.lang.Exception
This method is called after a test is executed.

Overrides:
tearDown in class OSESBTestCase
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
The main method runs all the tests in the text ui


testMessagePipeline_1

public void testMessagePipeline_1()
                           throws java.lang.Exception
Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-1-test-config.xml, which configures a MessagePipeline as follows:

1. A XMLValidationPipelineStage configured to use a org.osesb.utilities.xml.validation.XMLValidator_SchemaSource, which is a XML validator class that validates XML against schemas stored in the XMLRepository.

For unit testing the MessagePipelines, the XML repository is configured by deployabletestpackage1/transporthandler-config/xml-filesystem-repository-deployabletestpackage1-config.xml

Repository entries are mapped to the messageType of the incoming message, which in this case is given by the QName {http://osesb.test.com/cdcatalog}cdOrder_1. The messageType is extracted by a MessageRouter instance, which is configured using deployabletestpackage1/transporthandler-config/pooled-messagerouter-test-config.xml.

2. A XMLElementPropagatorPipelineStage named CDElementPropagatorPipelineStage extracts and propagates elements for downstream processing. The elments are propagated as individual XML.

3. A custom PipelineStage named ReconstructCDCatalogMessagePipelineStage re-assembles the orginal 'cdcatalog' message from the propagated elements and sets the re-assembled 'cdcatalog' message as the MessagePipeline result on the MessagePipelineContext.

Throws:
java.lang.Exception

testMessagePipeline_2

public void testMessagePipeline_2()
                           throws java.lang.Exception
Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-2-test-config.xml, which configures a MessagePipeline as follows:

A XMLNodeExtractorPipelineStage named SumCDElementPricesPipelineStage extracts all <cd> elements from a 'cdcatalog' XML message and sets the MessagePipeline result as XML that contains a root element named 'totalPrice' with a value that is the sum of all <price> elements.

Throws:
java.lang.Exception

testMessagePipeline_3

public void testMessagePipeline_3()
                           throws java.lang.Exception
Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-3-test-config.xml, which configures a MessagePipeline as follows:

DoubleSumCDElementPricesPipelineStage is a FlowControlPipelineStage that configures two branches, each with a single SumCDElementPricesPipelineStage, which extracts all <cd> elements from a 'cdcatalog' XML message and sets the MessagePipeline result as XML that contains a root element named 'totalPrice' with a value that is the sum of all <price> elements.

DoubleSumCDElementPricesPipelineStage is configured to run the branches in parallel and then set the MessagePipeline result as XML that contains a root element named 'totalPrice' with a value that is the sum of the results returned by each branch. So, the 'totalPrice' returned should be double the sum for the <price> elements in the original 'cdcatalog' message.

Throws:
java.lang.Exception

testMessagePipeline_4

public void testMessagePipeline_4()
                           throws java.lang.Exception
Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-4-test-config.xml, which configures a MessagePipeline as follows:

The test MessagePipeline is configured with a single PipelineStage, EchoMessageWithRandomPipelineStageExceptionPipelineStage, with a runStage() method that generates a random number. If the number is even, runStage() parses the input message using a pooled SAX parser and sets the result message for it's MessagePipeline to the content of the input message. If the number is odd, runStage() throws a PipelineStageException with the 'exceptionClassification' property set to 'testException'.

Note: For this test, the SOAPXMLMessageTransportHandler must be configured to return BrokerErrorMessages to the client when an error occurs. The 'onExceptionSendBrokerErrorMessage' environment property should be set to true.

Throws:
java.lang.Exception

testMessagePipeline_5

public void testMessagePipeline_5()
                           throws java.lang.Exception
Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-5-test-config.xml, which configures a MessagePipeline as follows:

The test MessagePipeline is configured with a single PipelineStage, FCEchoMessageWithRandomPipelineStageExceptionPipelineStage, which is a is a FlowControlPipelineStage that configures two EchoMessageWithRandomPipelineStageExceptionPipelineStage branches that are run in parallel.

EchoMessageWithRandomPipelineStageExceptionPipelineStage#runStage() generates a random number. If the number is even, runStage() parses the input message using a pooled SAX parser and sets the result message for it's MessagePipeline to the content of the input message. If the number is odd, runStage() throws a PipelineStageException with the 'exceptionClassification' property set to 'testException'.

Note: For this test, the SOAPXMLMessageTransportHandler must be configured to return BrokerErrorMessages to the client when an error occurs. The 'onExceptionSendBrokerErrorMessage' environment property should be set to true.

Throws:
java.lang.Exception

testMessagePipeline_6

public void testMessagePipeline_6()
                           throws java.lang.Exception
Unit test of transport handlers deployed with the MessagePipelineconfigured by deployabletestpackage1/transporthandler-config/message-pipeline-6-test-config.xml, which configures a MessagePipeline as follows:

A TestBrokerAcknowledgementMessagePipelineStage is configured to test the correct receipt of a BrokerAcknowledgementMessage from a transport handler.

TestBrokerAcknowledgementMessagePipelineStage is deployed to a transport handler with a sendReply() method that returns a BrokerAcknowledgementMessage when a reply is expected but when the target MessagePipeline does not return a result.

TestBrokerAcknowledgementMessagePipelineStage has a runStage() method that does nothing and therefore does not return a result thereby enabling a test of an expected BrokerAcknowledgementMessage.

Throws:
java.lang.Exception

testMessagePipeline_7

public void testMessagePipeline_7()
                           throws java.lang.Exception
Unit test of transport handlers deployed with the MessagePipeline configured by deployabletestpackage1/transporthandler-config/message-pipeline-7-test-config.xml, which configures a MessagePipeline as follows:

1. A XMLValidationPipelineStage configured to use a org.osesb.utilities.xml.validation.XMLValidator_SchemaSource, which is a XML validator class that validates XML against schemas stored in the XMLRepository.

For unit testing the MessagePipelines, the XML repository is configured by deployabletestpackage1/transporthandler-config/xml-filesystem-repository-deployabletestpackage1-config.xml

Repository entries are mapped to the messageType of the incoming message, which in this case is given by the QName {http://osesb.test.com/cdcatalog}cdOrder_1. The messageType is extracted by a MessageRouter instance, which is configured using deployabletestpackage1/transporthandler-config/pooled-messagerouter-test-config.xml.

2. EchoMessageWithAttachmentCompression is a custom PipelineStage with a runStage() method that expects a org.osesb.eaimessage.EAIXMLMessageWithAttachments with XML content that looks like:

<testFiles xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
              <testFile>
                  <fileName>Apas-Track2.mp3</fileName>
                  <mimeType xmime:contentType="audio/mpeg" />
              </testFile>
              <testFile>
                  <fileName>Dry Ice Video.wmv</fileName>
                  <mimeType xmime:contentType="video/x-ms-wmv" />
              </testFile>
          </testFiles>
     

EchoMessageWithAttachmentCompression# runStage() expects the number of attachments to equal the number of <testFile> elements.

runStage() compresses the attachments, changes the value of the <mimeType> element to 'application/zip'. runStage() sets the MessagePipeline result message to a EAIXMLMessageWithAttachments with the modified XML and compressed attachments.

Throws:
java.lang.Exception