Added consumer producer description

This commit is contained in:
Marcin Grzejszczak
2016-04-25 17:49:48 +02:00
parent e75bbaafbc
commit f18cb39fe6
2 changed files with 61 additions and 1 deletions

View File

@@ -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)
}
}

View File

@@ -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.
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]
----