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 voidassertDirectoryEquals(String expected, String actual) Asserts that two given directories are equal.static voidassertDirectoryEquals(String message, String expected, String actual) Asserts that two given directories are equal.static voidassertDirectoryExists(String filename) Asserts that a given directory is found in the file system.static voidassertDirectoryExists(Path file) To be used to check is a directory is found in the file systemstatic voidassertEndpointUri(org.apache.camel.Endpoint endpoint, String expectedUri) Asserts that a given endpoint has an expected uri.static ObjectassertExpression(org.apache.camel.Expression expression, org.apache.camel.Exchange exchange, Object expectedAnswer) Asserts that the given expression when evaluated returns the given answer.static voidassertFileExists(String filename) Asserts that a given file is found in the file system.static voidassertFileExists(Path file) To be used to check is a file is found in the file systemstatic voidassertFileExists(Path file, String content) To be used to check is a file is found in the file systemstatic voidassertFileNotExists(String filename) Asserts that a given file is not found in the file system.static voidassertFileNotExists(Path file) To be used to check is a file is not found in the file systemstatic voidassertInMessageBodyEquals(org.apache.camel.Exchange exchange, Object expectedBody) Asserts that the given exchange has a given expectedBody on the IN message.static ObjectassertInMessageHeader(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> TassertIsInstanceOf(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 voidassertMessageBodyEquals(org.apache.camel.Exchange exchange, Object expectedBody) Asserts that the given exchange has a given expectedBody on the message.static ObjectassertMessageHeader(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> TassertOneElement(List<T> list) Asserts that a given list has a single element.static ObjectassertOutMessageHeader(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 booleanassertPredicate(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange, boolean expectedValue) Asserts that the predicate returns the expected value on the exchange.static voidassertPredicateDoesNotMatch(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange) Asserts that a given predicate returnsfalseon a given exchange.static voidassertPredicateMatches(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange) Asserts that a given predicate returnstrueon a given exchange.static voidassertStringContains(String text, String containedText) Asserts that the text contains the given string.static org.apache.camel.builder.ValueBuilderbody()Returns a predicate and value builder for the inbound body on an exchange.static <T> org.apache.camel.builder.ValueBuilderReturns a predicate and value builder for the inbound message body as a specific type.static voidcreateCleanDirectory(Path file) Creates a given directory.static voidcreateDirectory(String file) Creates a given directory.static voidcreateDirectory(Path file) Creates a given directory.static org.apache.camel.ExchangecreateExchangeWithBody(org.apache.camel.CamelContext camelContext, Object body) Creates an exchange with the given body.static booleandeleteDirectory(File file) Recursively delete a directory, useful to zapping test data.static booleandeleteDirectory(String file) Recursively delete a directory, useful to zapping test data.static booleandeleteDirectory(Path file) Recursively delete a directory, useful to zapping test data.static org.apache.camel.builder.ValueBuilderexchangeProperty(String name) Returns a value builder for the given exchange property.static voidexecuteSlowly(int count, long interval, TimeUnit timeUnit, IntConsumer task) static Stringstatic Stringstatic intReturns 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.ValueBuilderReturns a value builder for the given header.static booleanIndicates whether the componentcamel-debugis present in the classpath of the test.static booleanisJavaVendor(String expectedVendor) Tells whether the current Java Virtual Machine has been issued by a given expected vendor.static booleanisPlatform(String expectedPlatform) Tells whether the current Operating System is the given expected platform.static voidRecursively delete a directory.static org.apache.camel.EndpointresolveMandatoryEndpoint(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.ValueBuildersystemProperty(String name) Returns a value builder for the given system property.static org.apache.camel.builder.ValueBuildersystemProperty(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 returnstrueon a given exchange. -
assertPredicateDoesNotMatch
public static void assertPredicateDoesNotMatch(org.apache.camel.Predicate predicate, org.apache.camel.Exchange exchange) Asserts that a given predicate returnsfalseon 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-debugis present in the classpath of the test.- Returns:
trueif it is present,falseotherwise.
-
fileUri
-
fileUri
-
executeSlowly
public static void executeSlowly(int count, long interval, TimeUnit timeUnit, IntConsumer task) throws Exception - Throws:
Exception
-