133 lines
4.0 KiB
Plaintext
133 lines
4.0 KiB
Plaintext
:input_name: jms:input
|
|
:output_name: jms:output
|
|
|
|
=== Stub Runner Camel
|
|
|
|
Spring Cloud Contract Verifier Stub Runner's messaging module gives you an easy way to
|
|
integrate with Apache Camel. For the provided artifacts, it automatically downloads the
|
|
stubs and registers the required routes.
|
|
|
|
==== Adding the Runner to the Project
|
|
|
|
You can have both Apache Camel and Spring Cloud Contract Stub Runner on the classpath.
|
|
Remember to annotate your test class with `@AutoConfigureStubRunner`.
|
|
|
|
==== Disabling the functionality
|
|
|
|
If you need to disable this functionality, set the `stubrunner.camel.enabled=false`
|
|
property.
|
|
|
|
Assume that you have the following Maven repository with deployed stubs for the
|
|
`camelService` application:
|
|
|
|
[source,bash,indent=0]
|
|
----
|
|
└── .m2
|
|
└── repository
|
|
└── io
|
|
└── codearte
|
|
└── accurest
|
|
└── stubs
|
|
└── camelService
|
|
├── 0.0.1-SNAPSHOT
|
|
│ ├── camelService-0.0.1-SNAPSHOT.pom
|
|
│ ├── camelService-0.0.1-SNAPSHOT-stubs.jar
|
|
│ └── maven-metadata-local.xml
|
|
└── maven-metadata-local.xml
|
|
----
|
|
|
|
Further assume that the stubs contain the following structure:
|
|
|
|
[source,bash,indent=0]
|
|
----
|
|
├── META-INF
|
|
│ └── MANIFEST.MF
|
|
└── repository
|
|
├── accurest
|
|
│ ├── bookDeleted.groovy
|
|
│ ├── bookReturned1.groovy
|
|
│ └── bookReturned2.groovy
|
|
└── mappings
|
|
----
|
|
|
|
Consider the following contracts (numbered *1*):
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl,indent=0]
|
|
----
|
|
|
|
Now consider *2*
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0]
|
|
----
|
|
|
|
These examples lend themselves to three scenarios:
|
|
|
|
* <<camel-scenario-1>>
|
|
* <<camel-scenario-2>>
|
|
* <<camel-scenario-3>>
|
|
|
|
[[camel-scenario-1]]
|
|
===== Scenario 1 (no input message)
|
|
|
|
To trigger a message via the `return_book_1` label, use the `StubTigger` interface, as
|
|
follows:
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger,indent=0]
|
|
----
|
|
|
|
To listen to the output of the message sent to `{output_name}`:
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0]
|
|
----
|
|
|
|
The received message passes the following assertions:
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger_message,indent=0]
|
|
----
|
|
|
|
[[camel-scenario-2]]
|
|
===== Scenario 2 (output triggered by input)
|
|
|
|
Since the route is set for you, you can send a message to the `{output_name}`
|
|
destination:
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_send,indent=0]
|
|
----
|
|
|
|
You can listen to the output of the message sent to `{output_name}`:
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive,indent=0]
|
|
----
|
|
|
|
The received message passes the following assertions:
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive_message,indent=0]
|
|
----
|
|
|
|
[[camel-scenario-3]]
|
|
===== Scenario 3 (input with no output)
|
|
|
|
Since the route is set for you, you can send a message to the `{output_name}`
|
|
destination:
|
|
|
|
[source,groovy]
|
|
----
|
|
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=trigger_no_output,indent=0]
|
|
----
|