Annotation Type CamelMainTest
-
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited @ExtendWith(org.apache.camel.test.main.junit5.CamelMainExtension.class) public @interface CamelMainTest
@CamelMainTest
is an annotation allowing to mark a test class as a test of a Camel Main application. A specific Camel context is created, initialized and started under the same conditions as a Camel Main application. The annotation can be inherited from a parent class. In the next example, the annotationCamelMainTest
on the test classSomeTest
indicates that the main class of the Camel Main application to simulate isSomeMainClass
and has one additional configuration class to consider which isSomeConfiguration
.@CamelMainTest(mainClass = SomeMainClass.class, configurationClasses = SomeConfiguration.class) class SomeTest { // The rest of the test class }
- See Also:
AdviceRouteMapping
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description AdviceRouteMapping[]
advices
Gives the mappings between the routes to advice and the corresponding route builders to call to advice the routes.Class<? extends org.apache.camel.CamelConfiguration>[]
configurationClasses
Gives the additional camel configuration classes to add to the global configuration.boolean
dumpRouteCoverage
Whether to dump route coverage stats at the end of the test.Class<?>
mainClass
Allows to specify the main class of the application to test if needed in order to simulate the same behavior as withMain(Class)
.String
mockEndpoints
Enable auto mocking endpoints based on the pattern.String
mockEndpointsAndSkip
Enable auto mocking endpoints based on the pattern, and skip sending to original endpoint.String[]
properties
Gives the list of properties to override with the CamelPropertiesComponent
.String
propertyPlaceholderFileName
Gives the file name of the property placeholder to use for the test.String[]
propertyPlaceholderLocations
Gives the property placeholder locations to use for the test.String[]
replaceRouteFromWith
Gives the identifier of routes to advice by replacing their from endpoint with the corresponding URI.int
shutdownTimeout
Returns the timeout to use when shutting down (unit in seconds).boolean
useJmx
Whether JMX should be used during testing.
-
-
-
Element Detail
-
mainClass
Class<?> mainClass
Allows to specify the main class of the application to test if needed in order to simulate the same behavior as withMain(Class)
. Note: This attribute can be set from a@Nested
test classes. The value of this attribute set on the innermost class is used.- Returns:
- the main class of the application to test if any.
void.class
by default indicating that there is no specific main class.
- Default:
- void.class
-
-
-
properties
String[] properties
Gives the list of properties to override with the CamelPropertiesComponent
. In the next example, the annotationCamelMainTest
on the test classSomeTest
indicates the existing value of the propertyhost
is replaced withlocalhost
and the existing value of the propertyport
is replaced with8080
.@CamelMainTest(properties = { "host=localhost", "port=8080" }) class SomeTest { // The rest of the test class }
@Nested
test classes. The values of this attribute are added to the values of the outer classes, knowing that the values are ordered from outermost to innermost.- Returns:
- an array of
String
in the following format"property-key-1=property-value-1", "property-key-2=property-value-2", ...
- Default:
- {}
-
-
-
replaceRouteFromWith
String[] replaceRouteFromWith
Gives the identifier of routes to advice by replacing their from endpoint with the corresponding URI. In the next example, the annotationCamelMainTest
on the test classSomeTest
indicates the value of the route whose identifiermain-route
is advised to replace its current from endpoint with adirect:main
endpoint.@CamelMainTest(replaceRouteFromWith = { "main-route=direct:main" }) class SomeTest { // The rest of the test class }
@Nested
test classes. The values of this attribute are added to the values of the outer classes, knowing that the values are ordered from outermost to innermost.- Returns:
- an array of
String
in the following format"route-id-1=new-uri-1", "route-id-2=new-uri-2", ...
- Default:
- {}
-
-
-
propertyPlaceholderFileName
String propertyPlaceholderFileName
Gives the file name of the property placeholder to use for the test. This method assumes that the file is located either in the package of the test class or directly in the default package. In other words, if the test class iscom.company.SomeTest
and this method has been overridden to returnsome-app.properties
, then it assumes that the actual possible locations of the property placeholder areclasspath:com/company/some-app.properties;optional=true,classpath:some-app.properties;optional=true
which means that for each property to find, it tries to get it first from the properties file of the same package if it exists and if it cannot be found, it tries to get it from the properties file with the same name but in the default package if it exists.Note: Since the properties files are declared as optional, no exception is raised if they are both absent. Note: If
Note: This attribute can be set from apropertyPlaceholderLocations()
is set, the value of this attribute is ignored.@Nested
test classes. The value of this attribute set on the innermost class is used.- Returns:
- the file name of the property placeholder located in the same package as the test class or directly in the default package. Not set by default.
- Default:
- ""
-
-
-
propertyPlaceholderLocations
String[] propertyPlaceholderLocations
Gives the property placeholder locations to use for the test. In case a property is defined at several property placeholder locations, the value of this property in the first property placeholder location according to the order in the list is used. In other words, the value of the properties defined in the first location of the property placeholder in the list takes precedence over the value of the properties of the following location of the property placeholder and so on.Note: If this attribute is set, the value of
Note: This attribute can be set from apropertyPlaceholderFileName()
is ignored.@Nested
test classes. The value of this attribute set on the innermost class is used.- Returns:
- the property placeholder locations to use for the test.
- Default:
- {}
-
-
-
configurationClasses
Class<? extends org.apache.camel.CamelConfiguration>[] configurationClasses
Gives the additional camel configuration classes to add to the global configuration. Note: This attribute can be set from a@Nested
test classes. The values of this attribute are added to the values of the outer classes, knowing that the values are ordered from outermost to innermost.- Returns:
- an array of camel configuration classes.
- Default:
- {}
-
-
-
advices
AdviceRouteMapping[] advices
Gives the mappings between the routes to advice and the corresponding route builders to call to advice the routes. Note: This attribute can be set from a@Nested
test classes. The values of this attribute are added to the values of the outer classes, knowing that the values are ordered from outermost to innermost.- Returns:
- an array of mapping between route and route builder
- Default:
- {}
-
-
-
mockEndpoints
String mockEndpoints
Enable auto mocking endpoints based on the pattern. Return * to mock all endpoints. Note: This attribute can be set from a@Nested
test classes. The value of this attribute set on the innermost class is used.- See Also:
EndpointHelper.matchEndpoint(CamelContext, String, String)
- Default:
- ""
-
-
-
mockEndpointsAndSkip
String mockEndpointsAndSkip
Enable auto mocking endpoints based on the pattern, and skip sending to original endpoint. Return * to mock all endpoints. Note: This attribute can be set from a@Nested
test classes. The value of this attribute set on the innermost class is used.- See Also:
EndpointHelper.matchEndpoint(CamelContext, String, String)
- Default:
- ""
-
-
-
dumpRouteCoverage
boolean dumpRouteCoverage
Whether to dump route coverage stats at the end of the test. This allows tooling or manual inspection of the stats, so you can generate a route trace diagram of which EIPs have been in use and which have not. Similar concepts as a code coverage report. You can also turn on route coverage globally via setting JVM system property CamelTestRouteCoverage=true. Note: This attribute can only be set on the outer class, values set on a@Nested
test classes are ignored.- Returns:
- true to write route coverage status in a xml file in the target/camel-route-coverage directory after the test has finished.
- Default:
- false
-
-