Added missing docs for #32

This commit is contained in:
Marcin Grzejszczak
2016-07-15 13:15:22 +02:00
parent 4ccec4fd22
commit bc22227fe3
3 changed files with 51 additions and 1 deletions

View File

@@ -113,6 +113,17 @@ Please see the example below:
include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/ContractHttpDocsSpec.groovy[tags=regex,indent=0]
----
You can also provide only one side of the communication using a regular expression. If you do that then automatically we'll
provide the generated string that matches the provided regular expression. For example:
[source,groovy,indent=0]
----
include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MockMvcMethodBodyBuilderSpec.groovy[tags=dsl_one_side_data_generation_example,indent=0]
----
In this example for request and response the opposite side of the communication will have the respective data generated.
=== Passing optional parameters
It is possible to provide optional parameters in your contract. It's only possible to have optional parameter for the:

View File

@@ -73,6 +73,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@@ -1398,7 +1398,6 @@ World.'''"""
test.contains('assertThatJson(parsedJson).field("message").matches("^(?!\\\\s*\\$).+")')
}
Contract dslForDocs =
// tag::dsl_example[]
org.springframework.cloud.contract.spec.Contract.make {
@@ -1444,4 +1443,39 @@ World.'''"""
}
}
// end::dsl_example[]
Contract dslWithOnlyOneSideForDocs =
// tag::dsl_one_side_data_generation_example[]
org.springframework.cloud.contract.spec.Contract.make {
request {
method 'PUT'
url '/foo'
body([
requestElement: value(client(regex('[0-9]{5}')))
])
}
response {
status 200
body([
responseElement: value(server(regex('[0-9]{7}')))
])
}
}
// end::dsl_one_side_data_generation_example[]
@Issue('#32')
def "should generate the regular expression for the other side of communication"() {
given:
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(
dslWithOnlyOneSideForDocs, properties)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.given(blockBuilder)
builder.then(blockBuilder)
def test = blockBuilder.toString()
then:
test.replace('\n', '').matches('.*')
test.replace('\n', '').stripIndent().stripMargin().matches('.*field\\("responseElement"\\).isEqualTo\\("[0-9]{7}.*')
}
}