org.apache.camel.test
Class TestSupport

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.camel.test.TestSupport
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
CamelTestSupport

public abstract class TestSupport
extends junit.framework.TestCase

A bunch of useful testing methods

Version:

Field Summary
protected  org.slf4j.Logger log
           
 
Constructor Summary
TestSupport()
           
 
Method Summary
static
<T> Collection<T>
assertCollectionSize(Collection<T> list, int size)
          Asserts that a list is of the given size
static
<T> Collection<T>
assertCollectionSize(String message, Collection<T> list, int size)
          Asserts that a list is of the given size
static void assertDirectoryEquals(String expected, String actual)
          To be used for folder/directory comparison that works across different platforms such as Window, Mac and Linux.
static void assertDirectoryEquals(String message, String expected, String actual)
          To be used for folder/directory comparison that works across different platforms such as Window, Mac and Linux.
static void assertEndpointUri(Endpoint endpoint, String uri)
           
static Object assertExpression(Expression expression, Exchange exchange, Object expected)
          Asserts that the given expression when evaluated returns the given answer
static void assertFileExists(String filename)
          To be used to check is a file is found in the file system
static void assertInMessageBodyEquals(Exchange exchange, Object expected)
          Asserts that the given exchange has an OUT message of the given body value
static Object assertInMessageHeader(Exchange exchange, String name, Object expected)
          Asserts the In message on the exchange contains the expected value
static
<T> T
assertIsInstanceOf(Class<T> expectedType, Object value)
           
static
<T> List<T>
assertListSize(List<T> list, int size)
          Asserts that a list is of the given size
static
<T> List<T>
assertListSize(String message, List<T> list, int size)
          Asserts that a list is of the given size
static Object assertMessageHeader(Message message, String name, Object expected)
           
static
<T> T
assertOneElement(List<T> list)
           
static void assertOutMessageBodyEquals(Exchange exchange, Object expected)
          Asserts that the given exchange has an OUT message of the given body value
static Object assertOutMessageHeader(Exchange exchange, String name, Object expected)
          Asserts the Out message on the exchange contains the expected value
static boolean assertPredicate(Predicate predicate, Exchange exchange, boolean expected)
          Asserts that the predicate returns the expected value on the exchange
static void assertPredicateDoesNotMatch(Predicate predicate, Exchange exchange)
          Asserts that the predicate returns the expected value on the exchange
static void assertPredicateMatches(Predicate predicate, Exchange exchange)
          Asserts that the predicate returns the expected value on the exchange
static void assertStringContains(String text, String containedText)
          Asserts that the text contains the given string
static ValueBuilder body()
          Returns a predicate and value builder for the inbound body on an exchange
static
<T> ValueBuilder
bodyAs(Class<T> type)
          Returns a predicate and value builder for the inbound message body as a specific type
protected  boolean canRunOnThisPlatform()
           
static void createDirectory(String file)
          create the directory
protected  Exchange createExchangeWithBody(CamelContext camelContext, Object body)
          Creates an exchange with the given body
static void deleteDirectory(File file)
          Recursively delete a directory, useful to zapping test data
static void deleteDirectory(String file)
          Recursively delete a directory, useful to zapping test data
static ValueBuilder faultBody()
          Returns a predicate and value builder for the fault body on an exchange
static
<T> ValueBuilder
faultBodyAs(Class<T> type)
          Returns a predicate and value builder for the fault message body as a specific type
static List<Route> getRouteList(RouteBuilder builder)
          A helper method to create a list of Route objects for a given route builder
 String getTestMethodName()
          Gets the current test method name
static ValueBuilder header(String name)
          Returns a value builder for the given header
static boolean isJava15()
          Is this Java 1.5
static boolean isJavaVendor(String vendor)
          Is this Java by the given vendor.
static boolean isPlatform(String platform)
          Is this OS the given platform.
static ValueBuilder outBody()
          Returns a predicate and value builder for the outbound body on an exchange
static
<T> ValueBuilder
outBodyAs(Class<T> type)
          Returns a predicate and value builder for the outbound message body as a specific type
static ValueBuilder property(String name)
          Returns a value builder for the given property
static Endpoint resolveMandatoryEndpoint(CamelContext context, String uri)
          Resolves an endpoint and asserts that it is found
static
<T extends Endpoint>
T
resolveMandatoryEndpoint(CamelContext context, String uri, Class<T> endpointType)
          Resolves an endpoint and asserts that it is found
 void runBare()
          Runs the bare test sequence only if this platform is supported
static ValueBuilder systemProperty(String name)
          Returns a value builder for the given system property
static ValueBuilder systemProperty(String name, String defaultValue)
          Returns a value builder for the given system property
static Processor unwrap(Processor processor)
          If a processor is wrapped with a bunch of DelegateProcessor or DelegateAsyncProcessor objects this call will drill through them and return the wrapped Processor.
static Channel unwrapChannel(Processor processor)
          If a processor is wrapped with a bunch of DelegateProcessor or DelegateAsyncProcessor objects this call will drill through them and return the Channel.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, tearDown, 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

log

protected transient org.slf4j.Logger log
Constructor Detail

TestSupport

public TestSupport()
Method Detail

runBare

public void runBare()
             throws Throwable
Runs the bare test sequence only if this platform is supported

Overrides:
runBare in class junit.framework.TestCase
Throws:
Throwable - if any exception is thrown

canRunOnThisPlatform

protected boolean canRunOnThisPlatform()

header

public static ValueBuilder header(String name)
Returns a value builder for the given header


property

public static ValueBuilder property(String name)
Returns a value builder for the given property


body

public static ValueBuilder body()
Returns a predicate and value builder for the inbound body on an exchange


bodyAs

public static <T> ValueBuilder bodyAs(Class<T> type)
Returns a predicate and value builder for the inbound message body as a specific type


outBody

public static ValueBuilder outBody()
Returns a predicate and value builder for the outbound body on an exchange


outBodyAs

public static <T> ValueBuilder outBodyAs(Class<T> type)
Returns a predicate and value builder for the outbound message body as a specific type


faultBody

public static ValueBuilder faultBody()
Returns a predicate and value builder for the fault body on an exchange


faultBodyAs

public static <T> ValueBuilder faultBodyAs(Class<T> type)
Returns a predicate and value builder for the fault message body as a specific type


systemProperty

public static ValueBuilder systemProperty(String name)
Returns a value builder for the given system property


systemProperty

public static ValueBuilder systemProperty(String name,
                                          String defaultValue)
Returns a value builder for the given system property


assertIsInstanceOf

public static <T> T assertIsInstanceOf(Class<T> expectedType,
                                       Object value)

assertEndpointUri

public static void assertEndpointUri(Endpoint endpoint,
                                     String uri)

assertInMessageHeader

public static Object assertInMessageHeader(Exchange exchange,
                                           String name,
                                           Object expected)
Asserts the In message on the exchange contains the expected value


assertOutMessageHeader

public static Object assertOutMessageHeader(Exchange exchange,
                                            String name,
                                            Object expected)
Asserts the Out message on the exchange contains the expected value


assertInMessageBodyEquals

public static void assertInMessageBodyEquals(Exchange exchange,
                                             Object expected)
                                      throws InvalidPayloadException
Asserts that the given exchange has an OUT message of the given body value

Parameters:
exchange - the exchange which should have an OUT message
expected - the expected value of the OUT message
Throws:
InvalidPayloadException - is thrown if the payload is not the expected class type

assertOutMessageBodyEquals

public static void assertOutMessageBodyEquals(Exchange exchange,
                                              Object expected)
                                       throws InvalidPayloadException
Asserts that the given exchange has an OUT message of the given body value

Parameters:
exchange - the exchange which should have an OUT message
expected - the expected value of the OUT message
Throws:
InvalidPayloadException - is thrown if the payload is not the expected class type

assertMessageHeader

public static Object assertMessageHeader(Message message,
                                         String name,
                                         Object expected)

assertExpression

public static Object assertExpression(Expression expression,
                                      Exchange exchange,
                                      Object expected)
Asserts that the given expression when evaluated returns the given answer


assertPredicateMatches

public static void assertPredicateMatches(Predicate predicate,
                                          Exchange exchange)
Asserts that the predicate returns the expected value on the exchange


assertPredicateDoesNotMatch

public static void assertPredicateDoesNotMatch(Predicate predicate,
                                               Exchange exchange)
Asserts that the predicate returns the expected value on the exchange


assertPredicate

public static boolean assertPredicate(Predicate predicate,
                                      Exchange exchange,
                                      boolean expected)
Asserts that the predicate returns the expected value on the exchange


resolveMandatoryEndpoint

public static Endpoint resolveMandatoryEndpoint(CamelContext context,
                                                String uri)
Resolves an endpoint and asserts that it is found


resolveMandatoryEndpoint

public static <T extends Endpoint> T resolveMandatoryEndpoint(CamelContext context,
                                                              String uri,
                                                              Class<T> endpointType)
Resolves an endpoint and asserts that it is found


createExchangeWithBody

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


assertOneElement

public static <T> T assertOneElement(List<T> list)

assertListSize

public static <T> List<T> assertListSize(List<T> list,
                                         int size)
Asserts that a list is of the given size


assertListSize

public static <T> List<T> assertListSize(String message,
                                         List<T> list,
                                         int size)
Asserts that a list is of the given size


assertCollectionSize

public static <T> Collection<T> assertCollectionSize(Collection<T> list,
                                                     int size)
Asserts that a list is of the given size


assertCollectionSize

public static <T> Collection<T> assertCollectionSize(String message,
                                                     Collection<T> list,
                                                     int size)
Asserts that a list is of the given size


getRouteList

public static List<Route> getRouteList(RouteBuilder builder)
                                throws Exception
A helper method to create a list of Route objects for a given route builder

Throws:
Exception

assertStringContains

public static void assertStringContains(String text,
                                        String containedText)
Asserts that the text contains the given string

Parameters:
text - the text to compare
containedText - the text which must be contained inside the other text parameter

unwrap

public static Processor unwrap(Processor processor)
If a processor is wrapped with a bunch of DelegateProcessor or DelegateAsyncProcessor objects this call will drill through them and return the wrapped Processor.


unwrapChannel

public static Channel unwrapChannel(Processor processor)
If a processor is wrapped with a bunch of DelegateProcessor or DelegateAsyncProcessor objects this call will drill through them and return the Channel.

Returns null if no channel is found.


deleteDirectory

public static void deleteDirectory(String file)
Recursively delete a directory, useful to zapping test data

Parameters:
file - the directory to be deleted

deleteDirectory

public static void deleteDirectory(File file)
Recursively delete a directory, useful to zapping test data

Parameters:
file - the directory to be deleted

createDirectory

public static void createDirectory(String file)
create the directory

Parameters:
file - the directory to be created

assertDirectoryEquals

public static void assertDirectoryEquals(String expected,
                                         String actual)
To be used for folder/directory comparison that works across different platforms such as Window, Mac and Linux.


assertDirectoryEquals

public static void assertDirectoryEquals(String message,
                                         String expected,
                                         String actual)
To be used for folder/directory comparison that works across different platforms such as Window, Mac and Linux.


assertFileExists

public static void assertFileExists(String filename)
To be used to check is a file is found in the file system


isPlatform

public static boolean isPlatform(String platform)
Is this OS the given platform.

Uses os.name from the system properties to determine the OS.

Parameters:
platform - such as Windows
Returns:
true if its that platform.

isJavaVendor

public static boolean isJavaVendor(String vendor)
Is this Java by the given vendor.

Uses java.vendor from the system properties to determine the vendor.

Parameters:
vendor - such as IBM
Returns:
true if its that vendor.

isJava15

public static boolean isJava15()
Is this Java 1.5

Returns:
true if its Java 1.5, false if its not (for example Java 1.6 or better)

getTestMethodName

public String getTestMethodName()
Gets the current test method name

Returns:
the method name


Apache CAMEL