Updated messaging docs

This commit is contained in:
Marcin Grzejszczak
2016-04-24 08:34:38 +02:00
parent bc1bdb7d16
commit 573695caf0
2 changed files with 127 additions and 10 deletions

View File

@@ -91,6 +91,7 @@ class MessagingMethodBodyBuilderSpec extends Specification {
def "should generate tests triggered by a message for Spock"() {
given:
// tag::trigger_message_dsl[]
def contractDsl = GroovyDsl.make {
label 'some_label'
input {
@@ -112,13 +113,16 @@ class MessagingMethodBodyBuilderSpec extends Specification {
}
}
}
// end::trigger_message_dsl[]
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
stripped(test) == stripped('''
stripped(test) == stripped(
// tag::trigger_message_spock[]
'''
given:
def inputMessage = accurestMessaging.create(
\'\'\'{"bookName":"foo"}\'\'\',
@@ -134,7 +138,9 @@ class MessagingMethodBodyBuilderSpec extends Specification {
and:
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
assertThatJson(parsedJson).field("bookName").isEqualTo("foo")
''')
'''
// end::trigger_message_spock[]
)
}
def "should generate tests triggered by a message for JUnit"() {
@@ -166,7 +172,9 @@ class MessagingMethodBodyBuilderSpec extends Specification {
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
stripped(test) == stripped('''
stripped(test) == stripped(
// tag::trigger_message_junit[]
'''
// given:
AccurestMessage inputMessage = accurestMessaging.create(
"{\\"bookName\\":\\"foo\\"}"
@@ -183,11 +191,14 @@ class MessagingMethodBodyBuilderSpec extends Specification {
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload()));
assertThatJson(parsedJson).field("bookName").isEqualTo("foo");
''')
'''
// end::trigger_message_junit[]
)
}
def "should generate tests without destination, triggered by a message"() {
given:
// tag::trigger_no_output_dsl[]
def contractDsl = GroovyDsl.make {
label 'some_label'
input {
@@ -201,13 +212,16 @@ class MessagingMethodBodyBuilderSpec extends Specification {
assertThat('bookWasDeleted()')
}
}
// end::trigger_no_output_dsl[]
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
stripped(test) == stripped('''
stripped(test) == stripped(
// tag::trigger_no_output_spock[]
'''
given:
def inputMessage = accurestMessaging.create(
\'\'\'{"bookName":"foo"}\'\'\',
@@ -220,7 +234,9 @@ class MessagingMethodBodyBuilderSpec extends Specification {
then:
noExceptionThrown()
bookWasDeleted()
''')
'''
// end::trigger_no_output_spock[]
)
}
def "should generate tests without destination, triggered by a message for JUnit"() {
@@ -244,7 +260,9 @@ class MessagingMethodBodyBuilderSpec extends Specification {
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
stripped(test) == stripped('''
stripped(test) == stripped(
// tag::trigger_no_output_junit[]
'''
// given:
AccurestMessage inputMessage = accurestMessaging.create(
"{\\"bookName\\":\\"foo\\"}"
@@ -256,7 +274,9 @@ class MessagingMethodBodyBuilderSpec extends Specification {
// then:
bookWasDeleted();
''')
'''
// end::trigger_no_output_junit[]
)
}
}

View File

@@ -47,6 +47,103 @@ testCompile "io.codearte.accurest:accurest-messaging-core:${accurestVersion}"
=== Publisher side test generation
Having the `input` or `outputMessage` sections in your DSL will result in creation of tests on the publisher's side.
Having the `input` or `outputMessage` sections in your DSL will result in creation of tests on the publisher's side. By default
JUnit tests will be created, however there is also a possibility to create Spock tests.
//TODO: add examples from MessaginMethodBodyBuilderSpec
=== Examples
There are 3 main scenarios that we should take into consideration:
- Scenario 1: there is no input message that produces an output one. The output message is triggered by a component
inside the application (e.g. scheduler)
- Scenario 2: the input message triggers an output message
- Scenarion 3: the input message is consumed and there is no output message
==== Scenario 1 (no input message)
For the given contract:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_dsl]
----
The following JUnit test will be created:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_junit_test]
----
And the following Spock test would be created:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_method_test]
----
==== Scenario 2 (output triggered by input)
For the given contract:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_dsl]
----
The following JUnit test will be created:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_junit]
----
And the following Spock test would be created:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_message_spock]
----
==== Scenario 3 (no output message)
For the given contract:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_dsl]
----
The following JUnit test will be created:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_junit]
----
And the following Spock test would be created:
[source,groovy]
----
include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_spock]
----
=== Consumer Stub Side generation
Unlike the HTTP part - in Messaging we need to publish the Groovy DSL inside the JAR with a stub. Then it's parsed on the consumer side
and proper stubbed routes are created.
For more infromation please consult the Stub Runner Messaging sections.
==== Gradle Setup
Example of Accurest Gradle setup:
[source,groovy,indent=0]
----
include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=jar_setup,indent=0]
----
==== Maven Setup
Example of Maven can be found in the [AccuREST Maven Plugin README](https://github.com/Codearte/accurest-maven-plugin/=publishing-wiremock-stubs-projectf-stubsjar)