org.apache.camel.test.junit4
Class CamelTestSupport

java.lang.Object
  extended by org.junit.Assert
      extended by org.apache.camel.test.junit4.TestSupport
          extended by org.apache.camel.test.junit4.CamelTestSupport
Direct Known Subclasses:
CamelSpringTestSupport

public abstract class CamelTestSupport
extends TestSupport

A useful base class which creates a CamelContext with some routes along with a ProducerTemplate for use in the test case

Version:
$Revision: 786457 $

Field Summary
protected  ConsumerTemplate consumer
           
protected  CamelContext context
           
protected  ProducerTemplate template
           
 
Fields inherited from class org.apache.camel.test.junit4.TestSupport
log
 
Constructor Summary
CamelTestSupport()
           
 
Method Summary
protected  void assertExpression(Exchange exchange, String languageName, String expressionText, Object expectedValue)
          Asserts that the given language name and expression evaluates to the given value on a specific exchange
protected  void assertMockEndpointsSatisfied()
          Asserts that all the expectations of the Mock endpoints are valid
protected  void assertPredicate(String languageName, String expressionText, Exchange exchange, boolean expected)
          Asserts that the given language name and predicate expression evaluates to the expected value on the message exchange
protected  Language assertResolveLanguage(String languageName)
          Asserts that the language name can be resolved
protected  void assertValidContext(CamelContext context)
           
protected  CamelContext createCamelContext()
           
protected  Exchange createExchangeWithBody(Object body)
          Creates an exchange with the given body
protected  Context createJndiContext()
           
protected  JndiRegistry createRegistry()
           
protected  RouteBuilder createRouteBuilder()
          Factory method which derived classes can use to create a RouteBuilder to define the routes for testing
protected  RouteBuilder[] createRouteBuilders()
          Factory method which derived classes can use to create an array of RouteBuilders to define the routes for testing
protected  void disableJMX()
          Disables the JMX agent.
protected  void enableJMX()
          Enables the JMX agent.
 Service getCamelContextService()
           
protected  Endpoint getMandatoryEndpoint(String uri)
           
protected
<T extends Endpoint>
T
getMandatoryEndpoint(String uri, Class<T> type)
           
protected  MockEndpoint getMockEndpoint(String uri)
          Resolves the mandatory Mock endpoint using a URI of the form mock:someName
protected
<T> List<T>
getSingletonEndpoints(Class<T> type)
           
 boolean isUseRouteBuilder()
           
protected  void postProcessTest()
          Lets post process this test instance to process any Camel annotations.
protected  Endpoint resolveMandatoryEndpoint(String uri)
          Resolves a mandatory endpoint for the given URI or an exception is thrown
protected
<T extends Endpoint>
T
resolveMandatoryEndpoint(String uri, Class<T> endpointType)
          Resolves a mandatory endpoint for the given URI and expected type or an exception is thrown
protected  void sendBodies(String endpointUri, Object... bodies)
          Sends messages to the given endpoint for each of the specified bodies
protected  void sendBody(String endpointUri, Object body)
          Sends a message to the given endpoint URI with the body value
protected  void sendBody(String endpointUri, Object body, Map<String,Object> headers)
          Sends a message to the given endpoint URI with the body value and specified headers
 void setCamelContextService(Service camelContextService)
          Allows a service to be registered a separate lifecycle service to start and stop the context; such as for Spring when the ApplicationContext is started and stopped, rather than directly stopping the CamelContext
 void setUp()
           
 void setUseRouteBuilder(boolean useRouteBuilder)
           
protected  void startCamelContext()
           
protected  void stopCamelContext()
           
 void tearDown()
           
 
Methods inherited from class org.apache.camel.test.junit4.TestSupport
assertCollectionSize, assertCollectionSize, assertDirectoryEquals, assertDirectoryEquals, assertEndpointUri, assertExpression, assertInMessageBodyEquals, assertInMessageHeader, assertIsInstanceOf, assertListSize, assertListSize, assertMessageHeader, assertOneElement, assertOutMessageBodyEquals, assertOutMessageHeader, assertPredicate, assertPredicateDoesNotMatch, assertPredicateMatches, assertStringContains, body, bodyAs, createDirectory, createExchangeWithBody, deleteDirectory, deleteDirectory, faultBody, faultBodyAs, getRouteList, header, outBody, outBodyAs, property, resolveMandatoryEndpoint, resolveMandatoryEndpoint, systemProperty, systemProperty, unwrap, unwrapChannel
 
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArraysAreSameLength, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail, isArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected CamelContext context

template

protected ProducerTemplate template

consumer

protected ConsumerTemplate consumer
Constructor Detail

CamelTestSupport

public CamelTestSupport()
Method Detail

isUseRouteBuilder

public boolean isUseRouteBuilder()

setUseRouteBuilder

public void setUseRouteBuilder(boolean useRouteBuilder)

getCamelContextService

public Service getCamelContextService()

setCamelContextService

public void setCamelContextService(Service camelContextService)
Allows a service to be registered a separate lifecycle service to start and stop the context; such as for Spring when the ApplicationContext is started and stopped, rather than directly stopping the CamelContext


setUp

public void setUp()
           throws Exception
Throws:
Exception

tearDown

public void tearDown()
              throws Exception
Throws:
Exception

postProcessTest

protected void postProcessTest()
                        throws Exception
Lets post process this test instance to process any Camel annotations. Note that using Spring Test or Guice is a more powerful approach.

Throws:
Exception

stopCamelContext

protected void stopCamelContext()
                         throws Exception
Throws:
Exception

startCamelContext

protected void startCamelContext()
                          throws Exception
Throws:
Exception

createCamelContext

protected CamelContext createCamelContext()
                                   throws Exception
Throws:
Exception

createRegistry

protected JndiRegistry createRegistry()
                               throws Exception
Throws:
Exception

createJndiContext

protected Context createJndiContext()
                             throws Exception
Throws:
Exception

createRouteBuilder

protected RouteBuilder createRouteBuilder()
                                   throws Exception
Factory method which derived classes can use to create a RouteBuilder to define the routes for testing

Throws:
Exception

createRouteBuilders

protected RouteBuilder[] createRouteBuilders()
                                      throws Exception
Factory method which derived classes can use to create an array of RouteBuilders to define the routes for testing

Throws:
Exception
See Also:
createRouteBuilder()

resolveMandatoryEndpoint

protected Endpoint resolveMandatoryEndpoint(String uri)
Resolves a mandatory endpoint for the given URI or an exception is thrown

Parameters:
uri - the Camel URI to use to create or resolve an endpoint
Returns:
the endpoint

resolveMandatoryEndpoint

protected <T extends Endpoint> T resolveMandatoryEndpoint(String uri,
                                                          Class<T> endpointType)
Resolves a mandatory endpoint for the given URI and expected type or an exception is thrown

Parameters:
uri - the Camel URI to use to create or resolve an endpoint
Returns:
the endpoint

getMockEndpoint

protected MockEndpoint getMockEndpoint(String uri)
Resolves the mandatory Mock endpoint using a URI of the form mock:someName

Parameters:
uri - the URI which typically starts with "mock:" and has some name
Returns:
the mandatory mock endpoint or an exception is thrown if it could not be resolved

sendBody

protected void sendBody(String endpointUri,
                        Object body)
Sends a message to the given endpoint URI with the body value

Parameters:
endpointUri - the URI of the endpoint to send to
body - the body for the message

sendBody

protected void sendBody(String endpointUri,
                        Object body,
                        Map<String,Object> headers)
Sends a message to the given endpoint URI with the body value and specified headers

Parameters:
endpointUri - the URI of the endpoint to send to
body - the body for the message
headers - any headers to set on the message

sendBodies

protected void sendBodies(String endpointUri,
                          Object... bodies)
Sends messages to the given endpoint for each of the specified bodies

Parameters:
endpointUri - the endpoint URI to send to
bodies - the bodies to send, one per message

createExchangeWithBody

protected Exchange createExchangeWithBody(Object body)
Creates an exchange with the given body


assertExpression

protected void assertExpression(Exchange exchange,
                                String languageName,
                                String expressionText,
                                Object expectedValue)
Asserts that the given language name and expression evaluates to the given value on a specific exchange


assertPredicate

protected void assertPredicate(String languageName,
                               String expressionText,
                               Exchange exchange,
                               boolean expected)
Asserts that the given language name and predicate expression evaluates to the expected value on the message exchange


assertResolveLanguage

protected Language assertResolveLanguage(String languageName)
Asserts that the language name can be resolved


assertMockEndpointsSatisfied

protected void assertMockEndpointsSatisfied()
                                     throws InterruptedException
Asserts that all the expectations of the Mock endpoints are valid

Throws:
InterruptedException

assertValidContext

protected void assertValidContext(CamelContext context)

getSingletonEndpoints

protected <T> List<T> getSingletonEndpoints(Class<T> type)

getMandatoryEndpoint

protected <T extends Endpoint> T getMandatoryEndpoint(String uri,
                                                      Class<T> type)

getMandatoryEndpoint

protected Endpoint getMandatoryEndpoint(String uri)

disableJMX

protected void disableJMX()
Disables the JMX agent. Must be called before the setUp() method.


enableJMX

protected void enableJMX()
Enables the JMX agent. Must be called before the setUp() method.



Apache CAMEL