Updated tests for the context path
without this change the explicit mode is broken and context path scenario can't be tested
with this change you can provide the EXPLICIT mode with which you can set the RestAssured to send real requests. That way you can set up your application to listen on a socket and have the context path setup. The contracts need to include the context path too since in real world you'll send a request to a URL that contains a context path element.
fixes #179 #117
This commit is contained in:
@@ -279,6 +279,59 @@ org.springframework.cloud.contract.spec.Contract.make {
|
||||
}
|
||||
----
|
||||
|
||||
==== Working with Context Paths
|
||||
|
||||
Spring Cloud Contract supports context paths.
|
||||
|
||||
IMPORTANT: The only thing that changes in order to fully support context paths is the switch
|
||||
on the *PRODUCER* side. The autogenerated tests need to be using the *EXPLICIT* mode.
|
||||
|
||||
The consumer side remains untouched, in order for the generated test to pass you have to switch the *EXPLICIT* mode.
|
||||
|
||||
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
|
||||
.Maven
|
||||
----
|
||||
<plugin>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<testMode>EXPLICIT</testMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
----
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes",role="secondary"]
|
||||
.Gradle
|
||||
----
|
||||
contracts {
|
||||
testMode = 'EXPLICIT'
|
||||
}
|
||||
----
|
||||
|
||||
That way you'll generate a test that *DOES NOT* use MockMvc. It means that you're generating
|
||||
real requests and you need to setup your generated test's base class to work on a real socket.
|
||||
|
||||
Let's imagine the following contract:
|
||||
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy[tags=context_path_contract,indent=0]
|
||||
----
|
||||
|
||||
Here is an example of how to set up a base class and Rest Assured for everything to work correctly.
|
||||
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy[tags=context_path_baseclass,indent=0]
|
||||
----
|
||||
|
||||
That way all:
|
||||
|
||||
- all your requests in the autogenerated tests will be sent to the real endpoint with your context path included (e.g. `/my-context-path/url`)
|
||||
- your contracts reflect that you have a context path, thus your generated stubs will also
|
||||
have that information (e.g. in the stubs you'll see that you have too call `/my-context-path/url`)
|
||||
|
||||
==== Messaging Top-Level Elements
|
||||
|
||||
|
||||
Reference in New Issue
Block a user