Working docs
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
=== Stub Runner Spring AMQP
|
||||
|
||||
Spring Cloud Contract Verifier Stub Runner's messaging module provides an easy way to
|
||||
integrate with Spring AMQP's Rabbit Template. For the provided artifacts, it
|
||||
automatically downloads the stubs and registers the required routes.
|
||||
|
||||
The integration tries to work standalone (that is, without interaction with a running
|
||||
RabbitMQ message broker). It expects a `RabbitTemplate` on the application context and
|
||||
uses it as a spring boot test named `@SpyBean`. As a result, it can use the mockito spy
|
||||
functionality to verify and inspect messages sent by the application.
|
||||
|
||||
On the message consumer side, the stub runner considers all `@RabbitListener` annotated
|
||||
endpoints and all `SimpleMessageListenerContainer` objects on the application context.
|
||||
|
||||
As messages are usually sent to exchanges in AMQP, the message contract contains the
|
||||
exchange name as the destination. Message listeners on the other side are bound to
|
||||
queues. Bindings connect an exchange to a queue. If message contracts are triggered, the
|
||||
Spring AMQP stub runner integration looks for bindings on the application context that
|
||||
match this exchange. Then it collects the queues from the Spring exchanges and tries to
|
||||
find message listeners bound to these queues. The message is triggered for all matching
|
||||
message listeners.
|
||||
|
||||
If you need to work with routing keys, it's enough to pass them via the `amqp_receivedRoutingKey`
|
||||
messaging header.
|
||||
|
||||
==== Adding the Runner to the Project
|
||||
|
||||
You can have both Spring AMQP and Spring Cloud Contract Stub Runner on the classpath and
|
||||
set the property `stubrunner.amqp.enabled=true`. Remember to annotate your test class
|
||||
with `@AutoConfigureStubRunner`.
|
||||
|
||||
IMPORTANT: If you already have Stream and Integration on the classpath, you need
|
||||
to disable them explicitly by setting the `stubrunner.stream.enabled=false` and
|
||||
`stubrunner.integration.enabled=false` properties.
|
||||
|
||||
Assume that you have the following Maven repository with a deployed stubs for the
|
||||
`spring-cloud-contract-amqp-test` application.
|
||||
|
||||
[source,bash,indent=0]
|
||||
----
|
||||
└── .m2
|
||||
└── repository
|
||||
└── com
|
||||
└── example
|
||||
└── spring-cloud-contract-amqp-test
|
||||
├── 0.4.0-SNAPSHOT
|
||||
│ ├── spring-cloud-contract-amqp-test-0.4.0-SNAPSHOT.pom
|
||||
│ ├── spring-cloud-contract-amqp-test-0.4.0-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
|
||||
└── contracts
|
||||
└── shouldProduceValidPersonData.groovy
|
||||
----
|
||||
|
||||
Consider the following contract:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/amqp/AmqpStubRunnerSpec.groovy[tags=amqp_contract,indent=0]
|
||||
----
|
||||
|
||||
Now consider the following Spring configuration:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
include::src/test/resources/application.yml[]
|
||||
----
|
||||
|
||||
===== Triggering the message
|
||||
|
||||
To trigger a message using the contract above, use the `StubTrigger` interface as
|
||||
follows:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/amqp/AmqpStubRunnerSpec.groovy[tags=client_trigger,indent=0]
|
||||
----
|
||||
|
||||
The message has a destination of `contract-test.exchange`, so the Spring AMQP stub runner
|
||||
integration looks for bindings related to this exchange.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
include::src/main/java/org/springframework/cloud/contract/stubrunner/messaging/amqp/AmqpMessagingApplication.java[tags=amqp_binding,indent=0]
|
||||
----
|
||||
|
||||
The binding definition binds the queue `test.queue`. As a result, the following listener
|
||||
definition is matched and invoked with the contract message.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
include::src/main/java/org/springframework/cloud/contract/stubrunner/messaging/amqp/AmqpMessagingApplication.java[tags=amqp_listener,indent=0]
|
||||
----
|
||||
|
||||
Also, the following annotated listener matches and is invoked:
|
||||
[source,java]
|
||||
----
|
||||
include::src/main/java/org/springframework/cloud/contract/stubrunner/messaging/amqp/MessageSubscriberRabbitListener.java[tags=amqp_annotated_listener,indent=0]
|
||||
----
|
||||
|
||||
NOTE: The message is directly handed over to the `onMessage` method of the
|
||||
`MessageListener` associated with the matching `SimpleMessageListenerContainer`.
|
||||
|
||||
===== Spring AMQP Test Configuration
|
||||
|
||||
In order to avoid Spring AMQP trying to connect to a running broker during our tests
|
||||
configure a mock `ConnectionFactory`.
|
||||
|
||||
To disable the mocked ConnectionFactory, set the following property:
|
||||
`stubrunner.amqp.mockConnection=false`
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
stubrunner:
|
||||
amqp:
|
||||
mockConnection: false
|
||||
----
|
||||
@@ -1,123 +0,0 @@
|
||||
: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 will automatically download the stubs and register the required
|
||||
routes.
|
||||
|
||||
==== Adding it to the project
|
||||
|
||||
It's enough to have both Apache Camel and Spring Cloud Contract Stub Runner on classpath.
|
||||
Remember to annotate your test class with `@AutoConfigureStubRunner`.
|
||||
|
||||
==== Disabling the functionality
|
||||
|
||||
If you need to disable this functionality just pass `stubrunner.camel.enabled=false` property.
|
||||
|
||||
==== Examples
|
||||
|
||||
===== Stubs structure
|
||||
|
||||
Let us assume that we have the following Maven repository with a 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
|
||||
----
|
||||
|
||||
And the stubs contain the following structure:
|
||||
|
||||
[source,bash,indent=0]
|
||||
----
|
||||
├── META-INF
|
||||
│ └── MANIFEST.MF
|
||||
└── repository
|
||||
├── accurest
|
||||
│ ├── bookDeleted.groovy
|
||||
│ ├── bookReturned1.groovy
|
||||
│ └── bookReturned2.groovy
|
||||
└── mappings
|
||||
----
|
||||
|
||||
Let's consider the following contracts (let' number it with *1*):
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl,indent=0]
|
||||
----
|
||||
|
||||
and number *2*
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0]
|
||||
----
|
||||
|
||||
===== Scenario 1 (no input message)
|
||||
|
||||
So as to trigger a message via the `return_book_1` label we'll 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]
|
||||
----
|
||||
|
||||
Next we'll want 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]
|
||||
----
|
||||
|
||||
And the received message would pass the following assertions
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_trigger_message,indent=0]
|
||||
----
|
||||
|
||||
===== Scenario 2 (output triggered by input)
|
||||
|
||||
Since the route is set for you it's enough to just 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]
|
||||
----
|
||||
|
||||
Next we'll want 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_receive,indent=0]
|
||||
----
|
||||
|
||||
And the received message would pass the following assertions
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/camel/CamelStubRunnerSpec.groovy[tags=client_receive_message,indent=0]
|
||||
----
|
||||
|
||||
===== Scenario 3 (input with no output)
|
||||
|
||||
Since the route is set for you it's enough to just 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]
|
||||
----
|
||||
@@ -1,138 +0,0 @@
|
||||
:input_name: input
|
||||
:output_name: output
|
||||
|
||||
=== Stub Runner Integration
|
||||
|
||||
Spring Cloud Contract Verifier Stub Runner's messaging module gives you an easy way to
|
||||
integrate with Spring Integration. For the provided artifacts, it automatically downloads
|
||||
the stubs and registers the required routes.
|
||||
|
||||
==== Adding the Runner to the Project
|
||||
|
||||
You can have both Spring Integration 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.integration.enabled=false` property.
|
||||
|
||||
Assume that you have the following Maven repository with deployed stubs for the
|
||||
`integrationService` application:
|
||||
|
||||
[source,bash,indent=0]
|
||||
----
|
||||
└── .m2
|
||||
└── repository
|
||||
└── io
|
||||
└── codearte
|
||||
└── accurest
|
||||
└── stubs
|
||||
└── integrationService
|
||||
├── 0.0.1-SNAPSHOT
|
||||
│ ├── integrationService-0.0.1-SNAPSHOT.pom
|
||||
│ ├── integrationService-0.0.1-SNAPSHOT-stubs.jar
|
||||
│ └── maven-metadata-local.xml
|
||||
└── maven-metadata-local.xml
|
||||
----
|
||||
|
||||
Further assume 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/integration/IntegrationStubRunnerSpec.groovy[tags=sample_dsl,indent=0]
|
||||
----
|
||||
|
||||
Now consider *2*:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0]
|
||||
----
|
||||
|
||||
and the following Spring Integration Route:
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
include::src/test/resources/integration-context.xml[lines=1;18..-1]
|
||||
----
|
||||
|
||||
These examples lend themselves to three scenarios:
|
||||
|
||||
* <<integration-scenario-1>>
|
||||
* <<integration-scenario-2>>
|
||||
* <<integration-scenario-3>>
|
||||
|
||||
[[integration-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/integration/IntegrationStubRunnerSpec.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/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0]
|
||||
----
|
||||
|
||||
The received message would pass the following assertions:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger_message,indent=0]
|
||||
----
|
||||
|
||||
[[integration-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/integration/IntegrationStubRunnerSpec.groovy[tags=client_send,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/integration/IntegrationStubRunnerSpec.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/integration/IntegrationStubRunnerSpec.groovy[tags=client_receive_message,indent=0]
|
||||
----
|
||||
|
||||
[[integration-scenario-3]]
|
||||
===== Scenario 3 (input with no output)
|
||||
|
||||
Since the route is set for you, you can send a message to the `{input_name}` destination:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=trigger_no_output,indent=0]
|
||||
----
|
||||
@@ -1,160 +0,0 @@
|
||||
=== Stub Runner Stream
|
||||
|
||||
Spring Cloud Contract Verifier Stub Runner's messaging module gives you an easy way to
|
||||
integrate with Spring Stream. For the provided artifacts, it automatically downloads the
|
||||
stubs and registers the required routes.
|
||||
|
||||
WARNING: If Stub Runner's integration with Stream the `messageFrom` or `sentTo` Strings
|
||||
are resolved first as a `destination` of a channel and no such `destination` exists, the
|
||||
destination is resolved as a channel name.
|
||||
|
||||
IMPORTANT: If you want to use Spring Cloud Stream remember, to add a dependency on
|
||||
`org.springframework.cloud:spring-cloud-stream-test-support`.
|
||||
|
||||
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
|
||||
.Maven
|
||||
----
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes",role="secondary"]
|
||||
.Gradle
|
||||
----
|
||||
testCompile "org.springframework.cloud:spring-cloud-stream-test-support"
|
||||
----
|
||||
|
||||
==== Adding the Runner to the Project
|
||||
|
||||
You can have both Spring Cloud Stream 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.stream.enabled=false`
|
||||
property.
|
||||
|
||||
Assume that you have the following Maven repository with a deployed stubs for the
|
||||
`streamService` application:
|
||||
|
||||
[source,bash,indent=0]
|
||||
----
|
||||
└── .m2
|
||||
└── repository
|
||||
└── io
|
||||
└── codearte
|
||||
└── accurest
|
||||
└── stubs
|
||||
└── streamService
|
||||
├── 0.0.1-SNAPSHOT
|
||||
│ ├── streamService-0.0.1-SNAPSHOT.pom
|
||||
│ ├── streamService-0.0.1-SNAPSHOT-stubs.jar
|
||||
│ └── maven-metadata-local.xml
|
||||
└── maven-metadata-local.xml
|
||||
----
|
||||
|
||||
Further assume 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/stream/StreamStubRunnerSpec.groovy[tags=sample_dsl,indent=0]
|
||||
----
|
||||
|
||||
Now consider *2*:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=sample_dsl_2,indent=0]
|
||||
----
|
||||
|
||||
Now consider the following Spring configuration:
|
||||
|
||||
[source,yaml]
|
||||
----
|
||||
include::src/test/resources/application.yml[]
|
||||
----
|
||||
|
||||
These examples lend themselves to three scenarios:
|
||||
|
||||
* <<stream-scenario-1>>
|
||||
* <<stream-scenario-2>>
|
||||
* <<stream-scenario-3>>
|
||||
|
||||
[[stream-scenario-1]]
|
||||
===== Scenario 1 (no input message)
|
||||
|
||||
To trigger a message via the `return_book_1` label, use the `StubTrigger` interface as
|
||||
follows:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger,indent=0]
|
||||
----
|
||||
|
||||
To listen to the output of the message sent to a channel whose `destination` is
|
||||
`returnBook`:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.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/stream/StreamStubRunnerSpec.groovy[tags=client_trigger_message,indent=0]
|
||||
----
|
||||
|
||||
[[stream-scenario-2]]
|
||||
===== Scenario 2 (output triggered by input)
|
||||
|
||||
Since the route is set for you, you can send a message to the `bookStorage`
|
||||
`destination`:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_send,indent=0]
|
||||
----
|
||||
|
||||
To listen to the output of the message sent to `returnBook`:
|
||||
|
||||
[source,groovy]
|
||||
----
|
||||
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/messaging/stream/StreamStubRunnerSpec.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/stream/StreamStubRunnerSpec.groovy[tags=client_receive_message,indent=0]
|
||||
----
|
||||
|
||||
[[stream-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/stream/StreamStubRunnerSpec.groovy[tags=trigger_no_output,indent=0]
|
||||
----
|
||||
Reference in New Issue
Block a user