Package org.apache.camel.test.junit5
Class TestSupport
- java.lang.Object
-
- org.apache.camel.test.junit5.TestSupport
-
public final class TestSupport extends Object
Provides utility methods for camel test purpose (builders, assertions, endpoint resolutions, file helpers).
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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.ValueBuilderbodyAs(Class<T> type)Returns 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 StringfileUri(Path testDirectory)static StringfileUri(Path testDirectory, String query)static intgetJavaMajorVersion()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.ValueBuilderheader(String name)Returns a value builder for the given header.static booleanisCamelDebugPresent()Indicates whether the componentcamel-debugis present in the classpath of the test.static booleanisJava18()Tells whether the current Java version is 1.8.static booleanisJava19()Tells whether the current Java version is 1.9.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 voidrecursivelyDeleteDirectory(File file)Recursively 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 Detail
-
header
public static org.apache.camel.builder.ValueBuilder header(String name)
Returns a value builder for the given header.
-
exchangeProperty
public static org.apache.camel.builder.ValueBuilder exchangeProperty(String name)
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
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.
-
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)
Asserts that a given value is of an expected type.
-
assertEndpointUri
public static void assertEndpointUri(org.apache.camel.Endpoint endpoint, String expectedUri)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.InvalidPayloadExceptionAsserts 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.InvalidPayloadExceptionAsserts 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
public static <T> T assertOneElement(List<T> list)
Asserts that a given list has a single element.
-
assertListSize
public static <T> List<T> assertListSize(List<T> list, int expectedSize)
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
public static <T> Collection<T> assertCollectionSize(Collection<T> list, int expectedSize)
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
public static void assertStringContains(String text, String containedText)
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
public static void assertDirectoryEquals(String expected, String actual)
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
public static void assertDirectoryEquals(String message, String expected, String actual)
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
public static void assertDirectoryExists(Path file)
To be used to check is a directory is found in the file system
-
assertDirectoryExists
public static void assertDirectoryExists(String filename)
Asserts that a given directory is found in the file system.
-
assertFileExists
public static void assertFileExists(Path file)
To be used to check is a file is found in the file system
-
assertFileExists
public static void assertFileExists(Path file, String content) throws IOException
To be used to check is a file is found in the file system- Throws:
IOException
-
assertFileExists
public static void assertFileExists(String filename)
Asserts that a given file is found in the file system.
-
assertFileNotExists
public static void assertFileNotExists(Path file)
To be used to check is a file is not found in the file system
-
assertFileNotExists
public static void assertFileNotExists(String filename)
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
public static boolean deleteDirectory(Path file)
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
public static boolean deleteDirectory(String file)
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
public static boolean deleteDirectory(File file)
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
public static void recursivelyDeleteDirectory(File file)
Recursively delete a directory. Deletion will be attempted a single time before giving up.- Parameters:
file- the directory to be deleted
-
createCleanDirectory
public static void createCleanDirectory(Path file)
Creates a given directory.- Parameters:
file- the directory to be created
-
createDirectory
public static void createDirectory(Path file)
Creates a given directory.- Parameters:
file- the directory to be created
-
createDirectory
public static void createDirectory(String file)
Creates a given directory.- Parameters:
file- the directory to be created
-
isPlatform
public static boolean isPlatform(String expectedPlatform)
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
public static boolean isJavaVendor(String expectedVendor)
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.
-
isJava18
public static boolean isJava18()
Tells whether the current Java version is 1.8.- Returns:
- true if its Java 1.8, false if its not (for example Java 1.7 or older)
-
isJava19
public static boolean isJava19()
Tells whether the current Java version is 1.9.- Returns:
- true if its Java 1.9, false if its not (for example Java 1.8 or older)
-
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.
-
-