org.mule.tck
Class AbstractMuleTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.mule.tck.AbstractMuleTestCase
All Implemented Interfaces:
junit.framework.Test, TestCaseWatchdogTimeoutHandler
Direct Known Subclasses:
AppBloodhoundTestCase, FunctionalTestCase, HttpProxyBuilderTestCase, ManagedStoresTestCase

public abstract class AbstractMuleTestCase
extends junit.framework.TestCase
implements TestCaseWatchdogTimeoutHandler

AbstractMuleTestCase is a base class for Mule testcases. This implementation provides services to test code for creating mock and test objects.


Nested Class Summary
static class AbstractMuleTestCase.TestInfo
           
 
Field Summary
protected  Latch callbackCalled
          Use this as a semaphore to the unit test to indicate when a callback has successfully been called.
static String CLASSNAME_ANNOTATIONS_CONFIG_BUILDER
          If the annotations module is on the classpath, also enable annotations config builder
static int DEFAULT_MULE_TEST_TIMEOUT_SECS
          Default test watchdog timeout in seconds.
static String[] IGNORED_DOT_MULE_DIRS
          Top-level directories under .mule which are not deleted on each test case recycle.
static long LOCK_TIMEOUT
          Default timeout for multithreaded tests (using CountDownLatch, WaitableBoolean, etc.), in milliseconds.
protected  Log logger
           
protected static MuleContext muleContext
           
protected  int numPorts
           
 List<Integer> ports
           
static String PROPERTY_MULE_TEST_TIMEOUT
          Name of a property to override the default test watchdog timeout.
static int RECEIVE_TIMEOUT
          Default timeout for waiting for responses
static String TEST_MESSAGE
          Convenient test message for unit testing.
protected  int testTimeoutSecs
          Timeout used for the test watchdog
 
Constructor Summary
AbstractMuleTestCase()
           
 
Method Summary
protected  void addBuilders(List<ConfigurationBuilder> builders)
           
protected  void configureMuleContext(MuleContextBuilder contextBuilder)
          Override this method to set properties of the MuleContextBuilder before it is used to create the MuleContext.
protected  MuleContext createMuleContext()
           
protected
<T> T
createObject(Class<T> clazz)
          Create an object of instance clazz.
protected
<T> T
createObject(Class<T> clazz, Object... args)
          Create an object of instance clazz.
protected  AbstractMuleTestCase.TestInfo createTestInfo()
           
protected  TestCaseWatchdog createWatchdog()
           
protected  void disposeManager()
           
protected  void doSetUp()
          Exactly the same a setUp() in normal JUnit test cases.
protected  void doTearDown()
          Exactly the same a tearDown() in normal JUnit test cases.
protected  ConfigurationBuilder getBuilder()
           
protected  String getConfigurationResources()
           
 List<Integer> getPorts()
           
 SensingNullMessageProcessor getSensingNullMessageProcessor()
           
protected  Properties getStartUpProperties()
           
static TestConnector getTestConnector()
           
static MuleEvent getTestEvent(Object data)
           
static MuleEvent getTestEvent(Object data, InboundEndpoint endpoint)
           
static MuleEvent getTestEvent(Object data, MessageExchangePattern mep)
           
static MuleEvent getTestEvent(Object data, MuleSession session)
           
static MuleEvent getTestEvent(Object data, Service service)
           
static MuleEvent getTestEvent(Object data, Service service, InboundEndpoint endpoint)
           
static MuleEvent getTestEvent(Object data, Service service, MessageExchangePattern mep)
           
static MuleEventContext getTestEventContext(Object data)
           
static MuleEventContext getTestEventContext(Object data, MessageExchangePattern mep)
           
static MuleEvent getTestEventUsingFlow(Object data)
           
protected  String getTestHeader()
           
static InboundEndpoint getTestInboundEndpoint(MessageExchangePattern mep)
           
static InboundEndpoint getTestInboundEndpoint(String name)
           
static InboundEndpoint getTestInboundEndpoint(String name, List<Transformer> transformers)
           
static InboundEndpoint getTestInboundEndpoint(String name, String uri)
           
static InboundEndpoint getTestInboundEndpoint(String name, String uri, List<Transformer> transformers, Filter filter, Map<Object,Object> properties)
           
static InboundEndpoint getTestInboundEndpoint(String name, String uri, List<Transformer> transformers, Filter filter, Map<Object,Object> properties, Connector connector)
           
protected  AbstractMuleTestCase.TestInfo getTestInfo()
           
static OutboundEndpoint getTestOutboundEndpoint(String name)
           
static OutboundEndpoint getTestOutboundEndpoint(String name, List<Transformer> transformers)
           
static OutboundEndpoint getTestOutboundEndpoint(String name, String uri)
           
static OutboundEndpoint getTestOutboundEndpoint(String name, String uri, List<Transformer> transformers, Filter filter, Map<Object,Object> properties)
           
static OutboundEndpoint getTestOutboundEndpoint(String name, String uri, List<Transformer> transformers, Filter filter, Map<Object,Object> properties, Connector connector)
           
static Service getTestService()
           
static Service getTestService(String name, Class<?> clazz)
           
static Service getTestService(String name, Class<?> clazz, Map<?,?> props)
           
static MuleSession getTestSession(Service service, MuleContext context)
           
 int getTestTimeoutSecs()
           
static InboundEndpoint getTestTransactedInboundEndpoint(MessageExchangePattern mep)
           
static Transformer getTestTransformer()
           
 TriggerableMessageSource getTriggerableMessageSource()
           
 TriggerableMessageSource getTriggerableMessageSource(MessageProcessor listener)
           
protected  void giveTheTestSomeTimeToCleanUpAndThenKillIt(String messageIfNeedToKill)
           
 void handleTimeout(long timeout, TimeUnit unit)
           
protected  void initialiseObject(Object o)
          A convenience method that will register an object in the registry using its hashcode as the key.
protected  void initTestTimeoutSecs()
           
protected  boolean isDisabledInThisEnvironment()
          Subclasses can override this method to skip the execution of the entire test class.
protected  boolean isDisabledInThisEnvironment(String testMethodName)
          Should this test run?
protected  boolean isDisposeManagerPerSuite()
           
protected  boolean isExcluded()
          Indicates whether this test has been explicitly disabled through the configuration file loaded by TestInfo.
protected  boolean isGracefulShutdown()
          Determines if the test case should perform graceful shutdown or not.
 boolean isOffline(String method)
           
protected  boolean isStartContext()
           
protected  void printTestHeader()
           
protected  void registerTestMethod()
           
 void run(junit.framework.TestResult result)
           
 void runBare()
          Shamelessly copy from Spring's ConditionalTestCase so in MULE-2.0 we can extend this class from ConditionalTestCase.
protected  void setDisposeManagerPerSuite(boolean val)
           
 void setFailOnTimeout(boolean failOnTimeout)
           
 void setName(String name)
           
protected  void setStartContext(boolean startContext)
           
protected  void setUp()
          Normal JUnit method
protected  void suitePostTearDown()
          Run after all testcase teardowns.
protected  void suitePreSetUp()
          Run before any testcase setup.
protected  void tearDown()
          Normal JUnit method
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runTest, 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
 

Field Detail

IGNORED_DOT_MULE_DIRS

public static final String[] IGNORED_DOT_MULE_DIRS
Top-level directories under .mule which are not deleted on each test case recycle. This is required, e.g. to play nice with transaction manager recovery service object store.


PROPERTY_MULE_TEST_TIMEOUT

public static final String PROPERTY_MULE_TEST_TIMEOUT
Name of a property to override the default test watchdog timeout.

See Also:
DEFAULT_MULE_TEST_TIMEOUT_SECS, Constant Field Values

DEFAULT_MULE_TEST_TIMEOUT_SECS

public static final int DEFAULT_MULE_TEST_TIMEOUT_SECS
Default test watchdog timeout in seconds.

See Also:
Constant Field Values

CLASSNAME_ANNOTATIONS_CONFIG_BUILDER

public static final String CLASSNAME_ANNOTATIONS_CONFIG_BUILDER
If the annotations module is on the classpath, also enable annotations config builder

See Also:
Constant Field Values

muleContext

protected static MuleContext muleContext

logger

protected final transient Log logger

numPorts

protected int numPorts

ports

public List<Integer> ports

TEST_MESSAGE

public static final String TEST_MESSAGE
Convenient test message for unit testing.

See Also:
Constant Field Values

LOCK_TIMEOUT

public static final long LOCK_TIMEOUT
Default timeout for multithreaded tests (using CountDownLatch, WaitableBoolean, etc.), in milliseconds. The higher this value, the more reliable the test will be, so it should be set high for Continuous Integration. However, this can waste time during day-to-day development cycles, so you may want to temporarily lower it while debugging.

See Also:
Constant Field Values

RECEIVE_TIMEOUT

public static final int RECEIVE_TIMEOUT
Default timeout for waiting for responses

See Also:
Constant Field Values

callbackCalled

protected Latch callbackCalled
Use this as a semaphore to the unit test to indicate when a callback has successfully been called.


testTimeoutSecs

protected int testTimeoutSecs
Timeout used for the test watchdog

Constructor Detail

AbstractMuleTestCase

public AbstractMuleTestCase()
Method Detail

registerTestMethod

protected void registerTestMethod()

initTestTimeoutSecs

protected void initTestTimeoutSecs()

setName

public void setName(String name)
Overrides:
setName in class junit.framework.TestCase

createTestInfo

protected AbstractMuleTestCase.TestInfo createTestInfo()

getTestInfo

protected AbstractMuleTestCase.TestInfo getTestInfo()

run

public void run(junit.framework.TestResult result)
Specified by:
run in interface junit.framework.Test
Overrides:
run in class junit.framework.TestCase

runBare

public void runBare()
             throws Throwable
Shamelessly copy from Spring's ConditionalTestCase so in MULE-2.0 we can extend this class from ConditionalTestCase.

Subclasses can override isDisabledInThisEnvironment to skip a single test.

Overrides:
runBare in class junit.framework.TestCase
Throws:
Throwable

isDisabledInThisEnvironment

protected boolean isDisabledInThisEnvironment()
Subclasses can override this method to skip the execution of the entire test class.

Returns:
true if the test class should not be run.

isExcluded

protected boolean isExcluded()
Indicates whether this test has been explicitly disabled through the configuration file loaded by TestInfo.

Returns:
whether the test has been explicitly disabled

isDisabledInThisEnvironment

protected boolean isDisabledInThisEnvironment(String testMethodName)
Should this test run?

Parameters:
testMethodName - name of the test method
Returns:
whether the test should execute in the current envionment

isOffline

public boolean isOffline(String method)

isDisposeManagerPerSuite

protected boolean isDisposeManagerPerSuite()

setDisposeManagerPerSuite

protected void setDisposeManagerPerSuite(boolean val)

getTestTimeoutSecs

public int getTestTimeoutSecs()

createWatchdog

protected TestCaseWatchdog createWatchdog()

handleTimeout

public void handleTimeout(long timeout,
                          TimeUnit unit)
Specified by:
handleTimeout in interface TestCaseWatchdogTimeoutHandler

giveTheTestSomeTimeToCleanUpAndThenKillIt

protected void giveTheTestSomeTimeToCleanUpAndThenKillIt(String messageIfNeedToKill)

setUp

protected final void setUp()
                    throws Exception
Normal JUnit method

Overrides:
setUp in class junit.framework.TestCase
Throws:
Exception
See Also:
doSetUp()

printTestHeader

protected void printTestHeader()

getTestHeader

protected String getTestHeader()

createMuleContext

protected MuleContext createMuleContext()
                                 throws Exception
Throws:
Exception

addBuilders

protected void addBuilders(List<ConfigurationBuilder> builders)

configureMuleContext

protected void configureMuleContext(MuleContextBuilder contextBuilder)
Override this method to set properties of the MuleContextBuilder before it is used to create the MuleContext.


getBuilder

protected ConfigurationBuilder getBuilder()
                                   throws Exception
Throws:
Exception

getConfigurationResources

protected String getConfigurationResources()

getStartUpProperties

protected Properties getStartUpProperties()

suitePreSetUp

protected void suitePreSetUp()
                      throws Exception
Run before any testcase setup. This is called once only before the test suite runs.

Throws:
Exception

suitePostTearDown

protected void suitePostTearDown()
                          throws Exception
Run after all testcase teardowns. This is called once only after all the tests in the suite have run.

Throws:
Exception

tearDown

protected final void tearDown()
                       throws Exception
Normal JUnit method

Overrides:
tearDown in class junit.framework.TestCase
Throws:
Exception
See Also:
doTearDown()

disposeManager

protected void disposeManager()

doSetUp

protected void doSetUp()
                throws Exception
Exactly the same a setUp() in normal JUnit test cases. this is called before a test method has been called.

Throws:
Exception - if something fails that should halt the testcase

doTearDown

protected void doTearDown()
                   throws Exception
Exactly the same a tearDown() in normal JUnit test cases. this is called after a test method has been called.

Throws:
Exception - if something fails that should halt the testcase

getTestInboundEndpoint

public static InboundEndpoint getTestInboundEndpoint(String name)
                                              throws Exception
Throws:
Exception

getTestOutboundEndpoint

public static OutboundEndpoint getTestOutboundEndpoint(String name)
                                                throws Exception
Throws:
Exception

getTestInboundEndpoint

public static InboundEndpoint getTestInboundEndpoint(MessageExchangePattern mep)
                                              throws Exception
Throws:
Exception

getTestTransactedInboundEndpoint

public static InboundEndpoint getTestTransactedInboundEndpoint(MessageExchangePattern mep)
                                                        throws Exception
Throws:
Exception

getTestInboundEndpoint

public static InboundEndpoint getTestInboundEndpoint(String name,
                                                     String uri)
                                              throws Exception
Throws:
Exception

getTestOutboundEndpoint

public static OutboundEndpoint getTestOutboundEndpoint(String name,
                                                       String uri)
                                                throws Exception
Throws:
Exception

getTestInboundEndpoint

public static InboundEndpoint getTestInboundEndpoint(String name,
                                                     List<Transformer> transformers)
                                              throws Exception
Throws:
Exception

getTestOutboundEndpoint

public static OutboundEndpoint getTestOutboundEndpoint(String name,
                                                       List<Transformer> transformers)
                                                throws Exception
Throws:
Exception

getTestInboundEndpoint

public static InboundEndpoint getTestInboundEndpoint(String name,
                                                     String uri,
                                                     List<Transformer> transformers,
                                                     Filter filter,
                                                     Map<Object,Object> properties,
                                                     Connector connector)
                                              throws Exception
Throws:
Exception

getTestOutboundEndpoint

public static OutboundEndpoint getTestOutboundEndpoint(String name,
                                                       String uri,
                                                       List<Transformer> transformers,
                                                       Filter filter,
                                                       Map<Object,Object> properties)
                                                throws Exception
Throws:
Exception

getTestInboundEndpoint

public static InboundEndpoint getTestInboundEndpoint(String name,
                                                     String uri,
                                                     List<Transformer> transformers,
                                                     Filter filter,
                                                     Map<Object,Object> properties)
                                              throws Exception
Throws:
Exception

getTestOutboundEndpoint

public static OutboundEndpoint getTestOutboundEndpoint(String name,
                                                       String uri,
                                                       List<Transformer> transformers,
                                                       Filter filter,
                                                       Map<Object,Object> properties,
                                                       Connector connector)
                                                throws Exception
Throws:
Exception

getTestEvent

public static MuleEvent getTestEvent(Object data,
                                     Service service)
                              throws Exception
Throws:
Exception

getTestEvent

public static MuleEvent getTestEvent(Object data,
                                     Service service,
                                     MessageExchangePattern mep)
                              throws Exception
Throws:
Exception

getTestEvent

public static MuleEvent getTestEvent(Object data)
                              throws Exception
Throws:
Exception

getTestEventUsingFlow

public static MuleEvent getTestEventUsingFlow(Object data)
                                       throws Exception
Throws:
Exception

getTestEvent

public static MuleEvent getTestEvent(Object data,
                                     MessageExchangePattern mep)
                              throws Exception
Throws:
Exception

getTestEvent

public static MuleEvent getTestEvent(Object data,
                                     MuleSession session)
                              throws Exception
Throws:
Exception

getTestEventContext

public static MuleEventContext getTestEventContext(Object data)
                                            throws Exception
Throws:
Exception

getTestEventContext

public static MuleEventContext getTestEventContext(Object data,
                                                   MessageExchangePattern mep)
                                            throws Exception
Throws:
Exception

getTestTransformer

public static Transformer getTestTransformer()
                                      throws Exception
Throws:
Exception

getTestEvent

public static MuleEvent getTestEvent(Object data,
                                     InboundEndpoint endpoint)
                              throws Exception
Throws:
Exception

getTestEvent

public static MuleEvent getTestEvent(Object data,
                                     Service service,
                                     InboundEndpoint endpoint)
                              throws Exception
Throws:
Exception

getTestSession

public static MuleSession getTestSession(Service service,
                                         MuleContext context)

getTestConnector

public static TestConnector getTestConnector()
                                      throws Exception
Throws:
Exception

getTestService

public static Service getTestService()
                              throws Exception
Throws:
Exception

getTestService

public static Service getTestService(String name,
                                     Class<?> clazz)
                              throws Exception
Throws:
Exception

getTestService

public static Service getTestService(String name,
                                     Class<?> clazz,
                                     Map<?,?> props)
                              throws Exception
Throws:
Exception

isStartContext

protected boolean isStartContext()

setStartContext

protected void setStartContext(boolean startContext)

setFailOnTimeout

public void setFailOnTimeout(boolean failOnTimeout)

isGracefulShutdown

protected boolean isGracefulShutdown()
Determines if the test case should perform graceful shutdown or not. Default is false so that tests run more quickly.


createObject

protected <T> T createObject(Class<T> clazz)
                  throws Exception
Create an object of instance clazz. It will then register the object with the registry so that any dependencies are injected and then the object will be initialised. Note that if the object needs to be configured with additional state that cannot be passed into the constructor you should create an instance first set any additional data on the object then call initialiseObject(Object).

Type Parameters:
T - Object of this type will be returned
Parameters:
clazz - the class to create an instance of.
Returns:
an initialised instance of class
Throws:
Exception - if there is a problem creating or initializing the object

createObject

protected <T> T createObject(Class<T> clazz,
                             Object... args)
                  throws Exception
Create an object of instance clazz. It will then register the object with the registry so that any dependencies are injected and then the object will be initialised. Note that if the object needs to be configured with additional state that cannot be passed into the constructor you should create an instance first set any additional data on the object then call initialiseObject(Object).

Type Parameters:
T - Object of this type will be returned
Parameters:
clazz - the class to create an instance of.
args - constructor parameters
Returns:
an initialised instance of class
Throws:
Exception - if there is a problem creating or initializing the object

initialiseObject

protected void initialiseObject(Object o)
                         throws RegistrationException
A convenience method that will register an object in the registry using its hashcode as the key. This will cause the object to have any objects injected and lifecycle methods called. Note that the object lifecycle will be called to the same current lifecycle as the MuleContext

Parameters:
o - the object to register and initialize it
Throws:
RegistrationException

getSensingNullMessageProcessor

public SensingNullMessageProcessor getSensingNullMessageProcessor()

getTriggerableMessageSource

public TriggerableMessageSource getTriggerableMessageSource(MessageProcessor listener)

getTriggerableMessageSource

public TriggerableMessageSource getTriggerableMessageSource()

getPorts

public List<Integer> getPorts()


Copyright © 2003-2011 MuleSoft, Inc.. All Rights Reserved.