Added Integration and Stream docs

This commit is contained in:
Marcin Grzejszczak
2016-04-24 08:58:20 +02:00
parent b11e8905f8
commit a46391ee38
7 changed files with 437 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ The `accurest-messaging-core` module contains 3 main interfaces:
- AccurestMessage - describes a message received / sent to a channel / queue / topic etc.
- AccurestMessageBuilder - describes how to build a message
- AccurestMessaging - class that allows you to build, send and receive messages
- AccurestFilter - interface to filter out the messages that do not follow the pattern from the DSL
In the generated test the `AccurestMessaging` is injected via `@Inject` annotation thus you can use other injection
frameworks than Spring.

View File

@@ -50,4 +50,8 @@ include::../../../../stub-runner/stub-runner/src/main/groovy/io/codearte/accures
For convenience the `StubFinder` interface extends `StubTrigger` so it's enough to use only one in your tests.
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/README.adoc[]
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-camel/README.adoc[]
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-integration/README.adoc[]
include::../../../../stub-runner/stub-runner-messaging/stub-runner-messaging-stream/README.adoc[]

View File

@@ -7,6 +7,15 @@ Accurest Stub Runner's messaging module gives you an easy way to integrate with
For the provided artifacts it will automatically download the stubs and register the required
routes.
==== Adding it to the project
To use it you have to add the following dependency to your project (example for Gradle):
[source,groovy,indent=0]
----
testCompile "io.codearte.accurest:stub-runner-messaging-camel:${accurestVersion}"
----
==== Examples
===== Stubs structure

View File

@@ -0,0 +1,154 @@
:input_name: input
:output_name: output
=== Stub Runner Messaging Integration
Accurest Stub Runner's messaging module gives you an easy way to integrate with Spring Integration.
For the provided artifacts it will automatically download the stubs and register the required
routes.
==== Adding it to the project
To use it you have to add the following dependency to your project (example for Gradle):
[source,groovy,indent=0]
----
testCompile "io.codearte.accurest:stub-runner-messaging-integration:${accurestVersion}"
----
==== Examples
===== Stubs structure
Let us assume that we have the following Maven repository with a 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
----
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/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=sample_dsl,indent=0]
----
and number *2*
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/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[]
----
===== Scenario 1 (no input message)
So as to trigger a message via the `return_book_1` label we'll use the `StubTiggerer` interface as follows
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.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/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0]
----
And the received message would pass the following assertions
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.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/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.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/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_receive,indent=0]
----
And the received message would pass the following assertions
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_receive_message,indent=0]
----
===== Custom triggers
`StubTrigger` gives you the following options to trigger a message:
===== Trigger by label
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=client_trigger,indent=0]
----
===== Trigger by group and artifact ids
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=trigger_group_artifact,indent=0]
----
===== Trigger by artifact ids
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=trigger_artifact,indent=0]
----
===== Trigger all messages
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/integration/IntegrationStubRunnerSpec.groovy[tags=trigger_all,indent=0]
----

View File

@@ -2,6 +2,7 @@ package io.codearte.accurest.stubrunner.messaging.integration
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import io.codearte.accurest.dsl.GroovyDsl
import io.codearte.accurest.messaging.AccurestMessage
import io.codearte.accurest.messaging.AccurestMessaging
import io.codearte.accurest.stubrunner.StubFinder
@@ -31,29 +32,43 @@ class IntegrationStubRunnerSpec extends Specification {
def 'should download the stub and register a route for it'() {
when:
// tag::client_send[]
messaging.send(new BookReturned('foo'), [sample: 'header'], 'input')
// end::client_send[]
then:
// tag::client_receive[]
AccurestMessage receivedMessage = messaging.receiveMessage('outputTest')
// end::client_receive[]
and:
// tag::client_receive_message[]
receivedMessage != null
assertJsons(receivedMessage.payload)
receivedMessage.headers.get('BOOK-NAME') == 'foo'
// end::client_receive_message[]
}
def 'should trigger a message by label'() {
when:
// tag::client_trigger[]
stubFinder.trigger('return_book_1')
// end::client_trigger[]
then:
// tag::client_trigger_receive[]
AccurestMessage receivedMessage = messaging.receiveMessage('outputTest')
// end::client_trigger_receive[]
and:
// tag::client_trigger_message[]
receivedMessage != null
assertJsons(receivedMessage.payload)
receivedMessage.headers.get('BOOK-NAME') == 'foo'
// end::client_trigger_message[]
}
def 'should trigger a label for the existing groupId:artifactId'() {
when:
// tag::trigger_group_artifact[]
stubFinder.trigger('io.codearte.accurest.stubs:integrationService', 'return_book_1')
// end::trigger_group_artifact[]
then:
AccurestMessage receivedMessage = messaging.receiveMessage('outputTest')
and:
@@ -64,7 +79,9 @@ class IntegrationStubRunnerSpec extends Specification {
def 'should trigger a label for the existing artifactId'() {
when:
// tag::trigger_artifact[]
stubFinder.trigger('integrationService', 'return_book_1')
// end::trigger_artifact[]
then:
AccurestMessage receivedMessage = messaging.receiveMessage('outputTest')
and:
@@ -95,7 +112,9 @@ class IntegrationStubRunnerSpec extends Specification {
def 'should trigger messages by running all triggers'() {
when:
// tag::trigger_all[]
stubFinder.trigger()
// end::trigger_all[]
then:
AccurestMessage receivedMessage = messaging.receiveMessage('outputTest')
and:
@@ -111,4 +130,46 @@ class IntegrationStubRunnerSpec extends Specification {
return json.bookName == 'foo'
}
GroovyDsl dsl =
// tag::sample_dsl[]
io.codearte.accurest.dsl.GroovyDsl.make {
label 'return_book_1'
input {
triggeredBy('bookReturnedTriggered()')
}
outputMessage {
sentTo('jms:output')
body('''{ "bookName" : "foo" }''')
headers {
header('BOOK-NAME', 'foo')
}
}
}
// end::sample_dsl[]
GroovyDsl dsl2 =
// tag::sample_dsl_2[]
io.codearte.accurest.dsl.GroovyDsl.make {
label 'return_book_2'
input {
messageFrom('jms:input')
messageBody([
bookName: 'foo'
])
messageHeaders {
header('sample', 'header')
}
}
outputMessage {
sentTo('jms:output')
body([
bookName: 'foo'
])
headers {
header('BOOK-NAME', 'foo')
}
}
}
// end::sample_dsl_2[]
}

View File

@@ -0,0 +1,146 @@
:input_name: input
:output_name: output
=== Stub Runner Messaging Stream
Accurest Stub Runner's messaging module gives you an easy way to integrate with Spring Stream.
For the provided artifacts it will automatically download the stubs and register the required
routes.
==== Adding it to the project
To use it you have to add the following dependency to your project (example for Gradle):
[source,groovy,indent=0]
----
testCompile "io.codearte.accurest:stub-runner-messaging-stream:${accurestVersion}"
----
==== Examples
===== Stubs structure
Let us assume that we 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
----
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/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=sample_dsl,indent=0]
----
and number *2*
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.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 `StubTiggerer` interface as follows
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.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/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger_receive,indent=0]
----
And the received message would pass the following assertions
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.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/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.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/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_receive,indent=0]
----
And the received message would pass the following assertions
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_receive_message,indent=0]
----
===== Custom triggers
`StubTrigger` gives you the following options to trigger a message:
===== Trigger by label
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=client_trigger,indent=0]
----
===== Trigger by group and artifact ids
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=trigger_group_artifact,indent=0]
----
===== Trigger by artifact ids
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=trigger_artifact,indent=0]
----
===== Trigger all messages
[source,groovy]
----
include::src/test/groovy/io/codearte/accurest/stubrunner/messaging/stream/StreamStubRunnerSpec.groovy[tags=trigger_all,indent=0]
----

View File

@@ -2,6 +2,7 @@ package io.codearte.accurest.stubrunner.messaging.stream
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import io.codearte.accurest.dsl.GroovyDsl
import io.codearte.accurest.messaging.AccurestMessage
import io.codearte.accurest.messaging.AccurestMessaging
import io.codearte.accurest.stubrunner.StubFinder
@@ -28,29 +29,43 @@ class StreamStubRunnerSpec extends Specification {
def 'should download the stub and register a route for it'() {
when:
// tag::client_send[]
messaging.send(new BookReturned('foo'), [sample: 'header'], 'input')
// end::client_send[]
then:
// tag::client_receive[]
AccurestMessage receivedMessage = messaging.receiveMessage('output')
// end::client_receive[]
and:
// tag::client_receive_message[]
receivedMessage != null
assertJsons(receivedMessage.payload)
receivedMessage.headers.get('BOOK-NAME') == 'foo'
// end::client_receive_message[]
}
def 'should trigger a message by label'() {
when:
// tag::client_trigger[]
stubFinder.trigger('return_book_1')
// end::client_trigger[]
then:
// tag::client_trigger_receive[]
AccurestMessage receivedMessage = messaging.receiveMessage('output')
// end::client_trigger_receive[]
and:
// tag::client_trigger_message[]
receivedMessage != null
assertJsons(receivedMessage.payload)
receivedMessage.headers.get('BOOK-NAME') == 'foo'
// end::client_trigger_message[]
}
def 'should trigger a label for the existing groupId:artifactId'() {
when:
// tag::trigger_group_artifact[]
stubFinder.trigger('io.codearte.accurest.stubs:streamService', 'return_book_1')
// end::trigger_group_artifact[]
then:
AccurestMessage receivedMessage = messaging.receiveMessage('output')
and:
@@ -61,7 +76,9 @@ class StreamStubRunnerSpec extends Specification {
def 'should trigger a label for the existing artifactId'() {
when:
// tag::trigger_artifact[]
stubFinder.trigger('streamService', 'return_book_1')
// end::trigger_artifact[]
then:
AccurestMessage receivedMessage = messaging.receiveMessage('output')
and:
@@ -92,7 +109,9 @@ class StreamStubRunnerSpec extends Specification {
def 'should trigger messages by running all triggers'() {
when:
// tag::trigger_all[]
stubFinder.trigger()
// end::trigger_all[]
then:
AccurestMessage receivedMessage = messaging.receiveMessage('output')
and:
@@ -108,4 +127,46 @@ class StreamStubRunnerSpec extends Specification {
return json.bookName == 'foo'
}
GroovyDsl dsl =
// tag::sample_dsl[]
io.codearte.accurest.dsl.GroovyDsl.make {
label 'return_book_1'
input {
triggeredBy('bookReturnedTriggered()')
}
outputMessage {
sentTo('jms:output')
body('''{ "bookName" : "foo" }''')
headers {
header('BOOK-NAME', 'foo')
}
}
}
// end::sample_dsl[]
GroovyDsl dsl2 =
// tag::sample_dsl_2[]
io.codearte.accurest.dsl.GroovyDsl.make {
label 'return_book_2'
input {
messageFrom('jms:input')
messageBody([
bookName: 'foo'
])
messageHeaders {
header('sample', 'header')
}
}
outputMessage {
sentTo('jms:output')
body([
bookName: 'foo'
])
headers {
header('BOOK-NAME', 'foo')
}
}
}
// end::sample_dsl_2[]
}