Package org.apache.camel.test.junit5
Class TestSupport
java.lang.Object
org.apache.camel.test.junit5.TestSupport
Provides utility methods for camel test purpose (builders, assertions, endpoint resolutions, file helpers).
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Collection
<T> assertCollectionSize
(String brokenAssertionMessagePrefix, Collection<T> list, int expectedSize) Asserts that a given collection has a given size.static <T> Collection
<T> assertCollectionSize
(Collection<T> list, int expectedSize) Asserts that a given collection has a given size.static void
assertDirectoryEquals
(String expected, String actual) Asserts that two given directories are equal.static void
assertDirectoryEquals
(String message, String expected, String actual) Asserts that two given directories are equal.static void
assertDirectoryExists
(String filename) Asserts that a given directory is found in the file system.static void
assertDirectoryExists
(Path file) To be used to check is a directory is found in the file systemstatic void
assertEndpointUri
(org.apache.camel.Endpoint endpoint, String expectedUri) Asserts that a given endpoint has an expected uri.static Object
assertExpression
(org.apache.camel.Expression expression, org.apache.camel.Exchange exchange, Object expectedAnswer) Asserts that the given expression when evaluated returns the given answer.static void
assertFileExists
(String filename) Asserts that a given file is found in the file system.static void
assertFileExists
(Path file) To be used to check is a file is found in the file systemstatic void
assertFileExists
(Path file, String content) To be used to check is a file is found in the file systemstatic void
assertFileNotExists
(String filename) Asserts that a given file is not found in the file system.static void
assertFileNotExists
(Path file) To be used to check is a file is not found in the file systemstatic void
assertInMessageBodyEquals
(org.apache.camel.Exchange exchange, Object expectedBody) Asserts that the given exchange has a given expectedBody on the IN message.static Object
assertInMessageHeader
(org.apache.camel.Exchange exchange, String headerName, Object expectedValue) Asserts that the In message on the exchange contains an header with a given name and expected value.static <T> T
assertIsInstanceOf
(Class<T> expectedType, Object value) Asserts that a given value is of an expected type.static <T> List
<T> assertListSize
(String brokenAssertionMessagePrefix, List<T> list, int expectedSize) Asserts that a list is of the given size.static <T> List
<T> assertListSize
(List<T> list, int expectedSize) Asserts that a given list has a given expected size.static void
assertMessageBodyEquals
(org.apache.camel.Exchange exchange, Object expectedBody) Asserts that the given exchange has a given expectedBody on the message.static Object
assertMessageHeader
(org.apache.camel.Message message, String headerName, Object expectedValue) Asserts that a given message contains an header with a given name and expected value.static <T> T
assertOneElement
(List<T> list) Asserts that a given list has a single element.static Object
assertOutMessageHeader
(org.apache.camel.Exchange exchange, String headerName, Object expectedValue) Asserts that the message on the exchange contains an header with a given name and expected value.static boolean
assertPredicate
(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange, boolean expectedValue) 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 a given predicate returnsfalse
on a given exchange.static void
assertPredicateMatches
(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange) Asserts that a given predicate returnstrue
on a given 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
Returns a predicate and value builder for the inbound message body as a specific type.static void
createCleanDirectory
(Path file) Creates a given directory.static void
createDirectory
(String file) Creates a given directory.static void
createDirectory
(Path file) Creates a given directory.static org.apache.camel.Exchange
createExchangeWithBody
(org.apache.camel.CamelContext camelContext, Object body) Creates an exchange with the given body.static boolean
deleteDirectory
(File file) Recursively delete a directory, useful to zapping test data.static boolean
deleteDirectory
(String file) Recursively delete a directory, useful to zapping test data.static boolean
deleteDirectory
(Path file) Recursively delete a directory, useful to zapping test data.static org.apache.camel.builder.ValueBuilder
exchangeProperty
(String name) Returns a value builder for the given exchange property.static void
executeSlowly
(int count, long interval, TimeUnit timeUnit, IntConsumer task) static String
static String
static int
Returns the current major Java version e.g 8.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.static org.apache.camel.builder.ValueBuilder
Returns a value builder for the given header.static boolean
Indicates whether the componentcamel-debug
is present in the classpath of the test.static boolean
isJavaVendor
(String expectedVendor) Tells whether the current Java Virtual Machine has been issued by a given expected vendor.static boolean
isPlatform
(String expectedPlatform) Tells whether the current Operating System is the given expected platform.static void
Recursively delete a directory.static org.apache.camel.Endpoint
resolveMandatoryEndpoint
(org.apache.camel.CamelContext context, String endpointUri) Resolves an endpoint and asserts that it is found.static <T extends org.apache.camel.Endpoint>
TresolveMandatoryEndpoint
(org.apache.camel.CamelContext context, String endpointUri, 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.
-
Method Details
-
header
Returns a value builder for the given header. -
exchangeProperty
Returns a value builder for the given exchange property. -
body
public static org.apache.camel.builder.ValueBuilder body()Returns a predicate and value builder for the inbound body on an exchange. -
bodyAs
Returns a predicate and value builder for the inbound message body as a specific type. -
systemProperty
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
Asserts that a given value is of an expected type. -
assertEndpointUri
Asserts that a given endpoint has an expected uri. -
assertInMessageHeader
public static Object assertInMessageHeader(org.apache.camel.Exchange exchange, String headerName, Object expectedValue) Asserts that the In message on the exchange contains an header with a given name and expected value. -
assertOutMessageHeader
public static Object assertOutMessageHeader(org.apache.camel.Exchange exchange, String headerName, Object expectedValue) Asserts that the message on the exchange contains an header with a given name and expected value. -
assertInMessageBodyEquals
public static void assertInMessageBodyEquals(org.apache.camel.Exchange exchange, Object expectedBody) throws org.apache.camel.InvalidPayloadException Asserts that the given exchange has a given expectedBody on the IN message.- Throws:
org.apache.camel.InvalidPayloadException
-
assertMessageBodyEquals
public static void assertMessageBodyEquals(org.apache.camel.Exchange exchange, Object expectedBody) throws org.apache.camel.InvalidPayloadException Asserts that the given exchange has a given expectedBody on the message.- Throws:
org.apache.camel.InvalidPayloadException
-
assertMessageHeader
public static Object assertMessageHeader(org.apache.camel.Message message, String headerName, Object expectedValue) Asserts that a given message contains an header with a given name and expected value. -
assertExpression
public static Object assertExpression(org.apache.camel.Expression expression, org.apache.camel.Exchange exchange, Object expectedAnswer) 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 a given predicate returnstrue
on a given exchange. -
assertPredicateDoesNotMatch
public static void assertPredicateDoesNotMatch(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange) Asserts that a given predicate returnsfalse
on a given exchange. -
assertPredicate
public static boolean assertPredicate(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange, boolean expectedValue) Asserts that the predicate returns the expected value on the exchange. -
assertOneElement
Asserts that a given list has a single element. -
assertListSize
Asserts that a given list has a given expected size. -
assertListSize
public static <T> List<T> assertListSize(String brokenAssertionMessagePrefix, List<T> list, int expectedSize) Asserts that a list is of the given size. When the assertion is broken, the error message starts with a given prefix. -
assertCollectionSize
Asserts that a given collection has a given size. -
assertCollectionSize
public static <T> Collection<T> assertCollectionSize(String brokenAssertionMessagePrefix, Collection<T> list, int expectedSize) Asserts that a given collection has a given size. When the assertion is broken, the error message starts with a given prefix. -
assertStringContains
Asserts that the text contains the given string.- Parameters:
text
- the text to comparecontainedText
- the text which must be contained inside the other text parameter
-
assertDirectoryEquals
Asserts that two given directories are equal. To be used for folder/directory comparison that works across different platforms such as Window, Mac and Linux. -
assertDirectoryEquals
Asserts that two given directories are equal. To be used for folder/directory comparison that works across different platforms such as Window, Mac and Linux. -
assertDirectoryExists
To be used to check is a directory is found in the file system -
assertDirectoryExists
Asserts that a given directory is found in the file system. -
assertFileExists
To be used to check is a file is found in the file system -
assertFileExists
To be used to check is a file is found in the file system- Throws:
IOException
-
assertFileExists
Asserts that a given file is found in the file system. -
assertFileNotExists
To be used to check is a file is not found in the file system -
assertFileNotExists
Asserts that a given file is not found in the file system. -
resolveMandatoryEndpoint
public static org.apache.camel.Endpoint resolveMandatoryEndpoint(org.apache.camel.CamelContext context, String endpointUri) 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 endpointUri, Class<T> endpointType) Resolves an endpoint and asserts that it is found. -
createExchangeWithBody
public static org.apache.camel.Exchange createExchangeWithBody(org.apache.camel.CamelContext camelContext, Object body) Creates an exchange with the given body. -
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
-
deleteDirectory
Recursively delete a directory, useful to zapping test data. Deletion will be attempted up to five time before giving up.- Parameters:
file
- the directory to be deleted- Returns:
- false when an error occur while deleting directory
-
deleteDirectory
Recursively delete a directory, useful to zapping test data. Deletion will be attempted up to five time before giving up.- Parameters:
file
- the directory to be deleted- Returns:
- false when an error occur while deleting directory
-
deleteDirectory
Recursively delete a directory, useful to zapping test data. Deletion will be attempted up to five time before giving up.- Parameters:
file
- the directory to be deleted- Returns:
- false when an error occur while deleting directory
-
recursivelyDeleteDirectory
Recursively delete a directory. Deletion will be attempted a single time before giving up.- Parameters:
file
- the directory to be deleted
-
createCleanDirectory
Creates a given directory.- Parameters:
file
- the directory to be created
-
createDirectory
Creates a given directory.- Parameters:
file
- the directory to be created
-
createDirectory
Creates a given directory.- Parameters:
file
- the directory to be created
-
isPlatform
Tells whether the current Operating System is the given expected platform. Uses os.name from the system properties to determine the Operating System.- Parameters:
expectedPlatform
- such as Windows- Returns:
- true when the current Operating System is the expected platform, false otherwise.
-
isJavaVendor
Tells whether the current Java Virtual Machine has been issued by a given expected vendor. Uses java.vendor from the system properties to determine the vendor.- Parameters:
expectedVendor
- such as IBM- Returns:
- true when the current Java Virtual Machine has been issued by the expected vendor, false otherwise.
-
getJavaMajorVersion
public static int getJavaMajorVersion()Returns the current major Java version e.g 8. Uses java.specification.version from the system properties to determine the major version.- Returns:
- the current major Java version.
-
isCamelDebugPresent
public static boolean isCamelDebugPresent()Indicates whether the componentcamel-debug
is present in the classpath of the test.- Returns:
true
if it is present,false
otherwise.
-
fileUri
-
fileUri
-
executeSlowly
public static void executeSlowly(int count, long interval, TimeUnit timeUnit, IntConsumer task) throws Exception - Throws:
Exception
-