org.apache.camel.test.junit4
Class TestSupport

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

public abstract class TestSupport
extends org.junit.Assert

A bunch of useful testing methods

Version:

Field Summary
protected  org.slf4j.Logger log
           
protected static String LS
           
 org.junit.rules.TestName testName
           
 
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(org.apache.camel.Endpoint endpoint, String uri)
           
static Object assertExpression(org.apache.camel.Expression expression, org.apache.camel.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(org.apache.camel.Exchange exchange, Object expected)
          Asserts that the given exchange has an OUT message of the given body value
static Object assertInMessageHeader(org.apache.camel.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(org.apache.camel.Message message, String name, Object expected)
           
static
<T> T
assertOneElement(List<T> list)
           
static void assertOutMessageBodyEquals(org.apache.camel.Exchange exchange, Object expected)
          Asserts that the given exchange has an OUT message of the given body value
static Object assertOutMessageHeader(org.apache.camel.Exchange exchange, String name, Object expected)
          Asserts the Out message on the exchange contains the expected value
static boolean assertPredicate(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange, boolean expected)
          Asserts that the predicate returns the expected value on the exchange
static void assertPredicateDoesNotMatch(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange)
          Asserts that the predicate returns the expected value on the exchange
static void assertPredicateMatches(org.apache.camel.Predicate predicate, org.apache.camel.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 org.apache.camel.builder.ValueBuilder body()
          Returns a predicate and value builder for the inbound body on an exchange
static
<T> org.apache.camel.builder.ValueBuilder
bodyAs(Class<T> type)
          Returns a predicate and value builder for the inbound message body as a specific type
static void createDirectory(String file)
          create the directory
protected  org.apache.camel.Exchange createExchangeWithBody(org.apache.camel.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 org.apache.camel.builder.ValueBuilder faultBody()
          Returns a predicate and value builder for the fault body on an exchange
static
<T> org.apache.camel.builder.ValueBuilder
faultBodyAs(Class<T> type)
          Returns a predicate and value builder for the fault message body as a specific type
static List<org.apache.camel.Route> getRouteList(org.apache.camel.builder.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 org.apache.camel.builder.ValueBuilder header(String name)
          Returns a value builder for the given header
static boolean isJava15()
          Deprecated. will be removed in the near future as Camel now requires JDK1.6+
static boolean isJavaVendor(String vendor)
          Is this Java by the given vendor.
static boolean isPlatform(String platform)
          Is this OS the given platform.
static org.apache.camel.builder.ValueBuilder outBody()
          Returns a predicate and value builder for the outbound body on an exchange
static
<T> org.apache.camel.builder.ValueBuilder
outBodyAs(Class<T> type)
          Returns a predicate and value builder for the outbound message body as a specific type
static org.apache.camel.builder.ValueBuilder property(String name)
          Returns a value builder for the given property
static org.apache.camel.Endpoint resolveMandatoryEndpoint(org.apache.camel.CamelContext context, String uri)
          Resolves an endpoint and asserts that it is found
static
<T extends org.apache.camel.Endpoint>
T
resolveMandatoryEndpoint(org.apache.camel.CamelContext context, String uri, Class<T> endpointType)
          Resolves an endpoint and asserts that it is found
static org.apache.camel.builder.ValueBuilder systemProperty(String name)
          Returns a value builder for the given system property
static org.apache.camel.builder.ValueBuilder systemProperty(String name, String defaultValue)
          Returns a value builder for the given system property
static org.apache.camel.Processor unwrap(org.apache.camel.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 org.apache.camel.Channel unwrapChannel(org.apache.camel.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 org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LS

protected static final String LS

log

protected transient org.slf4j.Logger log

testName

public org.junit.rules.TestName testName
Constructor Detail

TestSupport

public TestSupport()
Method Detail

header

public static org.apache.camel.builder.ValueBuilder header(String name)
Returns a value builder for the given header


property

public static org.apache.camel.builder.ValueBuilder property(String name)
Returns a value builder for the given property


body

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


bodyAs

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


outBody

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


outBodyAs

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


faultBody

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


faultBodyAs

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


systemProperty

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


systemProperty

public static org.apache.camel.builder.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(org.apache.camel.Endpoint endpoint,
                                     String uri)

assertInMessageHeader

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


assertOutMessageHeader

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


assertInMessageBodyEquals

public static void assertInMessageBodyEquals(org.apache.camel.Exchange exchange,
                                             Object expected)
                                      throws org.apache.camel.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:
org.apache.camel.InvalidPayloadException - is thrown if the payload is not the expected class type

assertOutMessageBodyEquals

public static void assertOutMessageBodyEquals(org.apache.camel.Exchange exchange,
                                              Object expected)
                                       throws org.apache.camel.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:
org.apache.camel.InvalidPayloadException - is thrown if the payload is not the expected class type

assertMessageHeader

public static Object assertMessageHeader(org.apache.camel.Message message,
                                         String name,
                                         Object expected)

assertExpression

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


assertPredicateMatches

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


assertPredicateDoesNotMatch

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


assertPredicate

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


resolveMandatoryEndpoint

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


resolveMandatoryEndpoint

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


createExchangeWithBody

protected org.apache.camel.Exchange createExchangeWithBody(org.apache.camel.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<org.apache.camel.Route> getRouteList(org.apache.camel.builder.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 org.apache.camel.Processor unwrap(org.apache.camel.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 org.apache.camel.Channel unwrapChannel(org.apache.camel.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

@Deprecated
public static boolean isJava15()
Deprecated. will be removed in the near future as Camel now requires JDK1.6+

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