Merge pull request #178 from RemboL/issues/177-multiline-non-json-body-breaks-the-generated-test
[#177] modified generation of test method body to allow for multiline body requests
This commit is contained in:
@@ -26,7 +26,7 @@ class MockMvcSpockMethodBodyBuilder extends SpockMethodBodyBuilder {
|
||||
bb.addLine(".header('${getTestSideValue(header.name)}', '${getTestSideValue(header.serverValue)}')")
|
||||
}
|
||||
if (request.body) {
|
||||
bb.addLine(".body('$bodyAsString')")
|
||||
bb.addLine(".body('''$bodyAsString''')")
|
||||
}
|
||||
bb.unindent()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package io.codearte.accurest.builder
|
||||
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import io.codearte.accurest.dsl.WireMockStubStrategy
|
||||
import io.codearte.accurest.dsl.WireMockStubVerifier
|
||||
@@ -8,7 +7,6 @@ import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* @author Jakub Kubrynski
|
||||
*/
|
||||
@@ -91,7 +89,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains(".body('{\"items\":[\"HOP\"]}')")
|
||||
blockBuilder.toString().contains(".body('''{\"items\":[\"HOP\"]}''')")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub())
|
||||
}
|
||||
@@ -116,7 +114,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains(".body('property1=VAL1')")
|
||||
blockBuilder.toString().contains(".body('''property1=VAL1''')")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub())
|
||||
}
|
||||
@@ -399,7 +397,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains(".body('')")
|
||||
spockTest.contains(".body('''''')")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub())
|
||||
}
|
||||
@@ -814,4 +812,28 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
!spockTest.contains("\\u041f")
|
||||
}
|
||||
|
||||
@Issue('177')
|
||||
def "should generate proper test code when having multiline body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "PUT"
|
||||
url "/multiline"
|
||||
body('''hello,
|
||||
World.''')
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains("""'''hello,
|
||||
World.'''""")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user