diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy
index 24d0eb2845..2382878856 100755
--- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy
+++ b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy
@@ -171,4 +171,70 @@ class DslToWireMockClientConverterSpec extends Specification {
}
''', json, false)
}
+
+ def 'should convert dsl to wiremock to show it in the docs'() {
+ given:
+ def converter = new DslToWireMockClientConverter()
+ and:
+ File file = tmpFolder.newFile("dsl_from_docs.groovy")
+ file.write('''
+ io.codearte.accurest.dsl.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'))}]"
+ )
+ }
+ }
+ ''')
+ when:
+ String json = converter.convertContent("Test", new Contract(file.toPath(), false, 0, null))
+ then:
+ JSONAssert.assertEquals( // tag::wiremock[]
+'''
+{
+ "request" : {
+ "url" : "/users/password",
+ "method" : "POST",
+ "bodyPatterns" : [ {
+ "matchesJsonPath" : "$[?(@.email =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4})?/)]"
+ }, {
+ "matchesJsonPath" : "$[?(@.callback_url =~ /((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?/)]"
+ } ],
+ "headers" : {
+ "Content-Type" : {
+ "equalTo" : "application/json"
+ }
+ }
+ },
+ "response" : {
+ "status" : 404,
+ "body" : "{\\"code\\":\\"123123\\",\\"message\\":\\"User not found by email == [not.existing@user.com]\\"}",
+ "headers" : {
+ "Content-Type" : "application/json"
+ }
+ },
+ "priority" : 1
+}
+'''
+// end::wiremock[]
+ , json, false)
+ }
+
}
diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy
new file mode 100644
index 0000000000..235e8184b5
--- /dev/null
+++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy
@@ -0,0 +1,299 @@
+package io.codearte.accurest.builder
+
+import io.codearte.accurest.dsl.GroovyDsl
+import spock.lang.Specification
+/**
+ * Tests used for the documentation
+ *
+ * @author Marcin Grzejszczak
+ */
+class ContractHttpDocsSpec extends Specification {
+
+ GroovyDsl httpDsl =
+ // tag::http_dsl[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ // Definition of HTTP request part of the contract
+ // (this can be a valid request or invalid depending
+ // on type of contract being specified).
+ request {
+ //...
+ }
+
+ // Definition of HTTP response part of the contract
+ // (a service implementing this contract should respond
+ // with following response after receiving request
+ // specified in "request" part above).
+ response {
+ //...
+ }
+
+ // Contract priority, which can be used for overriding
+ // contracts (1 is highest). Priority is optional.
+ priority 1
+ }
+ // end::http_dsl[]
+
+ GroovyDsl request =
+ // tag::request[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ // HTTP request method (GET/POST/PUT/DELETE).
+ method 'GET'
+
+ // Path component of request URL is specified as follows.
+ urlPath('/users')
+ }
+
+ response {
+ //...
+ }
+ }
+ // end::request[]
+
+ GroovyDsl url =
+ // tag::url[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ method 'GET'
+
+ // Specifying `url` and `urlPath` in one contract is illegal.
+ url('http://localhost:8888/users')
+ }
+
+ response {
+ //...
+ }
+ }
+ // end::url[]
+
+ GroovyDsl urlPaths =
+ // tag::urlpath[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ //...
+
+ urlPath('/users') {
+
+ // Each parameter is specified in form
+ // `'paramName' : paramValue` where parameter value
+ // may be a simple literal or one of matcher functions,
+ // all of which are used in this example.
+ queryParameters {
+
+ // If a simple literal is used as value
+ // default matcher function is used (equalTo)
+ parameter 'limit': 100
+
+ // `equalTo` function simply compares passed value
+ // using identity operator (==).
+ parameter 'filter': equalTo("email")
+
+ // `containing` function matches strings
+ // that contains passed substring.
+ parameter 'gender': value(stub(containing("[mf]")), server('mf'))
+
+ // `matching` function tests parameter
+ // against passed regular expression.
+ parameter 'offset': value(stub(matching("[0-9]+")), server(123))
+
+ // `notMatching` functions tests if parameter
+ // does not match passed regular expression.
+ parameter 'loginStartsWith': value(stub(notMatching(".{0,2}")), server(3))
+ }
+ }
+
+ //...
+ }
+
+ response {
+ //...
+ }
+ }
+ // end::urlpath[]
+
+ GroovyDsl headers =
+ // tag::headers[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ //...
+
+ // Each header is added in form `'Header-Name' : 'Header-Value'`.
+ headers {
+ header 'Content-Type': 'application/json'
+ }
+
+ //...
+ }
+
+ response {
+ //...
+ }
+ }
+ // end::headers[]
+
+ GroovyDsl body =
+ // tag::body[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ //...
+
+ // JSON and XML formats of request body are supported.
+ // Format will be determined from a header or body's content.
+ body '''{ "login" : "john", "name": "John The Contract" }'''
+ }
+
+ response {
+ //...
+ }
+ }
+ // end::body[]
+
+ GroovyDsl bodyAsXml =
+ // tag::bodyAsXml[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ //...
+
+ // In this case body will be formatted as XML.
+ body equalToXml(
+ '''johnJohn The Contract'''
+ )
+ }
+
+ response {
+ //...
+ }
+ }
+ // end::bodyAsXml[]
+
+ GroovyDsl response =
+ // tag::response[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ //...
+ }
+ response {
+ // Status code sent by the server
+ // in response to request specified above.
+ status 200
+ }
+ }
+ // end::response[]
+
+ GroovyDsl regex =
+ // tag::regex[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ method('GET')
+ url $(client(~/\/[0-9]{2}/), server('/12'))
+ }
+ response {
+ status 200
+ body(
+ id: value(
+ client('123'),
+ server(regex('[0-9]+'))
+ ),
+ surname: $(
+ client('Kowalsky'),
+ server('Lewandowski')
+ ),
+ name: 'Jan',
+ created: $(client('2014-02-02 12:23:43'), server(execute('currentDate(it)'))),
+ correlationId: value(client('5d1f9fef-e0dc-4f3d-a7e4-72d2220dd827'),
+ server(regex('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}'))
+ )
+ )
+ headers {
+ header 'Content-Type': 'text/plain'
+ }
+ }
+ }
+ // end::regex[]
+
+ GroovyDsl optionals =
+ // tag::optionals[]
+ io.codearte.accurest.dsl.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'))}]"
+ )
+ }
+ }
+ // end::optionals[]
+
+ def 'should convert dsl with optionals to proper Spock test'() {
+ given:
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
+ new MockMvcSpockMethodRequestProcessingBodyBuilder(optionals).appendTo(blockBuilder)
+ expect:
+ stripped(blockBuilder.toString()) == stripped(
+// tag::optionals_test[]
+"""
+given:
+ def request = given()
+ .header('Content-Type', 'application/json')
+ .body('''{"email":"abc@abc.com","callback_url":"http://partners.com"}''')
+
+when:
+ def response = given().spec(request)
+ .post("/users/password")
+
+then:
+ response.statusCode == 404
+ response.header('Content-Type') == 'application/json'
+and:
+ DocumentContext parsedJson = JsonPath.parse(response.body.asString())
+ assertThatJson(parsedJson).field("message").matches("User not found by email == \\\\\\\\[[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\\\\\.[a-zA-Z]{2,4}\\\\\\\\]")
+ assertThatJson(parsedJson).field("code").matches("(123123)?")
+"""
+// end::optionals_test[]
+)
+ }
+
+ GroovyDsl method =
+ // tag::method[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ method 'PUT'
+ url $(client(regex('^/api/[0-9]{2}$')), server('/api/12'))
+ headers {
+ header 'Content-Type': 'application/json'
+ }
+ body '''\
+ [{
+ "text": "Gonna see you at Warsaw"
+ }]
+ '''
+ }
+ response {
+ body (
+ path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))),
+ correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)')))
+ )
+ status 200
+ }
+ }
+ // end::method[]
+
+ private String stripped(String string) {
+ return string.stripMargin().stripIndent().replace('\t', '').replace('\n', '')
+ }
+}
diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy
index 0485a38d4d..3d36d7676f 100644
--- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy
+++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy
@@ -591,4 +591,74 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
"JaxRsClientJUnitMethodBodyBuilder" | { GroovyDsl dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'method("GET")'
}
+ def "should generate a call with an url path and query parameters with JUnit - we'll put it into docs"() {
+ 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"
+ }
+ """
+ }
+ }
+ MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
+ when:
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
+ then:
+ stripped(test) == stripped( // tag::jaxrs[]
+ '''
+ // when:
+ Response response = webTarget
+ .path("/users")
+ .queryParam("limit", "10")
+ .queryParam("offset", "20")
+ .queryParam("filter", "email")
+ .queryParam("sort", "name")
+ .queryParam("search", "55")
+ .queryParam("age", "99")
+ .queryParam("name", "Denis.Stepanov")
+ .queryParam("email", "bob@email.com")
+ .request()
+ .method("GET");
+
+ String responseAsString = response.readEntity(String.class);
+
+ // then:
+ assertThat(response.getStatus()).isEqualTo(200);
+ // and:
+ DocumentContext parsedJson = JsonPath.parse(responseAsString);
+ assertThatJson(parsedJson).field("property1").isEqualTo("a");
+ assertThatJson(parsedJson).field("property2").isEqualTo("b");
+'''
+// end::jaxrs[]
+)
+ and:
+ stubMappingIsValidWireMockStub(contractDsl)
+ }
+
+ private String stripped(String string) {
+ return string.stripMargin().stripIndent().replace('\t', '').replace('\n', '')
+ }
}
diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy
index 03d70d99ba..eaa303fb52 100644
--- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy
+++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy
@@ -49,8 +49,12 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
}
body(
""" {
- "email" : "${value(stub(optional(regex(email()))), test('abc@abc.com'))}",
- "callback_url" : "${value(client(regex(hostname())), server('http://partners.com'))}"
+ "email" : "${
+ value(stub(optional(regex(email()))), test('abc@abc.com'))
+ }",
+ "callback_url" : "${
+ value(client(regex(hostname())), server('http://partners.com'))
+ }"
}
"""
)
@@ -74,1087 +78,1138 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
def "should generate assertions for simple response body with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- }
- response {
- status 200
- body """{
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
+ }
+ response {
+ status 200
+ body """{
"property1": "a",
"property2": "b"
}"""
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").isEqualTo("b")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").isEqualTo("b")""")
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue("#187")
def "should generate assertions for null and boolean values with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- }
- response {
- status 200
- body """{
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
+ }
+ response {
+ status 200
+ body """{
"property1": "true",
"property2": null,
"property3": false
}"""
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ 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)""")
+ 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(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue("#79")
def "should generate assertions for simple response body constructed from map with a list with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- }
- response {
- status 200
- body(
- property1: 'a',
- property2: [
- [a: 'sth'],
- [b: 'sthElse']
- ]
- )
- }
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ body(
+ property1: 'a',
+ property2: [
+ [a: 'sth'],
+ [b: 'sthElse']
+ ]
+ )
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ 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")""")
+ 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(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue("#82")
def "should generate proper request when body constructed from map with a list #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- body(
- items: ['HOP']
- )
- }
- response {
- status 200
- }
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
+ body(
+ items: ['HOP']
+ )
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains(bodyString)
+ blockBuilder.toString().contains(bodyString)
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder | bodyString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''{\"items\":[\"HOP\"]}''')"""
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
+ methodBuilderName | methodBuilder | bodyString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''{\"items\":[\"HOP\"]}''')"""
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
}
@Issue("#88")
def "should generate proper request when body constructed from GString with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- body(
- "property1=VAL1"
- )
- }
- response {
- status 200
- }
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
+ body(
+ "property1=VAL1"
+ )
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains(bodyString)
+ blockBuilder.toString().contains(bodyString)
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder | bodyString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''property1=VAL1''')"""
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("\\"property1=VAL1\\"")'
+ methodBuilderName | methodBuilder | bodyString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''property1=VAL1''')"""
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("\\"property1=VAL1\\"")'
}
@Issue("185")
def "should generate assertions for a response body containing map with integers as keys with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- }
- response {
- status 200
- body(
- property: [
- 14: 0.0,
- 7 : 0.0
- ]
- )
- }
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ body(
+ property: [
+ 14: 0.0,
+ 7 : 0.0
+ ]
+ )
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ 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)""")
+ 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(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should generate assertions for array in response body with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- }
- response {
- status 200
- body """[
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
+ }
+ response {
+ status 200
+ body """[
{
"property1": "a"
},
{
"property2": "b"
}]"""
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property2").isEqualTo("b")""")
- blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property1").isEqualTo("a")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property2").isEqualTo("b")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).array().contains("property1").isEqualTo("a")""")
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should generate assertions for array inside response body element with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- }
- response {
- status 200
- body """{
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
+ }
+ response {
+ status 200
+ body """{
"property1": [
{ "property2": "test1"},
{ "property3": "test2"}
]
}"""
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ 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")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property1").contains("property2").isEqualTo("test1")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).array("property1").contains("property3").isEqualTo("test2")""")
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should generate assertions for nested objects in response body with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- url "test"
- }
- response {
- status 200
- body '''\
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ url "test"
+ }
+ response {
+ status 200
+ body '''\
{
"property1": "a",
"property2": {"property3": "b"}
}
'''
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").field("property3").isEqualTo("b")""")
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").field("property3").isEqualTo("b")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should generate regex assertions for map objects in response body with #methodBuilderName"() {
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')
- }
+ 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')
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}")""")
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should generate regex assertions for string objects in response body with #methodBuilderName"() {
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')
- }
+ 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')
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}")""")
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property2").matches("[0-9]{3}")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property1").isEqualTo("a")""")
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue(["#126", "#143"])
def "should generate escaped regex assertions for string objects in response body with #methodBuilderName"() {
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')
- }
+ 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')
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
+ builder.appendTo(blockBuilder)
then:
- blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").matches("\\\\d+")""")
+ blockBuilder.toString().contains("""assertThatJson(parsedJson).field("property").matches("\\\\d+")""")
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should generate a call with an url path and query parameters with #methodBuilderName"() {
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()
- }
+ 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 """
+ }
+ response {
+ status 200
+ body """
{
"property1": "a",
"property2": "b"
}
"""
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- 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")')
+ 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(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue('#169')
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 {
- 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()
- }
+ 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 """
+ }
+ response {
+ status 200
+ body """
{
"property1": "a",
"property2": "b"
}
"""
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- 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")')
+ 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(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should generate test for empty body with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method('POST')
- url("/ws/payments")
- body("")
- }
- response {
- status 406
- }
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method('POST')
+ url("/ws/payments")
+ body("")
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 406
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains(bodyString)
+ test.contains(bodyString)
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder | bodyString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ".body('''''')"
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ".body(\"\\\"\\\"\")"
+ methodBuilderName | methodBuilder | bodyString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ".body('''''')"
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ".body(\"\\\"\\\"\")"
}
def "should generate test for String in response body with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "POST"
- url "test"
- }
- response {
- status 200
- body "test"
- }
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "POST"
+ url "test"
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ body "test"
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains(bodyDefinitionString)
- test.contains(bodyEvaluationString)
+ test.contains(bodyDefinitionString)
+ test.contains(bodyEvaluationString)
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (response.getBody().asString());' | 'assertThat(responseBody).isEqualTo("test");'
+ methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl 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 with #methodBuilderName"() {
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]+')))
- }
+ 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]+')))
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains(headerEvaluationString)
+ test.contains(headerEvaluationString)
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder | headerEvaluationString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
+ methodBuilderName | methodBuilder | headerEvaluationString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl 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 with #methodBuilderName"() {
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]+")))
- }
+ 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]+")))
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains(headerEvaluationString)
+ test.contains(headerEvaluationString)
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder | headerEvaluationString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
+ methodBuilderName | methodBuilder | headerEvaluationString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl 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 with #methodBuilderName"() {
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"]
- ])
+ 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'
+ )
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+
+ response {
+ status 200
+ body(errors: [
+ [property: "bank_account_number", message: "incorrect_format"]
+ ])
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains("""assertThatJson(parsedJson).array("errors").contains("property").isEqualTo("bank_account_number")""")
- test.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(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should work properly with GString url with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
+ 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
+ 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',
+ )
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 422
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains('''/partners/11/agents/11/customers/09665703Z''')
+ test.contains('''/partners/11/agents/11/customers/09665703Z''')
and:
- stubMappingIsValidWireMockStub(contractDsl)
+ stubMappingIsValidWireMockStub(contractDsl)
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should resolve properties in GString with regular expression with #methodBuilderName"() {
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'))}]"
- )
+ 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'))
+ )
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ 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'))}]"
+ )
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- 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}\\\\\\\\]")""")
+ 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" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue('42')
def "should not omit the optional field in the test creation with MockMvcSpockMethodBodyBuilder"() {
given:
- MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ 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''')
+ 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]
+ contractDsl << [dslWithOptionals, dslWithOptionalsInString]
}
@Issue('42')
def "should not omit the optional field in the test creation with MockMvcJUnitMethodBodyBuilder"() {
given:
- MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ 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''')
+ 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]
+ contractDsl << [dslWithOptionals, dslWithOptionalsInString]
}
@Issue('72')
def "should make the execute method work with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method """PUT"""
- url """/fraudcheck"""
- body("""
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method """PUT"""
+ url """/fraudcheck"""
+ body("""
{
- "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
+ "clientPesel":"${
+ value(client(regex('[0-9]{10}')), server('1234567890'))
+ }",
"loanAmount":123.123
}
"""
- )
- headers {
- header("""Content-Type""", """application/vnd.fraud.v1+json""")
- }
-
+ )
+ headers {
+ header("""Content-Type""", """application/vnd.fraud.v1+json""")
}
- response {
- status 200
- body("""{
+
+ }
+ response {
+ status 200
+ body("""{
"fraudCheckStatus": "OK",
- "rejectionReason": ${value(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))}
+ "rejectionReason": ${
+ value(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
+ }
}""")
- headers {
- header('Content-Type': 'application/vnd.fraud.v1+json')
- header 'Location': value(
+ headers {
+ header('Content-Type': 'application/vnd.fraud.v1+json')
+ header 'Location': value(
stub(null),
test(execute('assertThatLocationIsNull($it)'))
- )
- }
+ )
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- String test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ String test = blockBuilder.toString()
then:
- assertionStrings.each { String assertionString ->
- assert test.contains(assertionString)
- }
+ assertionStrings.each { String assertionString ->
+ assert test.contains(assertionString)
+ }
where:
- methodBuilderName | methodBuilder | assertionStrings
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''', '''assertThatLocationIsNull(response.header('Location'))''']
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
+ methodBuilderName | methodBuilder | assertionStrings
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''', '''assertThatLocationIsNull(response.header('Location'))''']
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
}
def "should support inner map and list definitions with #methodBuilderName"() {
given:
- Pattern PHONE_NUMBER = Pattern.compile(/[+\w]*/)
- Pattern ANYSTRING = Pattern.compile(/.*/)
- Pattern NUMBERS = Pattern.compile(/[\d\.]*/)
- Pattern DATETIME = ANYSTRING
+ 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'))
- ]
- )
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "PUT"
+ url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/client_data"
+ headers {
+ header('Content-Type': 'application/json')
}
- response {
- status 200
- 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')
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains bodyString
- !test.contains("clientValue")
- !test.contains("cursor")
+ test.contains bodyString
+ !test.contains("clientValue")
+ !test.contains("cursor")
where:
- methodBuilderName | methodBuilder | bodyString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '"street":"Light Street"'
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"street\\":\\"Light Street\\"'
+ methodBuilderName | methodBuilder | bodyString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '"street":"Light Street"'
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"street\\":\\"Light Street\\"'
}
def "shouldn't generate unicode escape characters with #methodBuilderName"() {
given:
- Pattern ONLY_ALPHA_UNICODE = Pattern.compile(/[\p{L}]*/)
+ 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('Пенева'))
- ]
- )
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "PUT"
+ url "/v1/payments/e86df6f693de4b35ae648464c5b0dc09/енев"
+ headers {
+ header('Content-Type': 'application/json')
}
- response {
- status 200
- 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')
}
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- !test.contains("\\u041f")
+ !test.contains("\\u041f")
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue('177')
def "should generate proper test code when having multiline body with #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "PUT"
- url "/multiline"
- body('''hello,
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "PUT"
+ url "/multiline"
+ body('''hello,
World.''')
- }
- response {
- status 200
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.given(blockBuilder)
- def test = blockBuilder.toString()
+ builder.given(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains(bodyString)
+ test.contains(bodyString)
where:
- methodBuilderName | methodBuilder | bodyString
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """'''hello,
+ methodBuilderName | methodBuilder | bodyString
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """'''hello,
World.'''"""
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"hello,\\nWorld.\\"'
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"hello,\\nWorld.\\"'
}
@Issue('180')
def "should generate proper test code when having multipart parameters with #methodBuilderName"() {
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
+ 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')))
+ )
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- for (String requestString : requestStrings) {
- test.contains(requestString)
- }
+ for (String requestString : requestStrings) {
+ test.contains(requestString)
+ }
where:
- methodBuilderName | methodBuilder | requestStrings
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""'content-type', 'multipart/form-data;boundary=AaB03x'""",
- """.param('formParameter', '"formParameterValue"'""",
- """.param('someBooleanParameter', 'true')""",
- """.multiPart('file', 'filename.csv', 'file content'.bytes)"""]
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['"content-type", "multipart/form-data;boundary=AaB03x"',
- '.param("formParameter", "\\"formParameterValue\\"")',
- '.param("someBooleanParameter", "true")',
- '.multiPart("file", "filename.csv", "file content".getBytes());']
+ methodBuilderName | methodBuilder | requestStrings
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""'content-type', 'multipart/form-data;boundary=AaB03x'""",
+ """.param('formParameter', '"formParameterValue"'""",
+ """.param('someBooleanParameter', 'true')""",
+ """.multiPart('file', 'filename.csv', 'file content'.bytes)"""]
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl 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 with #methodBuilderName"() {
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
- }
+ 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')))
+ )
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.given(blockBuilder)
- def test = blockBuilder.toString()
+ builder.given(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains('.multiPart')
+ test.contains('.multiPart')
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
@Issue('#216')
def "should parse JSON with arrays using #methodBuilderName"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method "GET"
- urlPath('/auth/oauth/check_token') {
- queryParameters {
- parameter 'token':
- value(
- client(regex('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')),
- server('6973b31d-7140-402a-bca6-1cdb954e03a7')
- )
- }
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method "GET"
+ urlPath('/auth/oauth/check_token') {
+ queryParameters {
+ parameter 'token':
+ value(
+ client(regex('^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')),
+ server('6973b31d-7140-402a-bca6-1cdb954e03a7')
+ )
}
}
- response {
- status 200
- body(
- authorities: [
- value(stub('ROLE_ADMIN'), test(regex('^[a-zA-Z0-9_\\- ]+$')))
- ]
- )
- }
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ body(
+ authorities: [
+ value(stub('ROLE_ADMIN'), test(regex('^[a-zA-Z0-9_\\- ]+$')))
+ ]
+ )
+ }
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- test.contains('''assertThatJson(parsedJson).array("authorities").matches("^[a-zA-Z0-9_\\\\- ]+\\$").value()''')
+ test.contains('''assertThatJson(parsedJson).array("authorities").matches("^[a-zA-Z0-9_\\\\- ]+\\$").value()''')
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
def "should work with execution property"() {
given:
- GroovyDsl contractDsl = GroovyDsl.make {
- request {
- method 'PUT'
- url '/fraudcheck'
- }
- response {
- status 200
- body(
- fraudCheckStatus: "OK",
- rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
- )
- }
-
+ GroovyDsl contractDsl = GroovyDsl.make {
+ request {
+ method 'PUT'
+ url '/fraudcheck'
}
- MethodBodyBuilder builder = methodBuilder(contractDsl)
- BlockBuilder blockBuilder = new BlockBuilder(" ")
+ response {
+ status 200
+ body(
+ fraudCheckStatus: "OK",
+ rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
+ )
+ }
+
+ }
+ MethodBodyBuilder builder = methodBuilder(contractDsl)
+ BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
- builder.appendTo(blockBuilder)
- def test = blockBuilder.toString()
+ builder.appendTo(blockBuilder)
+ def test = blockBuilder.toString()
then:
- !test.contains('''assertThatJson(parsedJson).field("rejectionReason").isEqualTo("assertThatRejectionReasonIsNull("''')
- test.contains('''assertThatRejectionReasonIsNull(''')
+ !test.contains('''assertThatJson(parsedJson).field("rejectionReason").isEqualTo("assertThatRejectionReasonIsNull("''')
+ test.contains('''assertThatRejectionReasonIsNull(''')
where:
- methodBuilderName | methodBuilder
- "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
- "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
+ methodBuilderName | methodBuilder
+ "MockMvcSpockMethodBuilder" | { GroovyDsl dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
+ "MockMvcJUnitMethodBuilder" | { GroovyDsl dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
}
-
-
-}
+ GroovyDsl dslForDocs =
+ // tag::dsl_example[]
+ io.codearte.accurest.dsl.GroovyDsl.make {
+ request {
+ method 'PUT'
+ url '/api/12'
+ headers {
+ header 'Content-Type': 'application/vnd.com.ofg.twitter-places-analyzer.v1+json'
+ }
+ body '''\
+ [{
+ "created_at": "Sat Jul 26 09:38:57 +0000 2014",
+ "id": 492967299297845248,
+ "id_str": "492967299297845248",
+ "text": "Gonna see you at Warsaw",
+ "place":
+ {
+ "attributes":{},
+ "bounding_box":
+ {
+ "coordinates":
+ [[
+ [-77.119759,38.791645],
+ [-76.909393,38.791645],
+ [-76.909393,38.995548],
+ [-77.119759,38.995548]
+ ]],
+ "type":"Polygon"
+ },
+ "country":"United States",
+ "country_code":"US",
+ "full_name":"Washington, DC",
+ "id":"01fbe706f872cb32",
+ "name":"Washington",
+ "place_type":"city",
+ "url": "http://api.twitter.com/1/geo/id/01fbe706f872cb32.json"
+ }
+ }]
+ '''
+ }
+ response {
+ status 200
+ }
+ }
+ // end::dsl_example[]
+ }
\ No newline at end of file
diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy
index 37f40e1ba9..4e94ba6525 100644
--- a/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy
+++ b/accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy
@@ -4,6 +4,7 @@ import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc
import com.ofg.twitter.place.PairIdController
import spock.lang.Specification
+// tag::base_class[]
abstract class BaseMockMvcSpec extends Specification {
def setup() {
@@ -19,3 +20,4 @@ abstract class BaseMockMvcSpec extends Specification {
}
}
+// end::base_class[]
diff --git a/docs/src/docs/asciidoc/contract.adoc b/docs/src/docs/asciidoc/contract.adoc
index 7e2d7f7c97..000082923e 100644
--- a/docs/src/docs/asciidoc/contract.adoc
+++ b/docs/src/docs/asciidoc/contract.adoc
@@ -1,65 +1,28 @@
== Contract DSL
-Contract DSL in Accurest is written in Groovy, but don't be alarmed if you didn't use Groovy before. Knowledge of the language is not really needed as our DSL uses only a tiny subset of it (namely literals, method calls and closures). What's more, Accurest's DSL is designed to be programmer-readable without any knowledge of the DSL itself.
+Contract DSL in Accurest is written in Groovy, but don't be alarmed if you didn't use Groovy before. Knowledge of the language is not really needed as our DSL uses only
+a tiny subset of it (namely literals, method calls and closures). What's more, Accurest's DSL is designed to be programmer-readable without any knowledge of the DSL itself -
+ it's statically typed.
Let's look at full example of a contract definition.
+
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- method 'POST'
- urlPath('/users') {
- queryParameters {
- parameter 'limit': 100
- parameter 'offset': containing("1")
- parameter 'filter': "email"
- }
- }
- headers {
- header 'Content-Type': 'application/json'
- }
- body '''{ "login" : "john", "name": "John The Contract" }'''
- }
- response {
- status 200
- headers {
- header 'Location': '/users/john'
- }
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcMethodBodyBuilderSpec.groovy[tags=dsl_example,indent=0]
----
Not all features of the DSL are used in example above. If you didn't find what you are looking for, please check next paragraphs on this page.
> You can easily compile Accurest Contracts to WireMock stubs mapping using standalone maven command: `mvn io.codearte.accurest:accurest-maven-plugin:convert`.
-=== Top-Level Elements
+=== HTTP Top-Level Elements
Following methods can be called in the top-level closure of a contract definition. Request and response are mandatory, priority is optional.
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- // Definition of HTTP request part of the contract
- // (this can be a valid request or invalid depending
- // on type of contract being specified).
- request {
- ...
- }
-
- // Definition of HTTP response part of the contract
- // (a service implementing this contract should respond
- // with following response after receiving request
- // specified in "request" part above).
- response {
- ...
- }
-
- // Contract priority, which can be used for overriding
- // contracts (1 is highest). Priority is optional.
- priority 1
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=http_dsl,indent=0]
----
=== Request
@@ -68,145 +31,43 @@ HTTP protocol requires only **method and address** to be specified in a request.
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- // HTTP request method (GET/POST/PUT/DELETE).
- method 'GET'
-
- // Path component of request URL is specified as follows.
- urlPath('/users')
- }
-
- response {
- ...
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=request,indent=0]
----
It is possible to specify whole `url` instead of just path, but `urlPath` is the recommended way as it makes the tests **host-independent**.
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- method 'GET'
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=url,indent=0]
- // Specifying `url` and `urlPath` in one contract is illegal.
- url('http://localhost:8888/users')
- }
-
- response {
- ...
- }
-}
----
Request may contain **query parameters**, which are specified in a closure nested in a call to `urlPath` or `url`.
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- ...
-
- urlPath('/users') {
-
- // Each parameter is specified in form
- // `'paramName' : paramValue` where parameter value
- // may be a simple literal or one of matcher functions,
- // all of which are used in this example.
- queryParameters {
-
- // If a simple literal is used as value
- // default matcher function is used (equalTo)
- parameter 'limit': 100
-
- // `equalTo` function simply compares passed value
- // using identity operator (==).
- parameter 'filter': equalTo("email")
-
- // `containing` function matches strings
- // that contains passed substring.
- parameter 'gender': containing("[mf]")
-
- // `matching` function tests parameter
- // against passed regular expression.
- parameter 'offset': matching("[0-9]+")
-
- // `notMatching` functions tests if parameter
- // does not match passed regular expression.
- parameter 'loginStartsWith': notMatching(".{0,2}")
- }
- }
-
- ...
- }
-
- response {
- ...
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=urlpath,indent=0]
----
It may contain additional **request headers**...
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- ...
-
- // Each header is added in form `'Header-Name' : 'Header-Value'`.
- headers {
- header 'Content-Type': 'application/json'
- }
-
- ...
- }
-
- response {
- ...
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=headers,indent=0]
----
...and a **request body**.
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- ...
-
- // JSON and XML formats of request body are supported.
- // Format will be determined from a header or body's content.
- body '''{ "login" : "john", "name": "John The Contract" }'''
- }
-
- response {
- ...
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=body,indent=0]
----
**Body's format** can also be specified explicitly by invoking one of format functions.
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- ...
-
- // In this case body will be formatted as XML.
- body equalToXml(
- '''johnJohn The Contract'''
- )
- }
-
- response {
- ...
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=bodyAsXml,indent=0]
----
=== Response
@@ -215,54 +76,21 @@ Minimal response must contain **HTTP status code**.
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- ...
- }
- response {
- // Status code sent by the server
- // in response to request specified above.
- status 200
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=response,indent=0]
----
Besides status response may contain **headers** and **body**, which are specified the same way as in the request (see previous paragraph).
=== Regular expressions
-You can use regular expressions to write your requests in Contract DSL. It is particularly useful when you want to indicate that a given response should be provided for requests that follow a given pattern. Also, you can use it when you need to use patterns and not exact values both for your test and your server side tests.
+You can use regular expressions to write your requests in Contract DSL. It is particularly useful when you want to indicate that a given response
+should be provided for requests that follow a given pattern. Also, you can use it when you need to use patterns and not exact values both
+for your test and your server side tests.
- Please see the example below:
+Please see the example below:
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl groovyDsl == GroovyDsl.make {
- request {
- method('GET')
- url $(client(~/\/[0-9]{2}/), server('/12'))
- }
- response {
- status 200
- body(
- id: value(
- client('123'),
- server(regex('[0-9]+'))
- ),
- surname: $(
- client('Kowalsky'),
- server('Lewandowski')
- ),
- name: 'Jan',
- created: $(client('2014-02-02 12:23:43'), server({ currentDate(it) }))
- correlationId: value(client('5d1f9fef-e0dc-4f3d-a7e4-72d2220dd827'),
- server(regex('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')
- )
- )
- headers {
- header 'Content-Type': 'text/plain'
- }
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=regex,indent=0]
----
=== Passing optional parameters
@@ -276,131 +104,41 @@ Example:
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.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'))}]"
- )
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=optionals,indent=0]
----
By wrapping a part of the body with the `optional()` method you are in fact creating a regular expression that should be present 0 or more times.
-That way for the example above the following test would be generated:
+That way for the example above the following test would be generated if you pick Spock:
[source,groovy,indent=0]
----
- given:
- def request == given()
- .header('Content-Type', 'application/json')
- .body('{"email":"abc@abc.com","callback_url":"http://partners.com"}')
-
- when:
- def response == given().spec(request)
- .post("/users/password")
-
- then:
- response.statusCode === 404
- response.header('Content-Type') === 'application/json'
- and:
- DocumentContext parsedJson == JsonPath.parse(response.body.asString())
- !parsedJson.read('''$[?(@.code =~ /(123123)?/)]''', JSONArray).empty
- !parsedJson.read('''$[?(@.message =~ /User not found by email == \\[[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}\\]/)]''', JSONArray).empty
-
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=optionals_test,indent=0]
----
and the following stub:
[source,javascript,indent=0]
----
-{
- "request" : {
- "url" : "/users/password",
- "method" : "POST",
- "bodyPatterns" : [ {
- "matchesJsonPath" : "$[?(@.callback_url =~ /((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/)]"
- }, {
- "matchesJsonPath" : "$[?(@.email =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4})?/)]"
- } ],
- "headers" : {
- "Content-Type" : {
- "equalTo" : "application/json"
- }
- }
- },
- "response" : {
- "status" : 404,
- "body" : "{\"code\":\"123123\",\"message\":\"User not found by email == [not.existing@user.com]\"}",
- "headers" : {
- "Content-Type" : "application/json"
- }
- },
- "priority" : 1
-}
+include::../../../../accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy[tags=wiremock,indent=0]
----
=== Executing custom methods on server side
-It is also possible to define a method call to be executed on the server side during the test. Such a method can be added to the class defined as "baseClassForTests" in the configuration. Please see the examples below:
+It is also possible to define a method call to be executed on the server side during the test. Such a method can be added to the class defined as "baseClassForTests"
+in the configuration. Please see the examples below:
==== Groovy DSL
[source,groovy,indent=0]
----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- method 'PUT'
- url $(client(regex('^/api/[0-9]{2}$')), server('/api/12'))
- headers {
- header 'Content-Type': 'application/json'
- }
- body '''\
- [{
- "text": "Gonna see you at Warsaw"
- }]
-'''
- }
- response {
- body (
- path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))),
- correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)')))
- )
- status 200
- }
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/ContractHttpDocsSpec.groovy[tags=method,indent=0]
----
==== Base Mock Spec
[source,groovy,indent=0]
----
-abstract class BaseMockMvcSpec extends Specification {
-
- def setup() {
- RestAssuredMockMvc.standaloneSetup(new PairIdController())
- }
-
- void isProperCorrelationId(Integer correlationId) {
- assert correlationId === 123456
- }
-}
+include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/bootSimple/src/test/groovy/com/ofg/twitter/places/BaseMockMvcSpec.groovy[tags=base_class,indent=0]
----
=== JAX-RS support
@@ -419,43 +157,5 @@ Example of a test API generated:
[source,groovy,indent=0]
----
-class FraudDetectionServiceSpec extends MvcSpec {
-
- def shouldMarkClientAsNotFraud() {
- when:
- def response == webTarget
- .path('/fraudcheck')
- .request()
- .method('put', entity('{"clientPesel":"1234567890","loanAmount":123.123}', 'application/vnd.fraud.v1+json'))
-
- String responseAsString == response.readEntity(String)
-
- then:
- response.status === 200
- response.getHeaderString('Content-Type') === 'application/vnd.fraud.v1+json'
- and:
- def responseBody == new JsonSlurper().parseText(responseAsString)
- responseBody.fraudCheckStatus === "OK"
- assertThatRejectionReasonIsNull(responseBody.rejectionReason)
- }
-
- def shouldMarkClientAsFraud() {
- when:
- def response == webTarget
- .path('/fraudcheck')
- .request()
- .method('put', entity('{"clientPesel":"1234567890","loanAmount":99999}', 'application/vnd.fraud.v1+json'))
-
- String responseAsString == response.readEntity(String)
-
- then:
- response.status === 200
- response.getHeaderString('Content-Type') === 'application/vnd.fraud.v1+json'
- and:
- def responseBody == new JsonSlurper().parseText(responseAsString)
- responseBody.fraudCheckStatus ==~ java.util.regex.Pattern.compile('[A-Z]{5}')
- responseBody.rejectionReason === "Amount too high"
- }
-
-}
+include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientMethodBuilderSpec.groovy[tags=jaxrs,indent=0]
----
\ No newline at end of file
diff --git a/docs/src/docs/asciidoc/images/Deps.png b/docs/src/docs/asciidoc/images/Deps.png
new file mode 100644
index 0000000000..1426814308
Binary files /dev/null and b/docs/src/docs/asciidoc/images/Deps.png differ
diff --git a/docs/src/docs/asciidoc/images/Stubs1.png b/docs/src/docs/asciidoc/images/Stubs1.png
new file mode 100644
index 0000000000..ebadfdb910
Binary files /dev/null and b/docs/src/docs/asciidoc/images/Stubs1.png differ
diff --git a/docs/src/docs/asciidoc/images/Stubs2.png b/docs/src/docs/asciidoc/images/Stubs2.png
new file mode 100644
index 0000000000..e4bad24987
Binary files /dev/null and b/docs/src/docs/asciidoc/images/Stubs2.png differ
diff --git a/docs/src/docs/asciidoc/index.adoc b/docs/src/docs/asciidoc/index.adoc
index a1d3a7eb8b..060f611643 100644
--- a/docs/src/docs/asciidoc/index.adoc
+++ b/docs/src/docs/asciidoc/index.adoc
@@ -2,36 +2,14 @@ Welcome to the Accurest Documentation!
include::introduction.adoc[]
-include::rest.adoc[]
-
include::contract.adoc[]
+include::rest.adoc[]
+
include::messaging.adoc[]
include::stubrunner.adoc[]
include::stubrunner_msg.adoc[]
-== Migration Guide
-
-=== Migration to 0.4.7
-- in 0.4.7 we've fixed package name (coderate to codearte) so you've to do the same in your projects. This means replacing ```io.coderate.accurest.dsl.GroovyDsl``` with ```io.codearte.accurest.dsl.GroovyDsl```
-
-=== Migration to 1.0.0-RC1
-- from 1.0.0 we're distinguish ignored contracts from excluded contracts:
- - `excludedFiles` pattern tells Accurest to skip processing those files at all
- - `ignoredFiles` pattern tells Accurest to generate contracts and tests, but tests will be marked as `@Ignore`
-
-- from 1.0.0 the `basePackageForTests` behaviour has changed
- - prior to the change all DSL files had to be under `contractsDslDir`/`basePackageForTests`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation
- - now all DSL files have to be under `contractsDslDir`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation
- - If you don't migrate to the new approach you will have your tests under `contractsDslDir`.`contractsDslDir`.*subpackage*
-
-=== Migration to 1.0.7
-- from 1.0.7 we're setting JUnit as a default testing utility. You have to pass the following option to keep Spock
-as your first choice:
-
-[source,groovy]
-----
-include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=target_framework,indent=0]
-----
\ No newline at end of file
+include::migration.adoc[]
\ No newline at end of file
diff --git a/docs/src/docs/asciidoc/introduction.adoc b/docs/src/docs/asciidoc/introduction.adoc
index 6714efb910..f7ac2b0c17 100644
--- a/docs/src/docs/asciidoc/introduction.adoc
+++ b/docs/src/docs/asciidoc/introduction.adoc
@@ -1,26 +1,80 @@
== Introduction
-Just to make long story short - Accurest is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped with __REST Contract Definition Language__ (DSL). Contract definitions are used by Accurest to produce following resources:
+Just to make long story short - Accurest is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped
+with __Contract Definition Language__ (DSL). Contract definitions are used by Accurest to produce following resources:
-* JSON stub definitions to be used by Wiremock when doing integration testing on the client code (__client tests__). Test code must still be written by hand, test data is produced by Accurest.
-* Acceptance tests (in Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__). Full test is generated by Accurest.
+* JSON stub definitions to be used by Wiremock when doing integration testing on the client code (__client tests__).
+Test code must still be written by hand, test data is produced by Accurest.
+* Messaging routes if you're using one. We're integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to
+* Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__). Full test is generated by Accurest.
Accurest moves TDD to the level of software architecture.
=== Why?
-The main purposes of Accurest are:
+Let us assume that we have a system comprising of multiple microservices:
- - to ensure that WireMock stubs (used when developing the client) are doing exactly what actual server-side implementation will do,
+image::Deps.png[Microservices Architecture]
+
+==== Testing issues
+
+If we wanted to test the application in top left corner if it can communicate with other services then we could do one of two things:
+
+- deploy all microservices and perform end to end tests
+- mock other microservices in unit / integration tests
+
+Both have their advantages but also a lot of disadvantages. Let's focus on the latter.
+
+*Deploy all microservices and perform end to end tests*
+
+Advantages:
+- simulates production
+- tests real communication between services
+
+Disadvantages:
+- to test one microservice we would have to deploy 6 microservices, a couple of databases etc.
+- the environment where the tests would be conducted would be locked for a single suite of tests (i.e. nobody else would be able to run the tests in the meantime).
+- long to run
+- very late feedback
+- extremely hard to debug
+
+*Mock other microservices in unit / integration tests*
+
+Advantages:
+- very fast feedback
+- no infrastructure requirements
+
+Disadvantages:
+- the implementor of the service creates stubs thus they might have nothing to do with the reality
+- you can go to production with passing tests and failing production
+
+To solve the aforementioned issues Accurest with Stub Runner were created. Their main idea is to give you very fast feedback, without the need
+to set up the whole world of microservices.
+
+image::Stubs1.png[Stubbed Services]
+
+If you work on stubs then the only applications you need are those that your application is using directly.
+
+image::Stubs2.png[Stubbed Services]
+
+Accurest gives you the certainty that the stubs that you're using were created by the service that you're calling. Also if you can use them it means that they were
+tested against the producer's side. In other words - you can trust those stubs.
+
+
+=== Purposes
+
+The main purposes of Accurest with Stub Runner are:
+
+ - to ensure that WireMock / Messaging stubs (used when developing the client) are doing exactly what actual server-side implementation will do,
- to promote ATDD method and Microservices architectural style,
- to provide a way to publish changes in contracts that are immediately visible on both sides,
- to generate boilerplate test code used on the server side.
=== Client Side
-During the tests you want to have a Wiremock instance up and running that simulates the service Y.
+During the tests you want to have a Wiremock instance / Messaging route up and running that simulates the service Y.
You would like to feed that instance with a proper stub definition. That stub definition would need
-to be valid from the Wiremock's perspective but should also be reusable on the server side.
+to be valid and should also be reusable on the server side.
__Summing it up:__ On this side, in the stub definition, you can use patterns for request stubbing and you need exact
values for responses.
@@ -37,52 +91,20 @@ that your application behaves in the same way as you define in your stub.
__Summing it up:__ On this side, in the stub definition, you need exact values as request and can use patterns/methods
for response verification.
-=== Examples
+=== Dependencies
-[source,groovy,indent=0]
-----
-io.codearte.accurest.dsl.GroovyDsl.make {
- request {
- method 'PUT'
- url '/api/12'
- headers {
- header 'Content-Type': 'application/vnd.com.ofg.twitter-places-analyzer.v1+json'
- }
- body '''\
- [{
- "created_at": "Sat Jul 26 09:38:57 +0000 2014",
- "id": 492967299297845248,
- "id_str": "492967299297845248",
- "text": "Gonna see you at Warsaw",
- "place":
- {
- "attributes":{},
- "bounding_box":
- {
- "coordinates":
- [[
- [-77.119759,38.791645],
- [-76.909393,38.791645],
- [-76.909393,38.995548],
- [-77.119759,38.995548]
- ]],
- "type":"Polygon"
- },
- "country":"United States",
- "country_code":"US",
- "full_name":"Washington, DC",
- "id":"01fbe706f872cb32",
- "name":"Washington",
- "place_type":"city",
- "url": "http://api.twitter.com/1/geo/id/01fbe706f872cb32.json"
- }
- }]
-'''
- }
- response {
- status 200
- }
-}
-----
+Accurest and Stub Runner are using the following libraries
-//TODO: Add videos, slides
\ No newline at end of file
+- http://wiremock.org/[WireMock]
+- https://github.com/jayway/JsonPath[Jayway JSONPath]
+- https://github.com/marcingrzejszczak/jsonassert[JSONAssert from Marcin Grzejszczak]
+
+=== Additional readings / videos
+
+Below you can find some resources related to Accurest and Stub Runner. Note that some can be outdated since the Accurest project
+is under constant development.
+
+- https://www.youtube.com/watch?v=daafmTYFoDU[Olga Maciaszek-Sharma talking about Accurest]
+- https://vimeo.com/130779882[Marcin Grzejszczak and Jakub Kubrynski talking about Accurest]
+- http://www.slideshare.net/MarcinGrzejszczak/stick-to-the-rules-consumer-driven-contracts-201507-confitura[Slides from Marcin Grzejszczak's talk about Accurest]
+- http://toomuchcoding.com/blog/categories/accurest/[Accurest article from Marcin Grzejszczak's blog]
diff --git a/docs/src/docs/asciidoc/migration.adoc b/docs/src/docs/asciidoc/migration.adoc
new file mode 100644
index 0000000000..8ddc214619
--- /dev/null
+++ b/docs/src/docs/asciidoc/migration.adoc
@@ -0,0 +1,23 @@
+== Migration Guide
+
+=== Migration to 0.4.7
+- in 0.4.7 we've fixed package name (coderate to codearte) so you've to do the same in your projects. This means replacing ```io.coderate.accurest.dsl.GroovyDsl``` with ```io.codearte.accurest.dsl.GroovyDsl```
+
+=== Migration to 1.0.0-RC1
+- from 1.0.0 we're distinguish ignored contracts from excluded contracts:
+ - `excludedFiles` pattern tells Accurest to skip processing those files at all
+ - `ignoredFiles` pattern tells Accurest to generate contracts and tests, but tests will be marked as `@Ignore`
+
+- from 1.0.0 the `basePackageForTests` behaviour has changed
+ - prior to the change all DSL files had to be under `contractsDslDir`/`basePackageForTests`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation
+ - now all DSL files have to be under `contractsDslDir`/*subpackage* resulting in `basePackageForTests`.*subpackage* test package creation
+ - If you don't migrate to the new approach you will have your tests under `contractsDslDir`.`contractsDslDir`.*subpackage*
+
+=== Migration to 1.0.7
+- from 1.0.7 we're setting JUnit as a default testing utility. You have to pass the following option to keep Spock
+as your first choice:
+
+[source,groovy]
+----
+include::../../../../accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle[tags=target_framework,indent=0]
+----
\ No newline at end of file