diff --git a/multi/multi__spring_cloud_contract_verifier_introduction.html b/multi/multi__spring_cloud_contract_verifier_introduction.html index 945b7fdded..f23350369e 100644 --- a/multi/multi__spring_cloud_contract_verifier_introduction.html +++ b/multi/multi__spring_cloud_contract_verifier_introduction.html @@ -171,9 +171,28 @@ compliance with the added contracts. By default, the generated tests are under assertThatJson(parsedJson).field("['fraudCheckStatus']").matches("[A-Z]{5}"); assertThatJson(parsedJson).field("['rejection.reason']").isEqualTo("Amount too high"); }
The preceding example uses Spring’s MockMvc to run the tests. This is the default test
-mode for HTTP contracts. However, JAX-RX client and explicit HTTP invocations can also be
+mode for HTTP contracts. However, JAX-RS client and explicit HTTP invocations can also be
used. (To do so, change the testMode property of the plugin to JAX-RS or EXPLICIT,
-respectively.)
Apart from the default JUnit 4, you can instead use JUnit 5 or Spock tests, by setting the plugin +respectively.)
Since 2.1.0, it is also possible to use RestAssuredWebTestClient`with Spring’s reactive `WebTestClient
+run under the hood. This is particularly recommended while working with Reactive, Web-Flux-based applications.
+In order to use WebTestClient set testMode to WEBTESTCLIENT.
Here is an example of a test generated in WEBTESTCLIENT test mode:
[source,java,indent=0]
@Test
+ public void validate_shouldRejectABeerIfTooYoung() throws Exception {
+ // given:
+ WebTestClientRequestSpecification request = given()
+ .header("Content-Type", "application/json")
+ .body("{\"age\":10}");
+
+ // when:
+ WebTestClientResponse response = given().spec(request)
+ .post("/check");
+
+ // then:
+ assertThat(response.statusCode()).isEqualTo(200);
+ assertThat(response.header("Content-Type")).matches("application/json.*");
+ // and:
+ DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
+ assertThatJson(parsedJson).field("['status']").isEqualTo("NOT_OK");
+ }Apart from the default JUnit 4, you can instead use JUnit 5 or Spock tests, by setting the plugin
testFramework property to either JUNIT5 or Spock.
![]() | Tip |
|---|---|
You can now also generate WireMock scenarios based on the contracts, by including an order number followed by an underscore at the beginning of the contract file names. |
The following example shows an auto-generated test in Spock for a messaging stub contract:
[source,groovy,indent=0]
given: ContractVerifierMessage inputMessage = contractVerifierMessaging.create( diff --git a/multi/multi__spring_cloud_contract_verifier_setup.html b/multi/multi__spring_cloud_contract_verifier_setup.html index ab2c443be2..8d838962e9 100644 --- a/multi/multi__spring_cloud_contract_verifier_setup.html +++ b/multi/multi__spring_cloud_contract_verifier_setup.html @@ -116,7 +116,7 @@ shown here:contracts { baseClassForTests = 'org.mycompany.tests' generatedTestSourcesDir = project.file('src/generatedContract') }
- testMode: Defines the mode for acceptance tests. By default, the mode is MockMvc, -which is based on Spring’s MockMvc. It can also be changed to JaxRsClient or to +which is based on Spring’s MockMvc. It can also be changed to WebTestClient, JaxRsClient or to Explicit for real HTTP calls.
- imports: Creates an array with imports that should be included in generated tests (for example ['org.myorg.Matchers']). By default, it creates an empty array.
- staticImports: Creates an array with static imports that should be included in generated tests(for example ['org.myorg.Matchers.*']). By default, it creates an empty @@ -356,7 +356,7 @@ definition or the
executiondefinition, as shown he <baseClassForTests>org.springframework.cloud.verifier.twitter.place.BaseMockMvcSpec</baseClassForTests> </configuration> </plugin>
- testMode: Defines the mode for acceptance tests. By default, the mode is MockMvc, -which is based on Spring’s MockMvc. It can also be changed to JaxRsClient or to +which is based on Spring’s MockMvc. It can also be changed to WebTestClient, JaxRsClient or to Explicit for real HTTP calls.
- basePackageForTests: Specifies the base package for all generated tests. If not set, the value is picked from
baseClassForTests’s package and from `packageWithBaseClasses. If neither of these values are set, then the value is set to diff --git a/multi/multi__spring_cloud_contract_wiremock.html b/multi/multi__spring_cloud_contract_wiremock.html index 5ba211e421..44c3923880 100644 --- a/multi/multi__spring_cloud_contract_wiremock.html +++ b/multi/multi__spring_cloud_contract_wiremock.html @@ -162,8 +162,7 @@ Example:Spring REST Docs can be used to generate documentation (for example in Asciidoctor format) for an HTTP API with Spring MockMvc -or
WebTestClientor -Rest Assured. At the same time that you generate documentation for your API, you can also +orWebTestClientor Rest Assured. At the same time that you generate documentation for your API, you can also generate WireMock stubs by using Spring Cloud Contract WireMock. To do so, write your normal REST Docs test cases and use@AutoConfigureRestDocsto have stubs be automatically generated in the REST Docs output directory. The following code shows an diff --git a/multi/multi__using_the_pluggable_architecture.html b/multi/multi__using_the_pluggable_architecture.html index 620642f441..4cd749eac3 100644 --- a/multi/multi__using_the_pluggable_architecture.html +++ b/multi/multi__using_the_pluggable_architecture.html @@ -422,10 +422,10 @@ to clone the repository and use it as a source of contracts to generate tests or stubs.Either via environment variables, system properties, properties set inside the plugin or contracts repository configuration you can tweak the downloader’s behaviour. Below you can find the list of -properties
Table 10.1. SCM Stub Downloader properties
Type of a property
Name of the property
Description
*
git.branch(plugin prop)*
stubrunner.properties.git.branch(system prop)*
STUBRUNNER_PROPERTIES_GIT_BRANCH(env prop)master
Which branch to checkout
*
git.username(plugin prop)*
stubrunner.properties.git.username(system prop)*
STUBRUNNER_PROPERTIES_GIT_USERNAME(env prop)Git clone username
*
git.password(plugin prop)*
stubrunner.properties.git.password(system prop)*
STUBRUNNER_PROPERTIES_GIT_PASSWORD(env prop)Git clone password
*
git.no-of-attempts(plugin prop)*
stubrunner.properties.git.no-of-attempts(system prop)*
STUBRUNNER_PROPERTIES_GIT_NO_OF_ATTEMPTS(env prop)10
Number of attempts to push the commits to
origin*
git.wait-between-attempts(Plugin prop)*
stubrunner.properties.git.wait-between-attempts(system prop)*
STUBRUNNER_PROPERTIES_GIT_WAIT_BETWEEN_ATTEMPTS(env prop)1000
Number of millis to wait between attempts to push the commits to
originWhenever the
repositoryRootstarts with a Pact protocol +propertiesTable 10.1. SCM Stub Downloader properties
Type of a property
Name of the property
Description
*
git.branch(plugin prop)*
stubrunner.properties.git.branch(system prop)*
STUBRUNNER_PROPERTIES_GIT_BRANCH(env prop)master
Which branch to checkout
*
git.username(plugin prop)*
stubrunner.properties.git.username(system prop)*
STUBRUNNER_PROPERTIES_GIT_USERNAME(env prop)Git clone username
*
git.password(plugin prop)*
stubrunner.properties.git.password(system prop)*
STUBRUNNER_PROPERTIES_GIT_PASSWORD(env prop)Git clone password
*
git.no-of-attempts(plugin prop)*
stubrunner.properties.git.no-of-attempts(system prop)*
STUBRUNNER_PROPERTIES_GIT_NO_OF_ATTEMPTS(env prop)10
Number of attempts to push the commits to
origin*
git.wait-between-attempts(Plugin prop)*
stubrunner.properties.git.wait-between-attempts(system prop)*
STUBRUNNER_PROPERTIES_GIT_WAIT_BETWEEN_ATTEMPTS(env prop)1000
Number of millis to wait between attempts to push the commits to
originWhenever the
repositoryRootstarts with a Pact protocol (starts withpact://), the stub downloader will try to fetch the Pact contract definitions from the Pact Broker. Whatever is set afterpact://will be parsed as the Pact Broker URL.Either via environment variables, system properties, properties set inside the plugin or contracts repository configuration you can tweak the downloader’s behaviour. Below you can find the list of -properties
Table 10.2. SCM Stub Downloader properties
Name of a property
Default
Description
*
pactbroker.host(plugin prop)*
stubrunner.properties.pactbroker.host(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_HOST(env prop)Host from URL passed to
repositoryRootWhat is the URL of Pact Broker
*
pactbroker.port(plugin prop)*
stubrunner.properties.pactbroker.port(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_PORT(env prop)Port from URL passed to
repositoryRootWhat is the port of Pact Broker
*
pactbroker.protocol(plugin prop)*
stubrunner.properties.pactbroker.protocol(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_PROTOCOL(env prop)Protocol from URL passed to
repositoryRootWhat is the protocol of Pact Broker
*
pactbroker.tags(plugin prop)*
stubrunner.properties.pactbroker.tags(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_TAGS(env prop)Version of the stub, or
latestif version is+What tags should be used to fetch the stub
*
pactbroker.auth.scheme(plugin prop)*
stubrunner.properties.pactbroker.auth.scheme(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_AUTH_SCHEME(env prop)
BasicWhat kind of authentication should be used to connect to the Pact Broker
*
pactbroker.auth.username(plugin prop)*
stubrunner.properties.pactbroker.auth.username(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_AUTH_USERNAME(env prop)The username passed to
contractsRepositoryUsername(maven) orcontractRepository.username(gradle)Username used to connect to the Pact Broker
*
pactbroker.auth.password(plugin prop)*
stubrunner.properties.pactbroker.auth.password(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_AUTH_PASSWORD(env prop)The password passed to
contractsRepositoryPassword(maven) orcontractRepository.password(gradle)Password used to connect to the Pact Broker
*
pactbroker.provider-name-with-group-id(plugin prop)*
stubrunner.properties.pactbroker.provider-name-with-group-id(system prop)*
STUBRUNNER_PROPERTIES_PACTBROKER_PROVIDER_NAME_WITH_GROUP_ID(env prop)false
When
true, the provider name will be a combination ofgroupId:artifactId. Iffalse, justartifactIdis used