diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy index 88ddd86b90..5e5ca20856 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy @@ -2,6 +2,7 @@ package io.codearte.accurest.builder import io.codearte.accurest.dsl.GroovyDsl import spock.lang.Specification + /** * @author Marcin Grzejszczak */ @@ -9,21 +10,21 @@ class MessagingMethodBodyBuilderSpec extends Specification { def "should work for triggered based messaging with Spock"() { given: - // tag::trigger_method_dsl[] - def contractDsl = GroovyDsl.make { - label 'some_label' - input { - triggeredBy('bookReturnedTriggered()') - } - outputMessage { - sentTo('activemq:output') - body('''{ "bookName" : "foo" }''') - headers { - header('BOOK-NAME', 'foo') - } - } - } - // end::trigger_method_dsl[] +// tag::trigger_method_dsl[] +def contractDsl = GroovyDsl.make { + label 'some_label' + input { + triggeredBy('bookReturnedTriggered()') + } + outputMessage { + sentTo('activemq:output') + body('''{ "bookName" : "foo" }''') + headers { + header('BOOK-NAME', 'foo') + } + } +} +// end::trigger_method_dsl[] MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl) BlockBuilder blockBuilder = new BlockBuilder(" ") when: @@ -31,19 +32,19 @@ class MessagingMethodBodyBuilderSpec extends Specification { def test = blockBuilder.toString() then: stripped(test) == stripped( - // tag::trigger_method_test[] - ''' - when: - bookReturnedTriggered() +// tag::trigger_method_test[] +''' +when: + bookReturnedTriggered() - then: - def response = accurestMessaging.receiveMessage('activemq:output') - response.getHeader('BOOK-NAME') == 'foo' - and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) - assertThatJson(parsedJson).field("bookName").isEqualTo("foo") - ''' - // end::trigger_method_test[] +then: + def response = accurestMessaging.receiveMessage('activemq:output') + response.getHeader('BOOK-NAME') == 'foo' +and: + DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + assertThatJson(parsedJson).field("bookName").isEqualTo("foo") +''' +// end::trigger_method_test[] ) } @@ -69,19 +70,19 @@ class MessagingMethodBodyBuilderSpec extends Specification { def test = blockBuilder.toString() then: stripped(test) == stripped( - // tag::trigger_method_junit_test[] - ''' - // when: - bookReturnedTriggered(); +// tag::trigger_method_junit_test[] +''' +// when: + bookReturnedTriggered(); - // then: - AccurestMessage response = accurestMessaging.receiveMessage("activemq:output"); - assertThat(response.getHeader("BOOK-NAME")).isEqualTo("foo"); - // and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); - assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); - ''' - // end::trigger_method_junit_test[] +// then: + AccurestMessage response = accurestMessaging.receiveMessage("activemq:output"); + assertThat(response.getHeader("BOOK-NAME")).isEqualTo("foo"); +// and: + DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); + assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); +''' +// end::trigger_method_junit_test[] ) } @@ -92,27 +93,27 @@ 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 { - messageFrom('jms:input') - messageBody([ - bookName: 'foo' - ]) - messageHeaders { - header('sample', 'header') - } - } - outputMessage { - sentTo('jms:output') - body([ - bookName: 'foo' - ]) - headers { - header('BOOK-NAME', 'foo') - } - } - } +def contractDsl = GroovyDsl.make { + label 'some_label' + input { + messageFrom('jms:input') + messageBody([ + bookName: 'foo' + ]) + messageHeaders { + header('sample', 'header') + } + } + outputMessage { + sentTo('jms:output') + body([ + bookName: 'foo' + ]) + headers { + header('BOOK-NAME', 'foo') + } + } +} // end::trigger_message_dsl[] MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl) BlockBuilder blockBuilder = new BlockBuilder(" ") @@ -121,25 +122,25 @@ class MessagingMethodBodyBuilderSpec extends Specification { def test = blockBuilder.toString() then: stripped(test) == stripped( - // tag::trigger_message_spock[] - ''' - given: - def inputMessage = accurestMessaging.create( - \'\'\'{"bookName":"foo"}\'\'\', - ['sample': 'header'] - ) +// tag::trigger_message_spock[] +''' +given: + def inputMessage = accurestMessaging.create( + \'\'\'{"bookName":"foo"}\'\'\', + ['sample': 'header'] + ) - when: - accurestMessaging.send(inputMessage, 'jms:input') +when: + accurestMessaging.send(inputMessage, 'jms:input') - then: - def response = accurestMessaging.receiveMessage('jms:output') - response.getHeader('BOOK-NAME') == 'foo' - and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) - assertThatJson(parsedJson).field("bookName").isEqualTo("foo") - ''' - // end::trigger_message_spock[] +then: + def response = accurestMessaging.receiveMessage('jms:output') + response.getHeader('BOOK-NAME') == 'foo' +and: + DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload)) + assertThatJson(parsedJson).field("bookName").isEqualTo("foo") +''' +// end::trigger_message_spock[] ) } @@ -174,24 +175,24 @@ class MessagingMethodBodyBuilderSpec extends Specification { then: stripped(test) == stripped( // tag::trigger_message_junit[] - ''' - // given: - AccurestMessage inputMessage = accurestMessaging.create( - "{\\"bookName\\":\\"foo\\"}" - , headers() - .header("sample", "header")); +''' +// given: + AccurestMessage inputMessage = accurestMessaging.create( + "{\\"bookName\\":\\"foo\\"}" +, headers() + .header("sample", "header")); - // when: - accurestMessaging.send(inputMessage, "jms:input"); +// when: + accurestMessaging.send(inputMessage, "jms:input"); - // then: - AccurestMessage response = accurestMessaging.receiveMessage("jms:output"); - assertThat(response.getHeader("BOOK-NAME")).isEqualTo("foo"); - // and: - DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); - assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); +// then: + AccurestMessage response = accurestMessaging.receiveMessage("jms:output"); + assertThat(response.getHeader("BOOK-NAME")).isEqualTo("foo"); +// and: + DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); + assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); - ''' +''' // end::trigger_message_junit[] ) } @@ -199,19 +200,19 @@ class MessagingMethodBodyBuilderSpec extends Specification { def "should generate tests without destination, triggered by a message"() { given: // tag::trigger_no_output_dsl[] - def contractDsl = GroovyDsl.make { - label 'some_label' - input { - messageFrom('jms:delete') - messageBody([ - bookName: 'foo' - ]) - messageHeaders { - header('sample', 'header') - } - assertThat('bookWasDeleted()') - } - } +def contractDsl = GroovyDsl.make { + label 'some_label' + input { + messageFrom('jms:delete') + messageBody([ + bookName: 'foo' + ]) + messageHeaders { + header('sample', 'header') + } + assertThat('bookWasDeleted()') + } +} // end::trigger_no_output_dsl[] MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl) BlockBuilder blockBuilder = new BlockBuilder(" ") @@ -219,24 +220,24 @@ class MessagingMethodBodyBuilderSpec extends Specification { builder.appendTo(blockBuilder) def test = blockBuilder.toString() then: - stripped(test) == stripped( - // tag::trigger_no_output_spock[] - ''' - given: - def inputMessage = accurestMessaging.create( - \'\'\'{"bookName":"foo"}\'\'\', - ['sample': 'header'] - ) + String expectedMsg = +// tag::trigger_no_output_spock[] +''' +given: + def inputMessage = accurestMessaging.create( + \'\'\'{"bookName":"foo"}\'\'\', + ['sample': 'header'] + ) - when: - accurestMessaging.send(inputMessage, 'jms:delete') +when: + accurestMessaging.send(inputMessage, 'jms:delete') - then: - noExceptionThrown() - bookWasDeleted() - ''' - // end::trigger_no_output_spock[] - ) +then: + noExceptionThrown() + bookWasDeleted() +''' +// end::trigger_no_output_spock[] + stripped(test) == stripped(expectedMsg) } def "should generate tests without destination, triggered by a message for JUnit"() { @@ -260,23 +261,23 @@ class MessagingMethodBodyBuilderSpec extends Specification { builder.appendTo(blockBuilder) def test = blockBuilder.toString() then: - stripped(test) == stripped( - // tag::trigger_no_output_junit[] - ''' - // given: - AccurestMessage inputMessage = accurestMessaging.create( - "{\\"bookName\\":\\"foo\\"}" - , headers() - .header("sample", "header")); + String expectedMsg = +// tag::trigger_no_output_junit[] +''' +// given: + AccurestMessage inputMessage = accurestMessaging.create( + "{\\"bookName\\":\\"foo\\"}" +, headers() + .header("sample", "header")); - // when: - accurestMessaging.send(inputMessage, "jms:delete"); +// when: + accurestMessaging.send(inputMessage, "jms:delete"); - // then: - bookWasDeleted(); - ''' - // end::trigger_no_output_junit[] - ) +// then: + bookWasDeleted(); +''' +// end::trigger_no_output_junit[] + stripped(test) == stripped(expectedMsg) } } diff --git a/accurest-messaging/README.adoc b/accurest-messaging/README.adoc index 8bd09cb051..b59884a982 100644 --- a/accurest-messaging/README.adoc +++ b/accurest-messaging/README.adoc @@ -1,4 +1,4 @@ -= Accurest Messaging + = Accurest Messaging Accurest allows you to verify your application that uses messaging as means of communication. All of our integrations are working with Spring but you can also set one yourself. diff --git a/docs/src/docs/asciidoc/messaging.adoc b/docs/src/docs/asciidoc/messaging.adoc index e47549ef98..d6946f16ae 100644 --- a/docs/src/docs/asciidoc/messaging.adoc +++ b/docs/src/docs/asciidoc/messaging.adoc @@ -31,10 +31,10 @@ testCompile "io.codearte.accurest:accurest-messaging-stream:${accurestVersion}" 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 +- `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. @@ -56,7 +56,7 @@ 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 3: the input message is consumed and there is no output message ==== Scenario 1 (no input message) diff --git a/docs/src/docs/asciidoc/rest.adoc b/docs/src/docs/asciidoc/rest.adoc index ade4477aa9..b34e1301fe 100644 --- a/docs/src/docs/asciidoc/rest.adoc +++ b/docs/src/docs/asciidoc/rest.adoc @@ -53,7 +53,7 @@ Read more: http://codearte.github.io/accurest-maven-plugin/[accurest-maven-plugi ===== Add stubs -By default Accurest is looking for stubs in `src/test/resources/stubs` directory. +By default Accurest is looking for stubs in `src/test/accurest` directory. Directory containing stub definitions is treated as a class name, and each stub definition is treated as a single test. We assume that it contains at least one directory which will be used as test class name. If there is more than one level of nested directories all except the last one will be used as package name. @@ -66,6 +66,7 @@ src/test/accurest/myservice/shouldReturnUser.groovy ---- Accurest will create test class `defaultBasePackage.MyService` with two methods + - `shouldCreateUser()` - `shouldReturnUser()` @@ -102,7 +103,7 @@ accurest { ===== Base class for tests - When using Accurest in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified. +When using Accurest in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified. [source,groovy,indent=0] ---- @@ -131,7 +132,7 @@ In consumer service you need to configure Accurest plugin in exactly the same wa ./gradlew generateWireMockClientStubs ---- -command. Note that `stubsOutputDir` option has to be set for stub generation to work. +Note that `stubsOutputDir` option has to be set for stub generation to work. When present, json stubs can be used in consumer automated tests. diff --git a/docs/src/docs/asciidoc/stubrunner.adoc b/docs/src/docs/asciidoc/stubrunner.adoc index b429b2d4f8..e62bb68312 100644 --- a/docs/src/docs/asciidoc/stubrunner.adoc +++ b/docs/src/docs/asciidoc/stubrunner.adoc @@ -20,7 +20,7 @@ include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/sc ==== Maven -Example of Maven can be found in the [Accurest Maven Plugin README](https://github.com/Codearte/accurest-maven-plugin/=publishing-wiremock-stubs-projectf-stubsjar) +Example of Maven can be found in the https://github.com/Codearte/accurest-maven-plugin/=publishing-wiremock-stubs-projectf-stubsjar[Accurest Maven Plugin README] === Modules