blob: 4cf424a308125942113073969035939b7c96e1b8 [file] [log] [blame]
== Testing Example - CDI
=== Introduction
This example demonstrates the testing features that are provided as part
of the integration between Camel and CDI.
The example is implemented in Java with CDI dependency injection. It
uses JBoss Weld as the minimal CDI container to run the application,
though you can run the application in any CDI compliant container.
This example comes with a series of test classes that each demonstrates
particular features provided by the `+camel-test-cdi-junit5+` module:
[width="100%",cols="33%,67%",options="header",]
|===
|Test class |Description
|link:src/test/java/org/apache/camel/example/cdi/test/AlternativeTest.java[`+AlternativeTest+`]
|Mocks a bean used in a Camel route with a CDI alternative
|link:src/test/java/org/apache/camel/example/cdi/test/ApplicationScopedTest.java[`+ApplicationScopedTest+`]
|A stateful `+@ApplicationScoped+` test class
|link:src/test/java/org/apache/camel/example/cdi/test/CustomContextTest.java[`+CustomContextTest+`]
|Declares a custom Camel context bean for testing purpose
|link:src/test/java/org/apache/camel/example/cdi/test/OrderTest.java[`+OrderTest+`]
|Orders the test methods' execution with `+@Order+`. Note that in this test, an old JUnit 4 Rule of type Verifier is used such that `junit-jupiter-migrationsupport` needs to be explicitly added to the test dependencies of the project, see https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4-rule-support[Limited JUnit 4 Rule Support] for more details.
|link:src/test/java/org/apache/camel/example/cdi/test/AdviceTest.java[`+AdviceTest+`]
|Simple example that shows how to advice a route
|===
=== Build
You can build this example using:
[source,sh]
----
$ mvn install
----
=== Run
You can run this example using:
[source,sh]
----
$ mvn camel:run
----
When the Camel application runs, you should see the following message
being logged to the console, e.g.:
....
2016-03-04 17:54:04,147 [cdi.Main.main()] INFO route - Hello from camel-1
....
The Camel application can be stopped pressing ctrl+c in the shell.
You should see the following message being logged to the console:
....
2016-03-04 17:54:18,725 [Thread-1 ] INFO route - Bye from camel-1
....
NOTE: The name `camel-1` is automatically generated by the default name strategy.
In case, a custom Camel context is defined like in the example link:src/test/java/org/apache/camel/example/cdi/test/CustomContextTest.java[`+CustomContextTest+`],
the value of the annotation `@Named` is used instead as name of the Camel context.
=== Run unit tests
There are unit tests implemented, which can be run with the following command:
[source,sh]
----
$ mvn test
----
=== Help and contributions
If you hit any problem using Camel or have some feedback, then please
https://camel.apache.org/community/support/[let us know].
We also love contributors, so
https://camel.apache.org/community/contributing/[get involved] :-)
The Camel riders!