Fixed a bug with missing response variable
This commit is contained in:
@@ -52,9 +52,7 @@ abstract class MessagingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
addColonIfRequired(bb)
|
||||
}
|
||||
if (outputMessage) {
|
||||
if (outputMessage.headers) {
|
||||
validateResponseHeadersBlock(bb)
|
||||
}
|
||||
validateResponseHeadersBlock(bb)
|
||||
if (outputMessage.body) {
|
||||
bb.endBlock()
|
||||
if (outputMessage.headers) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.codearte.accurest.builder
|
||||
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import spock.lang.Specification
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@@ -280,4 +279,94 @@ then:
|
||||
stripped(test) == stripped(expectedMsg)
|
||||
}
|
||||
|
||||
def "should generate tests without headers for JUnit"() {
|
||||
given:
|
||||
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'
|
||||
])
|
||||
}
|
||||
}
|
||||
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(
|
||||
\t\t\t"{\\"bookName\\":\\"foo\\"}"
|
||||
\t\t, headers()
|
||||
\t\t\t.header("sample", "header"));
|
||||
|
||||
// when:
|
||||
accurestMessaging.send(inputMessage, "jms:input");
|
||||
|
||||
// then:
|
||||
AccurestMessage response = accurestMessaging.receiveMessage("jms:output");
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.getPayload()));
|
||||
assertThatJson(parsedJson).field("bookName").isEqualTo("foo");
|
||||
'''
|
||||
stripped(test) == stripped(expectedMsg)
|
||||
}
|
||||
|
||||
def "should generate tests without headers for Spock"() {
|
||||
given:
|
||||
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'
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
String expectedMsg =
|
||||
"""
|
||||
given:
|
||||
def inputMessage = accurestMessaging.create('''{"bookName":"foo"}'''
|
||||
,[
|
||||
'sample': 'header'
|
||||
])
|
||||
|
||||
when:
|
||||
accurestMessaging.send(inputMessage, 'jms:input')
|
||||
|
||||
then:
|
||||
def response = accurestMessaging.receiveMessage('jms:output')
|
||||
DocumentContext parsedJson = JsonPath.parse(accurestObjectMapper.writeValueAsString(response.payload))
|
||||
assertThatJson(parsedJson).field("bookName").isEqualTo("foo")
|
||||
"""
|
||||
stripped(test) == stripped(expectedMsg)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user