From f18cb39fe62d122d7e3eda7391e2425394f975c9 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 25 Apr 2016 17:49:48 +0200 Subject: [PATCH] Added consumer producer description --- .../MessagingMethodBodyBuilderSpec.groovy | 50 +++++++++++++++++++ docs/src/docs/asciidoc/contract.adoc | 12 ++++- 2 files changed, 61 insertions(+), 1 deletion(-) 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 1855c7b88b..22dba316f2 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 @@ -1,5 +1,6 @@ package io.codearte.accurest.builder +import io.codearte.accurest.dsl.Accurest import io.codearte.accurest.dsl.GroovyDsl import spock.lang.Specification /** @@ -375,4 +376,53 @@ then: return text.stripIndent().stripMargin().replace(' ', '').replace('\n', '').replace('\t', '').replaceAll("\\W", "") } + def "should generate tests without headers for JUnit with consumer / producer notation"() { + given: + def contractDsl = + // tag::consumer_producer[] +Accurest.make { + label 'some_label' + input { + messageFrom value(consumer('jms:output'), producer('jms:input')) + messageBody([ + bookName: 'foo' + ]) + messageHeaders { + header('sample', 'header') + } + } + outputMessage { + sentTo $(consumer('jms:input'), producer('jms:output')) + body([ + bookName: 'foo' + ]) + } +} + // end::consumer_producer[] + MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl) + BlockBuilder blockBuilder = new BlockBuilder(" ") + when: + builder.appendTo(blockBuilder) + def test = blockBuilder.toString() + then: + String expectedMsg = + ''' + // given: + AccurestMessage inputMessage = accurestMessaging.create( + "{\\"bookName\\":\\"foo\\"}" + , headers() + .header("sample", "header")); + + // when: + accurestMessaging.send(inputMessage, "jms:input"); + + // then: + AccurestMessage response = accurestMessaging.receiveMessage("jms:output"); + assertThat(response).isNotNull(); + DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload())); + assertThatJson(parsedJson).field("bookName").isEqualTo("foo"); +''' + stripped(test) == stripped(expectedMsg) + } + } diff --git a/docs/src/docs/asciidoc/contract.adoc b/docs/src/docs/asciidoc/contract.adoc index eb083a9338..8778f7259b 100644 --- a/docs/src/docs/asciidoc/contract.adoc +++ b/docs/src/docs/asciidoc/contract.adoc @@ -190,4 +190,14 @@ include::../../../../samples/messaging-integration/src/test/groovy/io/codearte/a In this case the output message will be sent to `output` if a proper message will be received on the `input` destination. In the message *publisher's* side we will generate a test that will send the input message to the defined destination. On the *consumer* side you can either send a message to the input -destination or use the `some_label` to trigger the message. \ No newline at end of file +destination or use the `some_label` to trigger the message. + +==== Consumer / Producer + +In HTTP you have a notion of `client`/`stub and `server`/`test` notation. You can use them also in messaging but we're providing also the `consumer` and `produer` methods +as presented below (note you can use either `$` or `value` methods to provide `consumer` and `producer` parts) + +[source,groovy] +---- +include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MessagingMethodBodyBuilderSpec.groovy[tags=consumer_producer] +---- \ No newline at end of file