Merged specs for MockMvcSpockMethodBuilder and MockMvcJUnitMethodBuilder.
This commit is contained in:
@@ -1,965 +0,0 @@
|
||||
package io.codearte.accurest.builder
|
||||
|
||||
import io.codearte.accurest.dsl.GroovyDsl
|
||||
import io.codearte.accurest.dsl.WireMockStubStrategy
|
||||
import io.codearte.accurest.dsl.WireMockStubVerifier
|
||||
import io.codearte.accurest.file.Contract
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @since 2015-08-07
|
||||
*/
|
||||
class MockMvcJunitMethodBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
|
||||
def "should generate assertions for simple response body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body """{
|
||||
"property1": "a",
|
||||
"property2": "b"
|
||||
}"""
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains('assertThatJson(parsedJson).field("property1").isEqualTo("a");')
|
||||
blockBuilder.toString().contains('assertThatJson(parsedJson).field("property2").isEqualTo("b");')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue("#187")
|
||||
def "should generate assertions for null and boolean values"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body """{
|
||||
"property1": "true",
|
||||
"property2": null,
|
||||
"property3": false
|
||||
}"""
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("true");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").isNull();""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property3").isEqualTo(false);""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
def "should generate assertions for simple response body constructed from map with a list"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
property1: 'a',
|
||||
property2: [
|
||||
[a: 'sth'],
|
||||
[b: 'sthElse']
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property2").contains("a").isEqualTo("sth");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property2").contains("b").isEqualTo("sthElse");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue("#82")
|
||||
def "should generate proper request when body constructed from map with a list"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
body(
|
||||
items: ['HOP']
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains('.body("{\\"items\\":[\\"HOP\\"]}")')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue("#88")
|
||||
def "should generate proper request when body constructed from GString"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
body(
|
||||
"property1=VAL1"
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains('.body("\\"property1=VAL1\\"")')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue("185")
|
||||
def "should generate assertions for a response body containing map with integers as keys"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
property: [
|
||||
14: 0.0,
|
||||
7 : 0.0
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").field(7).isEqualTo(0.0);""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").field(14).isEqualTo(0.0);""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should generate assertions for array in response body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body """[
|
||||
{
|
||||
"property1": "a"
|
||||
},
|
||||
{
|
||||
"property2": "b"
|
||||
}]"""
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property2").isEqualTo("b");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property1").isEqualTo("a");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should generate assertions for array inside response body element"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body """{
|
||||
"property1": [
|
||||
{ "property2": "test1"},
|
||||
{ "property3": "test2"}
|
||||
]
|
||||
}"""
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property1").contains("property2").isEqualTo("test1");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property1").contains("property3").isEqualTo("test2");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should generate assertions for nested objects in response body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body '''\
|
||||
{
|
||||
"property1": "a",
|
||||
"property2": {"property3": "b"}
|
||||
}
|
||||
'''
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").field("property3").isEqualTo("b");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should generate regex assertions for map objects in response body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
property1: "a",
|
||||
property2: value(
|
||||
client('123'),
|
||||
server(regex('[0-9]{3}'))
|
||||
)
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
|
||||
def "should generate regex assertions for string objects in response body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body("""{"property1":"a","property2":"${value(client('123'), server(regex('[0-9]{3}')))}"}""")
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}");""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue(["#126", "#143"])
|
||||
def "should generate escaped regex assertions for string objects in response body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body("""{"property":" ${value(client('123'), server(regex('\\d+')))}"}""")
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").matches("\\\\d+");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath('/users') {
|
||||
queryParameters {
|
||||
parameter 'limit': $(client(equalTo("20")), server(equalTo("10")))
|
||||
parameter 'offset': $(client(containing("20")), server(equalTo("20")))
|
||||
parameter 'filter': "email"
|
||||
parameter 'sort': equalTo("name")
|
||||
parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("55"))
|
||||
parameter 'age': $(client(notMatching("^\\w*\$")), server("99"))
|
||||
parameter 'name': $(client(matching("Denis.*")), server("Denis.Stepanov"))
|
||||
parameter 'email': "bob@email.com"
|
||||
parameter 'hello': $(client(matching("Denis.*")), server(absent()))
|
||||
parameter 'hello': absent()
|
||||
}
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body """
|
||||
{
|
||||
"property1": "a",
|
||||
"property2": "b"
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('get("/users?limit=10&offset=20&filter=email&sort=name&search=55&age=99&name=Denis.Stepanov&email=bob@email.com")')
|
||||
jUnitTest.contains('assertThatJson(parsedJson).field("property1").isEqualTo("a")')
|
||||
jUnitTest.contains('assertThatJson(parsedJson).field("property2").isEqualTo("b")')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
def "should generate a call with an url path and query parameters with url containing a pattern"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url($(stub(regex('/foo/[0-9]+')), test('/foo/123456'))) {
|
||||
queryParameters {
|
||||
parameter 'limit': $(client(equalTo("20")), server(equalTo("10")))
|
||||
parameter 'offset': $(client(containing("20")), server(equalTo("20")))
|
||||
parameter 'filter': "email"
|
||||
parameter 'sort': equalTo("name")
|
||||
parameter 'search': $(client(notMatching(~/^\/[0-9]{2}$/)), server("55"))
|
||||
parameter 'age': $(client(notMatching("^\\w*\$")), server("99"))
|
||||
parameter 'name': $(client(matching("Denis.*")), server("Denis.Stepanov"))
|
||||
parameter 'email': "bob@email.com"
|
||||
parameter 'hello': $(client(matching("Denis.*")), server(absent()))
|
||||
parameter 'hello': absent()
|
||||
}
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body """
|
||||
{
|
||||
"property1": "a",
|
||||
"property2": "b"
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('get("/foo/123456?limit=10&offset=20&filter=email&sort=name&search=55&age=99&name=Denis.Stepanov&email=bob@email.com")')
|
||||
jUnitTest.contains('assertThatJson(parsedJson).field("property1").isEqualTo("a")')
|
||||
jUnitTest.contains('assertThatJson(parsedJson).field("property2").isEqualTo("b")')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should generate test for empty body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method('POST')
|
||||
url("/ws/payments")
|
||||
body("")
|
||||
}
|
||||
response {
|
||||
status 406
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains(".body(\"\\\"\\\"\")")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should generate test for String in response body"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "POST"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body "test"
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('Object responseBody = (response.getBody().asString());')
|
||||
jUnitTest.contains('assertThat(responseBody).isEqualTo("test");')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue('113')
|
||||
def "should generate regex test for String in response header"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'POST'
|
||||
url $(client(regex('/partners/[0-9]+/users')), server('/partners/1000/users'))
|
||||
headers { header 'Content-Type': 'application/json' }
|
||||
body(
|
||||
first_name: 'John',
|
||||
last_name: 'Smith',
|
||||
personal_id: '12345678901',
|
||||
phone_number: '500500500',
|
||||
invitation_token: '00fec7141bb94793bfe7ae1d0f39bda0',
|
||||
password: 'john'
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 201
|
||||
headers {
|
||||
header 'Location': $(client('http://localhost/partners/1000/users/1001'), server(regex('http://localhost/partners/[0-9]+/users/[0-9]+')))
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
@Issue('115')
|
||||
def "should generate regex with helper method"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method 'POST'
|
||||
url $(client(regex('/partners/[0-9]+/users')), server('/partners/1000/users'))
|
||||
headers { header 'Content-Type': 'application/json' }
|
||||
body(
|
||||
first_name: 'John',
|
||||
last_name: 'Smith',
|
||||
personal_id: '12345678901',
|
||||
phone_number: '500500500',
|
||||
invitation_token: '00fec7141bb94793bfe7ae1d0f39bda0',
|
||||
password: 'john'
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 201
|
||||
headers {
|
||||
header 'Location': $(client('http://localhost/partners/1000/users/1001'), server(regex("^${hostname()}/partners/[0-9]+/users/[0-9]+")))
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should work with more complex stuff and jsonpaths"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
priority 10
|
||||
request {
|
||||
method 'POST'
|
||||
url '/validation/client'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
bank_account_number: '0014282912345698765432161182',
|
||||
email: 'foo@bar.com',
|
||||
phone_number: '100299300',
|
||||
personal_id: 'ABC123456'
|
||||
)
|
||||
}
|
||||
|
||||
response {
|
||||
status 200
|
||||
body(errors: [
|
||||
[property: "bank_account_number", message: "incorrect_format"]
|
||||
])
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains("""assertThatJson(parsedJson).array("errors").contains("property").isEqualTo("bank_account_number");""")
|
||||
jUnitTest.contains("""assertThatJson(parsedJson).array("errors").contains("message").isEqualTo("incorrect_format");""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
|
||||
}
|
||||
|
||||
def "should work properly with GString url"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
|
||||
request {
|
||||
method 'PUT'
|
||||
url "/partners/${value(client(regex('^[0-9]*$')), server('11'))}/agents/11/customers/09665703Z"
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
first_name: 'Josef',
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 422
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains("/partners/11/agents/11/customers/09665703Z")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
|
||||
def "should resolve properties in GString with regular expression"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
priority 1
|
||||
request {
|
||||
method 'POST'
|
||||
url '/users/password'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
email: $(client(regex(email())), server('not.existing@user.com')),
|
||||
callback_url: $(client(regex(hostname())), server('http://partners.com'))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 404
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
code: 4,
|
||||
message: "User not found by email = [${value(server(regex(email())), client('not.existing@user.com'))}]"
|
||||
)
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('''assertThatJson(parsedJson).field("message").matches("User not found by email = \\\\\\\\[[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\\\\\.[a-zA-Z]{2,4}\\\\\\\\]");''')
|
||||
}
|
||||
|
||||
|
||||
@Issue('42')
|
||||
@Unroll
|
||||
def "should not omit the optional field in the test creation"() {
|
||||
given:
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('\\"email\\":\\"abc@abc.com\\"')
|
||||
jUnitTest.contains('assertThatJson(parsedJson).field("code").matches("(123123)?");')
|
||||
!jUnitTest.contains('''REGEXP''')
|
||||
!jUnitTest.contains('''OPTIONAL''')
|
||||
!jUnitTest.contains('''OptionalProperty''')
|
||||
where:
|
||||
contractDsl << [
|
||||
GroovyDsl.make {
|
||||
priority 1
|
||||
request {
|
||||
method 'POST'
|
||||
url '/users/password'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
email: $(stub(optional(regex(email()))), test('abc@abc.com')),
|
||||
callback_url: $(stub(regex(hostname())), test('http://partners.com'))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 404
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
code: value(stub("123123"), test(optional("123123"))),
|
||||
message: "User not found by email = [${value(test(regex(email())), stub('not.existing@user.com'))}]"
|
||||
)
|
||||
}
|
||||
},
|
||||
GroovyDsl.make {
|
||||
priority 1
|
||||
request {
|
||||
method 'POST'
|
||||
url '/users/password'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
""" {
|
||||
"email" : "${value(stub(optional(regex(email()))), test('abc@abc.com'))}",
|
||||
"callback_url" : "${value(client(regex(hostname())), server('http://partners.com'))}"
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 404
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
""" {
|
||||
"code" : "${value(stub(123123), test(optional(123123)))}",
|
||||
"message" : "User not found by email = [${
|
||||
value(server(regex(email())), client('not.existing@user.com'))
|
||||
}]"
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@Issue('72')
|
||||
def "should make the execute method work"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method """PUT"""
|
||||
url """/fraudcheck"""
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header("""Content-Type""", """application/vnd.fraud.v1+json""")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body("""{
|
||||
"fraudCheckStatus": "OK",
|
||||
"rejectionReason": ${value(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))}
|
||||
}""")
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''')
|
||||
}
|
||||
|
||||
def "should support inner map and list definitions"() {
|
||||
given:
|
||||
|
||||
Pattern PHONE_NUMBER = Pattern.compile(/[+\w]*/)
|
||||
Pattern ANYSTRING = Pattern.compile(/.*/)
|
||||
Pattern NUMBERS = Pattern.compile(/[\d\.]*/)
|
||||
Pattern DATETIME = ANYSTRING
|
||||
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "PUT"
|
||||
url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/client_data"
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
body(
|
||||
client: [
|
||||
first_name : $(stub(regex(onlyAlphaUnicode())), test('Denis')),
|
||||
last_name : $(stub(regex(onlyAlphaUnicode())), test('FakeName')),
|
||||
email : $(stub(regex(email())), test('fakemail@fakegmail.com')),
|
||||
fax : $(stub(PHONE_NUMBER), test('+xx001213214')),
|
||||
phone : $(stub(PHONE_NUMBER), test('2223311')),
|
||||
data_of_birth: $(stub(DATETIME), test('2002-10-22T00:00:00Z'))
|
||||
],
|
||||
client_id_card: [
|
||||
id : $(stub(ANYSTRING), test('ABC12345')),
|
||||
date_of_issue: $(stub(ANYSTRING), test('2002-10-02T00:00:00Z')),
|
||||
address : [
|
||||
street : $(stub(ANYSTRING), test('Light Street')),
|
||||
city : $(stub(ANYSTRING), test('Fire')),
|
||||
region : $(stub(ANYSTRING), test('Skys')),
|
||||
country: $(stub(ANYSTRING), test('HG')),
|
||||
zip : $(stub(NUMBERS), test('658965'))
|
||||
]
|
||||
],
|
||||
incomes_and_expenses: [
|
||||
monthly_income : $(stub(NUMBERS), test('0.0')),
|
||||
monthly_loan_repayments: $(stub(NUMBERS), test('100')),
|
||||
monthly_living_expenses: $(stub(NUMBERS), test('22'))
|
||||
],
|
||||
additional_info: [
|
||||
allow_to_contact: $(stub(optional(regex(anyBoolean()))), test('true'))
|
||||
]
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains '\\"street\\":\\"Light Street\\"'
|
||||
!jUnitTest.contains("clientValue")
|
||||
!jUnitTest.contains("cursor")
|
||||
}
|
||||
|
||||
def "shouldn't generate unicode escape characters"() {
|
||||
given:
|
||||
Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/)
|
||||
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "PUT"
|
||||
url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/енев"
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
body(
|
||||
client: [
|
||||
first_name: $(stub(ONLY_ALPHA_UNICODE), test('Пенева')),
|
||||
last_name : $(stub(ONLY_ALPHA_UNICODE), test('Пенева'))
|
||||
]
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
!jUnitTest.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.'''""")
|
||||
}
|
||||
|
||||
@Issue('180')
|
||||
def "should generate proper test code when having multipart parameters"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "PUT"
|
||||
url "/multipart"
|
||||
headers {
|
||||
header('content-type', 'multipart/form-data;boundary=AaB03x')
|
||||
}
|
||||
multipart(
|
||||
formParameter: value(client(regex('.+')), server('"formParameterValue"')),
|
||||
someBooleanParameter: value(client(regex('(true|false)')), server('true')),
|
||||
file: named(value(client(regex('.+')), server('filename.csv')), value(client(regex('.+')), server('file content')))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('"content-type", "multipart/form-data;boundary=AaB03x"')
|
||||
jUnitTest.contains('.param("formParameter", "\\"formParameterValue\\"")')
|
||||
jUnitTest.contains('.param("someBooleanParameter", "true")')
|
||||
jUnitTest.contains('.multiPart("file", "filename.csv", "file content".getBytes());')
|
||||
}
|
||||
|
||||
@Issue('180')
|
||||
def "should generate proper test code when having multipart parameters with named as map"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "PUT"
|
||||
url "/multipart"
|
||||
multipart(
|
||||
formParameter: value(client(regex('".+"')), server('"formParameterValue"')),
|
||||
someBooleanParameter: value(client(regex('(true|false)')), server('true')),
|
||||
file: named(
|
||||
name: value(client(regex('.+')), server('filename.csv')),
|
||||
content: value(client(regex('.+')), server('file content')))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcJUnitMethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
def jUnitTest = blockBuilder.toString()
|
||||
then:
|
||||
jUnitTest.contains('.multiPart')
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import io.codearte.accurest.dsl.WireMockStubStrategy
|
||||
import io.codearte.accurest.dsl.WireMockStubVerifier
|
||||
import io.codearte.accurest.file.Contract
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
|
||||
@@ -13,9 +14,70 @@ import java.util.regex.Pattern
|
||||
/**
|
||||
* @author Jakub Kubrynski
|
||||
*/
|
||||
class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
class MockMvcMethodBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
|
||||
def "should generate assertions for simple response body"() {
|
||||
@Shared
|
||||
GroovyDsl dslWithOptionalsInString = GroovyDsl.make {
|
||||
priority 1
|
||||
request {
|
||||
method 'POST'
|
||||
url '/users/password'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
email: $(stub(optional(regex(email()))), test('abc@abc.com')),
|
||||
callback_url: $(stub(regex(hostname())), test('http://partners.com'))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 404
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
code: value(stub("123123"), test(optional("123123"))),
|
||||
message: "User not found by email = [${value(test(regex(email())), stub('not.existing@user.com'))}]"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Shared
|
||||
GroovyDsl dslWithOptionals = GroovyDsl.make {
|
||||
priority 1
|
||||
request {
|
||||
method 'POST'
|
||||
url '/users/password'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
""" {
|
||||
"email" : "${value(stub(optional(regex(email()))), test('abc@abc.com'))}",
|
||||
"callback_url" : "${value(client(regex(hostname())), server('http://partners.com'))}"
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 404
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
""" {
|
||||
"code" : "${value(stub(123123), test(optional(123123)))}",
|
||||
"message" : "User not found by email = [${
|
||||
value(server(regex(email())), client('not.existing@user.com'))
|
||||
}]"
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def "should generate assertions for simple response body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -30,7 +92,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}"""
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -38,11 +100,16 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").isEqualTo("b")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue("#187")
|
||||
def "should generate assertions for null and boolean values"() {
|
||||
@Unroll
|
||||
def "should generate assertions for null and boolean values with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -58,7 +125,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}"""
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -67,11 +134,16 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").isNull()""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property3").isEqualTo(false)""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
def "should generate assertions for simple response body constructed from map with a list"() {
|
||||
@Unroll
|
||||
def "should generate assertions for simple response body constructed from map with a list with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -89,7 +161,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
)
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -98,11 +170,16 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property2").contains("a").isEqualTo("sth")""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property2").contains("b").isEqualTo("sthElse")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue("#82")
|
||||
def "should generate proper request when body constructed from map with a list"() {
|
||||
@Unroll
|
||||
def "should generate proper request when body constructed from map with a list #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -116,18 +193,23 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains(""".body('''{\"items\":[\"HOP\"]}''')""")
|
||||
blockBuilder.toString().contains(bodyString)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | """.body('''{\"items\":[\"HOP\"]}''')"""
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
}
|
||||
|
||||
@Issue("#88")
|
||||
def "should generate proper request when body constructed from GString"() {
|
||||
@Unroll
|
||||
def "should generate proper request when body constructed from GString with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -141,18 +223,23 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains(""".body('''property1=VAL1''')""")
|
||||
blockBuilder.toString().contains(bodyString)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | """.body('''property1=VAL1''')"""
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("\\"property1=VAL1\\"")'
|
||||
}
|
||||
|
||||
@Issue("185")
|
||||
def "should generate assertions for a response body containing map with integers as keys"() {
|
||||
@Unroll
|
||||
def "should generate assertions for a response body containing map with integers as keys with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -169,7 +256,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
)
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -177,10 +264,15 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").field(7).isEqualTo(0.0)""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").field(14).isEqualTo(0.0)""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should generate assertions for array in response body"() {
|
||||
@Unroll
|
||||
def "should generate assertions for array in response body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -198,7 +290,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}]"""
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -206,10 +298,15 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property2").isEqualTo("b")""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property1").isEqualTo("a")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should generate assertions for array inside response body element"() {
|
||||
@Unroll
|
||||
def "should generate assertions for array inside response body element with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -226,7 +323,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}"""
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -234,10 +331,15 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property1").contains("property2").isEqualTo("test1")""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property1").contains("property3").isEqualTo("test2")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should generate assertions for nested objects in response body"() {
|
||||
@Unroll
|
||||
def "should generate assertions for nested objects in response body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -254,7 +356,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
'''
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -262,10 +364,15 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").field("property3").isEqualTo("b")""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for map objects in response body"() {
|
||||
@Unroll
|
||||
def "should generate regex assertions for map objects in response body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -283,12 +390,10 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -296,10 +401,15 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}")""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for string objects in response body"() {
|
||||
@Unroll
|
||||
def "should generate regex assertions for string objects in response body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -311,12 +421,10 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
body("""{"property1":"a","property2":"${value(client('123'), server(regex('[0-9]{3}')))}"}""")
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -324,11 +432,16 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}")""")
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue(["#126", "#143"])
|
||||
def "should generate escaped regex assertions for string objects in response body"() {
|
||||
@Unroll
|
||||
def "should generate escaped regex assertions for string objects in response body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -343,17 +456,22 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").matches("\\\\d+")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters"() {
|
||||
@Unroll
|
||||
def "should generate a call with an url path and query parameters with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -383,21 +501,26 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
"""
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('get("/users?limit=10&offset=20&filter=email&sort=name&search=55&age=99&name=Denis.Stepanov&email=bob@email.com")')
|
||||
spockTest.contains('assertThatJson(parsedJson).field("property1").isEqualTo("a")')
|
||||
spockTest.contains('assertThatJson(parsedJson).field("property2").isEqualTo("b")')
|
||||
test.contains('get("/users?limit=10&offset=20&filter=email&sort=name&search=55&age=99&name=Denis.Stepanov&email=bob@email.com")')
|
||||
test.contains('assertThatJson(parsedJson).field("property1").isEqualTo("a")')
|
||||
test.contains('assertThatJson(parsedJson).field("property2").isEqualTo("b")')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
def "should generate a call with an url path and query parameters with url containing a pattern"() {
|
||||
@Unroll
|
||||
def "should generate a call with an url path and query parameters with url containing a pattern with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -427,20 +550,25 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
"""
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('get("/foo/123456?limit=10&offset=20&filter=email&sort=name&search=55&age=99&name=Denis.Stepanov&email=bob@email.com")')
|
||||
spockTest.contains('assertThatJson(parsedJson).field("property1").isEqualTo("a")')
|
||||
spockTest.contains('assertThatJson(parsedJson).field("property2").isEqualTo("b")')
|
||||
test.contains('get("/foo/123456?limit=10&offset=20&filter=email&sort=name&search=55&age=99&name=Denis.Stepanov&email=bob@email.com")')
|
||||
test.contains('assertThatJson(parsedJson).field("property1").isEqualTo("a")')
|
||||
test.contains('assertThatJson(parsedJson).field("property2").isEqualTo("b")')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should generate test for empty body"() {
|
||||
@Unroll
|
||||
def "should generate test for empty body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -452,18 +580,23 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
status 406
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains(".body('''''')")
|
||||
test.contains(bodyString)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | ".body('''''')"
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ".body(\"\\\"\\\"\")"
|
||||
}
|
||||
|
||||
def "should generate test for String in response body"() {
|
||||
@Unroll
|
||||
def "should generate test for String in response body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -475,20 +608,25 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
body "test"
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('def responseBody = (response.body.asString())')
|
||||
spockTest.contains('responseBody == "test"')
|
||||
test.contains(bodyDefinitionString)
|
||||
test.contains(bodyEvaluationString)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (response.getBody().asString());' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
}
|
||||
|
||||
@Issue('113')
|
||||
def "should generate regex test for String in response header"() {
|
||||
@Unroll
|
||||
def "should generate regex test for String in response header with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -511,19 +649,24 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')''')
|
||||
test.contains(headerEvaluationString)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | headerEvaluationString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
}
|
||||
|
||||
@Issue('115')
|
||||
def "should generate regex with helper method"() {
|
||||
@Unroll
|
||||
def "should generate regex with helper method with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -546,18 +689,23 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')''')
|
||||
test.contains(headerEvaluationString)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | headerEvaluationString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
|
||||
}
|
||||
|
||||
def "should work with more complex stuff and jsonpaths"() {
|
||||
@Unroll
|
||||
def "should work with more complex stuff and jsonpaths with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
priority 10
|
||||
@@ -582,19 +730,24 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
])
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains("""assertThatJson(parsedJson).array("errors").contains("property").isEqualTo("bank_account_number")""")
|
||||
spockTest.contains("""assertThatJson(parsedJson).array("errors").contains("message").isEqualTo("incorrect_format")""")
|
||||
test.contains("""assertThatJson(parsedJson).array("errors").contains("property").isEqualTo("bank_account_number")""")
|
||||
test.contains("""assertThatJson(parsedJson).array("errors").contains("message").isEqualTo("incorrect_format")""")
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should work properly with GString url"() {
|
||||
@Unroll
|
||||
def "should work properly with GString url with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
|
||||
@@ -612,18 +765,23 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
status 422
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('''/partners/11/agents/11/customers/09665703Z''')
|
||||
test.contains('''/partners/11/agents/11/customers/09665703Z''')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
def "should resolve properties in GString with regular expression"() {
|
||||
@Unroll
|
||||
def "should resolve properties in GString with regular expression with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
priority 1
|
||||
@@ -649,93 +807,60 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
)
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains("""assertThatJson(parsedJson).field("message").matches("User not found by email = \\\\\\\\[[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\\\\\.[a-zA-Z]{2,4}\\\\\\\\]")""")
|
||||
test.contains("""assertThatJson(parsedJson).field("message").matches("User not found by email = \\\\\\\\[[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\\\\\.[a-zA-Z]{2,4}\\\\\\\\]")""")
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue('42')
|
||||
@Unroll
|
||||
def "should not omit the optional field in the test creation"() {
|
||||
def "should not omit the optional field in the test creation with MockMvcSpockMethodBodyBuilder"() {
|
||||
given:
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('''"email":"abc@abc.com"''')
|
||||
spockTest.contains("""assertThatJson(parsedJson).field("code").matches("(123123)?")""")
|
||||
!spockTest.contains('''REGEXP''')
|
||||
!spockTest.contains('''OPTIONAL''')
|
||||
!spockTest.contains('''OptionalProperty''')
|
||||
test.contains('''"email":"abc@abc.com"''')
|
||||
test.contains("""assertThatJson(parsedJson).field("code").matches("(123123)?")""")
|
||||
!test.contains('''REGEXP''')
|
||||
!test.contains('''OPTIONAL''')
|
||||
!test.contains('''OptionalProperty''')
|
||||
where:
|
||||
contractDsl << [
|
||||
GroovyDsl.make {
|
||||
priority 1
|
||||
request {
|
||||
method 'POST'
|
||||
url '/users/password'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
email: $(stub(optional(regex(email()))), test('abc@abc.com')),
|
||||
callback_url: $(stub(regex(hostname())), test('http://partners.com'))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 404
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
code: value(stub("123123"), test(optional("123123"))),
|
||||
message: "User not found by email = [${value(test(regex(email())), stub('not.existing@user.com'))}]"
|
||||
)
|
||||
}
|
||||
},
|
||||
GroovyDsl.make {
|
||||
priority 1
|
||||
request {
|
||||
method 'POST'
|
||||
url '/users/password'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
""" {
|
||||
"email" : "${value(stub(optional(regex(email()))), test('abc@abc.com'))}",
|
||||
"callback_url" : "${value(client(regex(hostname())), server('http://partners.com'))}"
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 404
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body(
|
||||
""" {
|
||||
"code" : "${value(stub(123123), test(optional(123123)))}",
|
||||
"message" : "User not found by email = [${
|
||||
value(server(regex(email())), client('not.existing@user.com'))
|
||||
}]"
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
]
|
||||
contractDsl << [dslWithOptionals, dslWithOptionalsInString]
|
||||
}
|
||||
|
||||
@Issue('42')
|
||||
@Unroll
|
||||
def "should not omit the optional field in the test creation with MockMvcJUnitMethodBodyBuilder"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('\\"email\\":\\"abc@abc.com\\"')
|
||||
test.contains('assertThatJson(parsedJson).field("code").matches("(123123)?");')
|
||||
!test.contains('''REGEXP''')
|
||||
!test.contains('''OPTIONAL''')
|
||||
!test.contains('''OptionalProperty''')
|
||||
where:
|
||||
contractDsl << [dslWithOptionals, dslWithOptionalsInString]
|
||||
}
|
||||
|
||||
@Issue('72')
|
||||
def "should make the execute method work"() {
|
||||
@Unroll
|
||||
def "should make the execute method work with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -750,7 +875,6 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
)
|
||||
headers {
|
||||
header("""Content-Type""", """application/vnd.fraud.v1+json""")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -762,22 +886,24 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}""")
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''')
|
||||
test.contains(assertionString)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | assertionString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | '''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))'''
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))'''
|
||||
}
|
||||
|
||||
def "should support inner map and list definitions"() {
|
||||
@Unroll
|
||||
def "should support inner map and list definitions with #methodBuilderName"() {
|
||||
given:
|
||||
|
||||
Pattern PHONE_NUMBER = Pattern.compile(/[+\w]*/)
|
||||
@@ -829,19 +955,24 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains '"street":"Light Street"'
|
||||
!spockTest.contains("clientValue")
|
||||
!spockTest.contains("cursor")
|
||||
test.contains bodyString
|
||||
!test.contains("clientValue")
|
||||
!test.contains("cursor")
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | '"street":"Light Street"'
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"street\\":\\"Light Street\\"'
|
||||
|
||||
}
|
||||
|
||||
|
||||
def "shouldn't generate unicode escape characters"() {
|
||||
@Unroll
|
||||
def "shouldn't generate unicode escape characters with #methodBuilderName"() {
|
||||
given:
|
||||
Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/)
|
||||
|
||||
@@ -866,17 +997,22 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
}
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
!spockTest.contains("\\u041f")
|
||||
!test.contains("\\u041f")
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
@Issue('177')
|
||||
def "should generate proper test code when having multiline body"() {
|
||||
@Unroll
|
||||
def "should generate proper test code when having multiline body with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -889,18 +1025,23 @@ World.''')
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains("""'''hello,
|
||||
World.'''""")
|
||||
test.contains(bodyString)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | """'''hello,
|
||||
World.'''"""
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"hello,\\nWorld.\\"'
|
||||
}
|
||||
|
||||
@Issue('180')
|
||||
def "should generate proper test code when having multipart parameters"() {
|
||||
@Unroll
|
||||
def "should generate proper test code when having multipart parameters with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -919,20 +1060,30 @@ World.'''""")
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains("""'content-type', 'multipart/form-data;boundary=AaB03x'""")
|
||||
spockTest.contains(""".param('formParameter', '"formParameterValue"'""")
|
||||
spockTest.contains(""".param('someBooleanParameter', 'true')""")
|
||||
spockTest.contains(""".multiPart('file', 'filename.csv', 'file content'.bytes)""")
|
||||
for (String requestString : requestStrings) {
|
||||
test.contains(requestString)
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) } | ["""'content-type', 'multipart/form-data;boundary=AaB03x'""",
|
||||
""".param('formParameter', '"formParameterValue"'""",
|
||||
""".param('someBooleanParameter', 'true')""",
|
||||
""".multiPart('file', 'filename.csv', 'file content'.bytes)"""]
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['"content-type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes());']
|
||||
}
|
||||
|
||||
@Issue('180')
|
||||
def "should generate proper test code when having multipart parameters with named as map"() {
|
||||
@Unroll
|
||||
def "should generate proper test code when having multipart parameters with named as map with #methodBuilderName"() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
@@ -950,14 +1101,21 @@ World.'''""")
|
||||
status 200
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.given(blockBuilder)
|
||||
def spockTest = blockBuilder.toString()
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
spockTest.contains('.multiPart')
|
||||
test.contains('.multiPart')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { dsl -> new MockMvcSpockMethodBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
}
|
||||
|
||||
|
||||
protected void stubMappingIsValidWireMockStub(GroovyDsl contractDsl) {
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user