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 voidassertExpression(org.apache.camel.CamelContext context, org.apache.camel.Exchange exchange, String languageName, String expressionText, Object expectedValue) Asserts that the given language name and expression evaluates to the given value on a specific exchangestatic 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 voidassertPredicate(org.apache.camel.CamelContext context, String languageName, String expressionText, org.apache.camel.Exchange exchange, boolean expected) Asserts that the given language name and predicate expression evaluates to the expected value on the message exchangestatic 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 org.apache.camel.spi.LanguageassertResolveLanguage(org.apache.camel.CamelContext context, String languageName) Deprecated.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 org.apache.camel.EndpointgetMandatoryEndpoint(org.apache.camel.CamelContext context, String uri) static <T extends org.apache.camel.Endpoint>
TgetMandatoryEndpoint(org.apache.camel.CamelContext context, String uri, Class<T> type) static org.apache.camel.component.mock.MockEndpointgetMockEndpoint(org.apache.camel.CamelContext context, String uri, boolean create) Resolves theMockEndpointusing a URI of the formmock:someName, optionally creating it if it does not exist.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 PropertiesloadExternalProperties(Class<?> clazz, String path) static PropertiesloadExternalProperties(ClassLoader loader, String path) static PropertiesloadExternalProperties(Properties properties, Class<?> clazz, String path) static PropertiesloadExternalProperties(Properties properties, ClassLoader loader, String path) static PropertiesloadExternalPropertiesQuietly(Class<?> clazz, String path) static PropertiesloadExternalPropertiesQuietly(ClassLoader loader, String path) static PropertiesloadExternalPropertiesQuietly(Properties properties, Class<?> clazz, String path) static PropertiesloadExternalPropertiesQuietly(Properties properties, ClassLoader loader, String path) 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 voidsendBodies(org.apache.camel.ProducerTemplate template, String endpointUri, Object... bodies) Sends a message to the given endpoint URI with the body valuestatic voidSends a message to the given endpoint URI with the body valuestatic voidsendBody(org.apache.camel.ProducerTemplate template, String endpointUri, Object body, Map<String, Object> headers) 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. -
assertExpression
public static void assertExpression(org.apache.camel.CamelContext context, org.apache.camel.Exchange exchange, String languageName, String expressionText, Object expectedValue) Asserts that the given language name and expression evaluates to the given value on a specific 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. -
assertResolveLanguage
@Deprecated(since="4.7.0") public static org.apache.camel.spi.Language assertResolveLanguage(org.apache.camel.CamelContext context, String languageName) Deprecated.Asserts that the language name can be resolved -
assertPredicate
public static void assertPredicate(org.apache.camel.CamelContext context, String languageName, String expressionText, org.apache.camel.Exchange exchange, boolean expected) Asserts that the given language name and predicate expression evaluates to the expected value on the message exchange -
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
-
getMandatoryEndpoint
-
getMandatoryEndpoint
public static org.apache.camel.Endpoint getMandatoryEndpoint(org.apache.camel.CamelContext context, String uri) -
sendBody
-
sendBody
public static void sendBody(org.apache.camel.ProducerTemplate template, String endpointUri, Object body) Sends a message to the given endpoint URI with the body value- Parameters:
endpointUri- the URI of the endpoint to send tobody- the body for the message
-
sendBodies
public static void sendBodies(org.apache.camel.ProducerTemplate template, String endpointUri, Object... bodies) Sends a message to the given endpoint URI with the body value- Parameters:
template- the producer template to use to send the messagesendpointUri- the URI of the endpoint to send tobodies- the bodies for the message
-
getMockEndpoint
public static org.apache.camel.component.mock.MockEndpoint getMockEndpoint(org.apache.camel.CamelContext context, String uri, boolean create) throws org.apache.camel.NoSuchEndpointException Resolves theMockEndpointusing a URI of the formmock:someName, optionally creating it if it does not exist. This implementation will lookup existing mock endpoints and match on the mock queue name, eg mock:foo and mock:foo?retainFirst=5 would match as the queue name is foo.- Parameters:
uri- the URI which typically starts with "mock:" and has some namecreate- whether to allow the endpoint to be created if it doesn't exist- Returns:
- the mock endpoint or an
NoSuchEndpointExceptionis thrown if it could not be resolved - Throws:
org.apache.camel.NoSuchEndpointException- is the mock endpoint does not exist
-
loadExternalPropertiesQuietly
-
loadExternalPropertiesQuietly
-
loadExternalPropertiesQuietly
public static Properties loadExternalPropertiesQuietly(Properties properties, Class<?> clazz, String path) -
loadExternalPropertiesQuietly
public static Properties loadExternalPropertiesQuietly(Properties properties, ClassLoader loader, String path) -
loadExternalProperties
- Throws:
IOException
-
loadExternalProperties
- Throws:
IOException
-
loadExternalProperties
public static Properties loadExternalProperties(Properties properties, Class<?> clazz, String path) throws IOException - Throws:
IOException
-
loadExternalProperties
public static Properties loadExternalProperties(Properties properties, ClassLoader loader, String path) throws IOException - Throws:
IOException
-