forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document how to use mock in JVM mode tests apache#1449
- Loading branch information
1 parent
2f6c58e
commit 52106d3
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Injection of CDI beans (described in Usage) does not work in native mode. | ||
|
||
In the native mode the test and the application under test are running in two different processes and it is not possible | ||
to share a mock bean between them (see https://quarkus.io/guides/getting-started-testing#native-executable-testing[Quarkus documentation]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
To use camel-mock capabilities in tests it is required to get access to MockEndpoint instances. | ||
|
||
CDI injection could be used for accessing instances (see https://quarkus.io/guides/getting-started-testing#injection-into-tests[Quarkus documentation]). | ||
You can inject camelContext into test using `@Inject` annotation. Camel context can be then used for obtaining mock endpoints. | ||
See the following example: | ||
|
||
---- | ||
import javax.inject.Inject; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.junit.jupiter.api.Test; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
@QuarkusTest | ||
public class MockJvmTest { | ||
@Inject | ||
CamelContext camelContext; | ||
@Inject | ||
ProducerTemplate producerTemplate; | ||
@Test | ||
public void test() throws InterruptedException { | ||
producerTemplate.sendBody("direct:start", "Hello World"); | ||
MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:result", MockEndpoint.class); | ||
mockEndpoint.expectedBodiesReceived("Hello World"); | ||
mockEndpoint.assertIsSatisfied(); | ||
} | ||
} | ||
---- | ||
Route used for the example test: | ||
---- | ||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
|
||
@ApplicationScoped | ||
public class MockRoute extends RouteBuilder { | ||
|
||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start").to("mock:result"); | ||
} | ||
} | ||
---- |