org.osesb.msgrouting.test.deployabletestpackage1
Class MessagePipelineStageUnitTests

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

public class MessagePipelineStageUnitTests
extends OSESBTestCase

This class contains unit tests for the MessagePipelines in the org.osesb.msgrouting.test.deployabletestpackage1 package.

The unit tests are intended to verify operation of the MessagePipelines before deployment with a transport handler.


Field Summary
 
Fields inherited from class org.osesb.utilities.junit.OSESBTestCase
configFile, log, reader, testDataDirectory, testProperties, thisClassName
 
Constructor Summary
MessagePipelineStageUnitTests(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 for the MessagePipeline configured by message-pipeline-1-test-config.xml, which configures a MessagePipeline as follows:

1.

 void testMessagePipeline_2()
          Unit test for the MessagePipeline configured by 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 for the MessagePipeline configured by 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 for the MessagePipeline configured by 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 for the MessagePipeline configured by 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 for the MessagePipeline configured by message-pipeline-6-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

MessagePipelineStageUnitTests

public MessagePipelineStageUnitTests(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 for the MessagePipeline configured by 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 in deployabletestpackage1/xml-repository. 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. The messageType is extracted by a MessageRouter instance, which is configured using deployabletestpackage1/message-router-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 for the MessagePipeline configured by 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 for the MessagePipeline configured by 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 for the MessagePipeline configured by 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'.

Throws:
java.lang.Exception

testMessagePipeline_5

public void testMessagePipeline_5()
                           throws java.lang.Exception
Unit test for the MessagePipeline configured by 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'.

Throws:
java.lang.Exception

testMessagePipeline_6

public void testMessagePipeline_6()
                           throws java.lang.Exception
Unit test for the MessagePipeline configured by message-pipeline-6-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 in deployabletestpackage1/xml-repository. 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. The messageType is extracted by a MessageRouter instance, which is configured using deployabletestpackage1/message-router-test-config.xml.

2. EchoMessageWithAttachmentCompressionPipelineStage 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>
     

EchoMessageWithAttachmentCompressionPipelineStage#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