Added HttpStatus delegate in the Groovy DSL Response

with this change there are numerous helper methods that should provide a more descriptive DSL for the response status. Instead of a numerical status you can now call a method e.g. instead of 200 call OK()

fixes gh-575
This commit is contained in:
Marcin Grzejszczak
2018-03-15 09:59:11 +01:00
parent f31e9ba137
commit 8e4360535c
77 changed files with 1064 additions and 347 deletions

View File

@@ -121,15 +121,26 @@ used to test contracts between applications and not to simulate full behavior.
This section explores how Spring Cloud Contract Verifier with Stub Runner works.
==== A three second tour
[[spring-cloud-contract-verifier-intro-three-second-tour]]
==== A Three-second Tour
This very brief tour walks through using Spring Cloud Contract:
* <<spring-cloud-contract-verifier-intro-three-second-tour-producer>>
* <<spring-cloud-contract-verifier-intro-three-second-tour-consumer>>
You can find a somewhat longer tour
<<spring-cloud-contract-verifier-intro-three-minute-tour,here>>.
[[spring-cloud-contract-verifier-intro-three-second-tour-producer]]
===== On the Producer Side
In order to start working with `Spring Cloud Contract`, add files with REST/ messaging contracts expressed in either
Groovy DSL or YAML to the contracts directory set by the
`contractsDslDir` property, by default `$rootDir/src/test/resources/contracts`.
To start working with Spring Cloud Contract, add files with `REST/` messaging contracts
expressed in either Groovy DSL or YAML to the contracts directory, which is set by the
`contractsDslDir` property. By default, it is `$rootDir/src/test/resources/contracts`.
Then, add Spring Cloud Contract Verifier dependency and plugin to your build file:
Then add the Spring Cloud Contract Verifier dependency and plugin to your build file, as
shown in the following example:
[source,xml,indent=0]
----
@@ -140,6 +151,9 @@ Then, add Spring Cloud Contract Verifier dependency and plugin to your build fil
</dependency>
----
The following listing shows how to add the plugin, which should go in the build/plugins
portion of the file:
[source,xml,indent=0]
----
<plugin>
@@ -150,27 +164,32 @@ Then, add Spring Cloud Contract Verifier dependency and plugin to your build fil
</plugin>
----
Now, running `./mvnw clean install` will cause tests that verify the application
compliance with the added contracts to be automatically generated, by default under `org.springframework.cloud.contract.verifier.tests.`.
Running `./mvnw clean install` automatically generates tests that verify the application
compliance with the added contracts. By default, the tests get generated under
`org.springframework.cloud.contract.verifier.tests.`.
As the implementation of the functionalities described by the contracts is not yet present,
the tests will fail.
As the implementation of the functionalities described by the contracts is not yet
present, the tests fail.
To make them pass, the correct implementation of either handling HTTP requests or messages
will have to be added. Also, a correct base test class for auto-generated tests needs to be added to the project.
This class will be extended by all the auto-generated tests and it should contain all the setup
necessary to run them (for example `RestAssuredMockMvc` controller setup or messaging test setup).
To make them pass, you must add the correct implementation of either handling HTTP
requests or messages. Also, you must add a correct base test class for auto-generated
tests to the project. This class is extended by all the auto-generated tests, and it
should contain all the setup necessary to run them (for example `RestAssuredMockMvc`
controller setup or messaging test setup).
Once the implementation and the test base class are in place, the tests will pass, and both the application
and the stub artifacts will be built and installed in the local Maven repository. The changes can now be merged
and both the application and the stub artifacts may be published in an online repository.
Once the implementation and the test base class are in place, the tests pass, and both the
application and the stub artifacts are built and installed in the local Maven repository.
The changes can now be merged, and both the application and the stub artifacts may be
published in an online repository.
[[spring-cloud-contract-verifier-intro-three-second-tour-consumer]]
===== On the Consumer Side
`Spring Cloud Contract Stub Runner` can be used in the integration tests to get a running WireMock instance/
messaging route that simulates the actual service.
`Spring Cloud Contract Stub Runner` can be used in the integration tests to get a running
WireMock instance or messaging route that simulates the actual service.
Add the dependency to `Spring Cloud Contract Stub Runner`:
To do so, add the dependency to `Spring Cloud Contract Stub Runner`, as shown in the
following example:
[source,xml,indent=0]
----
@@ -181,23 +200,23 @@ Add the dependency to `Spring Cloud Contract Stub Runner`:
</dependency>
----
Get the Producer-side stubs installed in your Maven repository by either:
- checking out the Producer side repository, adding contracts and generating the stubs by running:
You can get the Producer-side stubs installed in your Maven repository in either of two
ways:
* By checking out the Producer side repository and adding contracts and generating the stubs
by running the following commands:
+
[source,bash,indent=0]
----
$ cd local-http-server-repo
$ ./mvnw clean install -DskipTests
----
TIP: The tests are being skipped because the Producer-side contract implementation is not in place yet,
so the automatically-generated contract tests would fail;
or:
- getting already existing producer service stubs from a remote repository; to do this, simply pass the
stub artifact ids and artifact repository url as `Spring Cloud Contract Stub Runner` properties:
TIP: The tests are being skipped because the Producer-side contract implementation is not
in place yet, so the automatically-generated contract tests fail.
* By getting already-existing producer service stubs from a remote repository. To do so,
pass the stub artifact IDs and artifact repository URL as `Spring Cloud Contract
Stub Runner` properties, as shown in the following example:
+
[source,yaml,indent=0]
----
stubrunner:
@@ -205,10 +224,9 @@ stubrunner:
repositoryRoot: http://repo.spring.io/libs-snapshot
----
Now just annotate your test class with `@AutoConfigureStubRunner`. In the annotation, provide
the group-id and artifact-id for `Spring Cloud Contract Stub Runner` to run the collaborators' stubs for you.
TIP: Use the `REMOTE` stubsMode when downloading stubs from an online repository and `LOCAL` for offline work.
Now you can annotate your test class with `@AutoConfigureStubRunner`. In the annotation,
provide the `group-id` and `artifact-id` values for `Spring Cloud Contract Stub Runner` to
run the collaborators' stubs for you, as shown in the following example:
[source,java, indent=0]
----
@@ -220,19 +238,33 @@ TIP: Use the `REMOTE` stubsMode when downloading stubs from an online repository
public class LoanApplicationServiceTests {
----
Now in your integration test, you will be able to receive stubbed versions of HTTP responses or messages that are
expected to be emitted by the collaborator service.
TIP: Use the `REMOTE` `stubsMode` when downloading stubs from an online repository and
`LOCAL` for offline work.
==== A three minute tour
Now, in your integration test, you can receive stubbed versions of HTTP responses or
messages that are expected to be emitted by the collaborator service.
[[spring-cloud-contract-verifier-intro-three-minute-tour]]
==== A Three-minute Tour
This brief tour walks through using Spring Cloud Contract:
* <<spring-cloud-contract-verifier-intro-three-minute-tour-producer>>
* <<spring-cloud-contract-verifier-intro-three-minute-tour-consumer>>
You can find an even more brief tour
<<spring-cloud-contract-verifier-intro-three-second-tour,here>>.
[[spring-cloud-contract-verifier-intro-three-minute-tour-producer]]
===== On the Producer Side
In order to start working with `Spring Cloud Contract`, add files with REST/ messaging contracts expressed in either
Groovy DSL or YAML to the contracts directory set by the
`contractsDslDir` property, by default `$rootDir/src/test/resources/contracts`.
To start working with `Spring Cloud Contract`, add files with `REST/` messaging contracts
expressed in either Groovy DSL or YAML to the contracts directory, which is set by the
`contractsDslDir` property. By default, it is `$rootDir/src/test/resources/contracts`.
For the HTTP stubs, a contract defines what kind of response should be returned for a given request (taking into account the HTTP
methods, urls, headers, status codes, etc.). A sample HTTP stub contract in Groovy DSL would look like this:
For the HTTP stubs, a contract defines what kind of response should be returned for a
given request (taking into account the HTTP methods, URLs, headers, status codes, and so
on). The following example shows how an HTTP stub contract in Groovy DSL:
[source,groovy,indent=0]
----
@@ -251,7 +283,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body([
fraudCheckStatus: "FRAUD",
"rejection.reason": "Amount too high"
@@ -263,7 +295,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
----
While the same contract expressed in YAML would look the following way:
The same contract expressed in YAML would look like the following example:
[source,yaml,indent=0]
----
@@ -289,24 +321,29 @@ response:
Content-Type: application/json;charset=UTF-8
----
In the case of messaging, the input and the output messages can be defined (taking into account from and
where to it was sent, the message body and header), as well as the methods that should be called after the message
is received or the methods that, when called, should trigger a message.
An example of a Camel messaging contract expressed in Groovy DSL whould look like this:
In the case of messaging, you can define:
* The input and the output messages can be defined (taking into account from and where it
was sent, the message body, and the header).
* The methods that should be called after the message is received.
* The methods that, when called, should trigger a message.
The following example shows a Camel messaging contract expressed in Groovy DSL:
[source,groovy]
----
Unresolved directive in verifier_introduction.adoc - include::{verifier_core_path}/src/test/groovy/org/springframework/cloud/contract/verifier/builder/MessagingMethodBodyBuilderSpec.groovy[tags=trigger_no_output_dsl]
----
While, the same contract expressed in YAML would look as in the code below:
The following example shows the same contract expressed in YAML:
[source,yml,indent=0]
----
Unresolved directive in verifier_introduction.adoc - include::{verifier_core_path}/src/test/resources/yml/contract_message_scenario3.yml[indent=0]
----
Then, add Spring Cloud Contract Verifier dependency and plugin to your build file:
Then you can add Spring Cloud Contract Verifier dependency and plugin to your build file,
as shown in the following example:
[source,xml,indent=0]
----
@@ -317,6 +354,9 @@ Then, add Spring Cloud Contract Verifier dependency and plugin to your build fil
</dependency>
----
The following listing shows how to add the plugin, which should go in the build/plugins
portion of the file:
[source,xml,indent=0]
----
<plugin>
@@ -327,10 +367,11 @@ Then, add Spring Cloud Contract Verifier dependency and plugin to your build fil
</plugin>
----
Now, running `./mvnw clean install` will cause tests that verify the application
compliance with the added contracts to be automatically generated, by default under `org.springframework.cloud.contract.verifier.tests.`.
Running `./mvnw clean install` automatically generates tests that verify the application
compliance with the added contracts. By default, the generated tests are under
`org.springframework.cloud.contract.verifier.tests.`.
A sample auto-generated test for an HTTP contract would look the following way:
The following example shows a sample auto-generated test for an HTTP contract:
[source,java,indent=0]
----
@@ -355,17 +396,18 @@ public void validate_shouldMarkClientAsFraud() throws Exception {
}
----
The sample above uses Spring's `MockMvc` to run the tests. This is the default test mode for HTTP
contracts, however also JAX-RX client and explicit HTTP invocations can be used as well (just change
the `testMode` property of the plugin to `JAX-RS` or `EXPLICIT`.
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
used. (To do so, change the `testMode` property of the plugin to `JAX-RS` or `EXPLICIT`,
respectively.)
Apart from the default JUnit, you can also use Spock tests, instead, by setting the plugin `testFramework`
property to `Spock`.
Apart from the default JUnit, you can instead use Spock tests, by setting the plugin
`testFramework` property to `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.
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.
A sample auto-generated test in Spock for a messaging stub contract would look similar to this:
The following example shows an auto-generated test in Spock for a messaging stub contract:
[source,groovy,indent=0]
----
@@ -383,17 +425,19 @@ then:
bookWasDeleted()
----
As the implementation of the functionalities described by the contracts is not yet present,
the tests will fail.
As the implementation of the functionalities described by the contracts is not yet
present, the tests fail.
To make them pass, the correct implementation of handling either HTTP requests or messages
will have to be added. Also, a correct base test class for auto-generated tests needs to be added to the project.
This class will be extended by all the auto-generated tests and it should contain all the setup
necessary to run them (for example `RestAssuredMockMvc` controller setup or messaging test setup).
To make them pass, you must add the correct implementation of handling either HTTP
requests or messages. Also, you must add a correct base test class for auto-generated
tests to the project. This class is extended by all the auto-generated tests and should
contain all the setup necessary to run them (for example, `RestAssuredMockMvc` controller
setup or messaging test setup).
Once the implementation and the test base class are in place, the tests will pass, and both the application
and the stub artifacts will be built and installed in the local Maven repository. Information about
installing the stubs jar to the local repository will appear in the logs:
Once the implementation and the test base class are in place, the tests pass, and both the
application and the stub artifacts are built and installed in the local Maven repository.
Information about installing the stubs jar to the local repository appears in the logs, as
shown in the following example:
[source,bash,indent=0]
----
@@ -411,22 +455,26 @@ Once the implementation and the test base class are in place, the tests will pas
[INFO] Installing /some/path/http-server/target/http-server-0.0.1-SNAPSHOT-stubs.jar to /path/to/your/.m2/repository/com/example/http-server/0.0.1-SNAPSHOT/http-server-0.0.1-SNAPSHOT-stubs.jar
----
The changes can now be merged and both the application and the stub artifacts may be published in an online repository.
You can now merge the changes and publish both the application and the stub artifacts
in an online repository.
*Docker Project*
In order to enable working with contracts while creating applications in non-JVM technologies,
the `springcloud/spring-cloud-contract` Docker image has been created. It contains a project that will
automatically generate tests for HTTP contracts and execute them in `EXPLICIT` test mode, then, if
the tests pass, generate Wiremock stubs and -optionally- publish them to an artifact manager. In order to use the
image, it's sufficient to mount the contracts into the `/contracts` directory and set a few environment variables.
In order to enable working with contracts while creating applications in non-JVM
technologies, the `springcloud/spring-cloud-contract` Docker image has been created. It
contains a project that automatically generates tests for HTTP contracts and executes them
in `EXPLICIT` test mode. Then, if the tests pass, it generates Wiremock stubs and,
optionally, publishes them to an artifact manager. In order to use the image, you can
mount the contracts into the `/contracts` directory and set a few environment variables.
// TODO: We should answer the obvious question: Which environment variables?
[[spring-cloud-contract-verifier-intro-three-minute-tour-consumer]]
===== On the Consumer Side
`Spring Cloud Contract Stub Runner` can be used in the integration tests to get a running WireMock instance/
messaging route that simulates the actual service.
`Spring Cloud Contract Stub Runner` can be used in the integration tests to get a running
WireMock instance or messaging route that simulates the actual service.
Add the dependency to `Spring Cloud Contract Stub Runner`:
To get started, add the dependency to `Spring Cloud Contract Stub Runner`:
[source,xml,indent=0]
----
@@ -437,23 +485,23 @@ Add the dependency to `Spring Cloud Contract Stub Runner`:
</dependency>
----
Get the Producer-side stubs installed in your Maven repository by either:
- checking out the Producer side repository, adding contracts and generating the stubs by running:
You can get the Producer-side stubs installed in your Maven repository in either of two
ways:
* By checking out the Producer side repository and adding contracts and generating the
stubs by running the following commands:
+
[source,bash,indent=0]
----
$ cd local-http-server-repo
$ ./mvnw clean install -DskipTests
----
TIP: The tests are being skipped because the Producer-side contract implementation is not in place yet,
so the automatically-generated contract tests would fail;
or:
- getting already existing producer service stubs from a remote repository; to do this, simply pass the
stub artifact ids and artifact repository url as `Spring Cloud Contract Stub Runner` properties:
NOTE: The tests are skipped because the Producer-side contract implementation is not yet
in place, so the automatically-generated contract tests fail.
* Getting already existing producer service stubs from a remote repository. To do so,
pass the stub artifact IDs and artifact repository URl as `Spring Cloud Contract Stub
Runner` properties, as shown in the following example:
+
[source,yaml,indent=0]
----
stubrunner:
@@ -461,10 +509,9 @@ stubrunner:
repositoryRoot: http://repo.spring.io/libs-snapshot
----
Now just annotate your test class with `@AutoConfigureStubRunner`. In the annotation, provide
the group-id and artifact-id for `Spring Cloud Contract Stub Runner` to run the collaborators' stubs for you.
TIP: Use the `REMOTE` stubsMode when downloading stubs from an online repository and `LOCAL` for offline work.
Now you can annotate your test class with `@AutoConfigureStubRunner`. In the annotation,
provide the `group-id` and `artifact-id` for `Spring Cloud Contract Stub Runner` to run
the collaborators' stubs for you, as shown in the following example:
[source,java, indent=0]
----
@@ -476,8 +523,12 @@ TIP: Use the `REMOTE` stubsMode when downloading stubs from an online repository
public class LoanApplicationServiceTests {
----
Now in your integration test, you will be able to receive stubbed versions of HTTP responses or messages that are
expected to be emitted by the collaborator service. You will see entries similar to theses in the build logs:
TIP: Use the `REMOTE` `stubsMode` when downloading stubs from an online repository and
`LOCAL` for offline work.
In your integration test, you can receive stubbed versions of HTTP responses or messages
that are expected to be emitted by the collaborator service. You can see entries similar
to the following in the build logs:
[source,bash,indent=0]
----
@@ -491,7 +542,7 @@ expected to be emitted by the collaborator service. You will see entries similar
----
==== Defining the contract
==== Defining the Contract
As consumers of services, we need to define what exactly we want to achieve. We need to
formulate our expectations. That is why we write contracts.
@@ -518,7 +569,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response { // (6)
status 200 // (7)
status OK() // (7)
body([ // (8)
fraudCheckStatus: "FRAUD",
"rejection.reason": "Amount too high"
@@ -876,7 +927,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response { // (6)
status 200 // (7)
status OK() // (7)
body([ // (8)
fraudCheckStatus: "FRAUD",
"rejection.reason": "Amount too high"
@@ -1868,7 +1919,7 @@ Contract.make {
}
}
response {
status 200
status OK()
body('''
bar
''')

View File

@@ -371,7 +371,7 @@ Contract.make {
}
}
response {
status 200
status OK()
body('''
bar
''')

View File

@@ -357,10 +357,13 @@ include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=response,
include::{verifier_core_path}/src/test/resources/yml/contract.yml[tags=response_obligatory,indent=0]
----
Besides status, the response may contain **headers** and a **body**, both of which are
specified the same way as in the request (see the previous paragraph).
TIP: Via the Groovy DSL you can reference the `org.springframework.cloud.contract.spec.internal.HttpStatus`
methods to provide a meaningful status instead of a digit. E.g. you can call
`OK()` for a status `200` or `BAD_REQUEST()` for `400`.
=== Dynamic properties
The contract can contain some dynamic properties: timestamps, IDs, and so on. You do not
@@ -929,7 +932,7 @@ Contract.make {
url("/foo")
}
response {
status 200
status OK()
body(events: [[
operation : 'EXPORT',
eventId : '16f1ed75-0bcc-4f0d-a04d-3121798faf99',
@@ -1007,7 +1010,7 @@ org.springframework.cloud.contract.spec.Contract.make {
url '/get'
}
response {
status 200
status OK()
body 'Passed'
async()
}

View File

@@ -151,7 +151,7 @@ org.springframework.cloud.contract.spec.Contract.make {
])
}
response {
status 200
status OK()
body([
time : value(producer(regex('[0-9]{4}-[0-9]{2}-[0-9]{2} [0-2][0-9]-[0-5][0-9]-[0-5][0-9]')),
id: value([producer(regex('[0-9a-zA-z]{8}-[0-9a-zA-z]{4}-[0-9a-zA-z]{4}-[0-9a-zA-z]{12}'))

View File

@@ -249,7 +249,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body([
fraudCheckStatus: "FRAUD",
"rejection.reason": "Amount too high"

View File

@@ -13,7 +13,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response { // (6)
status 200 // (7)
status OK() // (7)
body([ // (8)
fraudCheckStatus: "FRAUD",
rejectionReason: "Amount too high"

View File

@@ -13,7 +13,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response { // (6)
status 200 // (7)
status OK() // (7)
body([ // (8)
fraudCheckStatus: "FRAUD",
rejectionReason: "Amount too high"

View File

@@ -13,7 +13,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response { // (6)
status 200 // (7)
status OK() // (7)
body([ // (8)
fraudCheckStatus: "FRAUD",
rejectionReason: "Amount too high"

View File

@@ -13,7 +13,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response { // (6)
status 200 // (7)
status OK() // (7)
body([ // (8)
fraudCheckStatus: "FRAUD",
"rejection.reason": "Amount too high"

View File

@@ -17,7 +17,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
"rejection.reason": $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.contract.spec.Contract
url '/frauds'
}
response {
status 200
status OK()
body([
count: 200
])
@@ -25,7 +25,7 @@ import org.springframework.cloud.contract.spec.Contract
url '/drunks'
}
response {
status 200
status OK()
body([
count: 100
])

View File

@@ -14,7 +14,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body([
result: "Sorry ${fromRequest().body('$.name')} but you're a fraud"
])

View File

@@ -12,7 +12,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body([
result: "Don't worry ${fromRequest().body('$.name')} you're not a fraud"
])

View File

@@ -0,0 +1,384 @@
package org.springframework.cloud.contract.spec.internal
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
/**
* Helper functions for HTTP statuses
*
* @author Marcin Grzejszczak
* @since 2.0.0
*/
@CompileStatic
@EqualsAndHashCode
class HttpStatus {
private HttpStatus() {}
// 1xx Informational
/**
* {@code 100 Continue}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.2.1">HTTP/1.1: Semantics and Content, section 6.2.1</a>
*/
int CONTINUE() {
return 100
}
/**
* {@code 101 Switching Protocols}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.2.2">HTTP/1.1: Semantics and Content, section 6.2.2</a>
*/
int SWITCHING_PROTOCOLS() {
return 101
}
/**
* {@code 102 Processing}.
* @see <a href="http://tools.ietf.org/html/rfc2518#section-10.1">WebDAV</a>
*/
int PROCESSING() { return 102 }
/**
* {@code 103 Checkpoint}.
* @see <a href="http://code.google.com/p/gears/wiki/ResumableHttpRequestsProposal">A proposal for supporting
* resumable POST/PUT HTTP requests in HTTP/1.0</a>
*/
int CHECKPOINT() { return 103 }
// 2xx Success
/**
* {@code 200 OK}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.1">HTTP/1.1: Semantics and Content, section 6.3.1</a>
*/
int OK() { return 200 }
/**
* {@code 201 Created}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.2">HTTP/1.1: Semantics and Content, section 6.3.2</a>
*/
int CREATED() { return 201 }
/**
* {@code 202 Accepted}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.3">HTTP/1.1: Semantics and Content, section 6.3.3</a>
*/
int ACCEPTED() { return 202 }
/**
* {@code 203 Non-Authoritative Information}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.4">HTTP/1.1: Semantics and Content, section 6.3.4</a>
*/
int NON_AUTHORITATIVE_INFORMATION() { return 203 }
/**
* {@code 204 No Content}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.5">HTTP/1.1: Semantics and Content, section 6.3.5</a>
*/
int NO_CONTENT() { return 204 }
/**
* {@code 205 Reset Content}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.3.6">HTTP/1.1: Semantics and Content, section 6.3.6</a>
*/
int RESET_CONTENT() { return 205 }
/**
* {@code 206 Partial Content}.
* @see <a href="http://tools.ietf.org/html/rfc7233#section-4.1">HTTP/1.1: Range Requests, section 4.1</a>
*/
int PARTIAL_CONTENT() { return 206 }
/**
* {@code 207 Multi-Status}.
* @see <a href="http://tools.ietf.org/html/rfc4918#section-13">WebDAV</a>
*/
int MULTI_STATUS() { return 207 }
/**
* {@code 208 Already Reported}.
* @see <a href="http://tools.ietf.org/html/rfc5842#section-7.1">WebDAV Binding Extensions</a>
*/
int ALREADY_REPORTED() { return 208 }
/**
* {@code 226 IM Used}.
* @see <a href="http://tools.ietf.org/html/rfc3229#section-10.4.1">Delta encoding in HTTP</a>
*/
int IM_USED() { return 226 }
// 3xx Redirection
/**
* {@code 300 Multiple Choices}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.1">HTTP/1.1: Semantics and Content, section 6.4.1</a>
*/
int MULTIPLE_CHOICES() { return 300 }
/**
* {@code 301 Moved Permanently}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.2">HTTP/1.1: Semantics and Content, section 6.4.2</a>
*/
int MOVED_PERMANENTLY() { return 301 }
/**
* {@code 302 Found}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.3">HTTP/1.1: Semantics and Content, section 6.4.3</a>
*/
int FOUND() { return 302 }
/**
* {@code 302 Moved Temporarily}.
* @see <a href="http://tools.ietf.org/html/rfc1945#section-9.3">HTTP/1.0, section 9.3</a>
* @deprecated in favor of {@link #FOUND} which will be returned from {@code HttpStatus.valueOf(302)}
*/
@Deprecated
int MOVED_TEMPORARILY() { return 302 }
/**
* {@code 303 See Other}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.4">HTTP/1.1: Semantics and Content, section 6.4.4</a>
*/
int SEE_OTHER() { return 303 }
/**
* {@code 304 Not Modified}.
* @see <a href="http://tools.ietf.org/html/rfc7232#section-4.1">HTTP/1.1: Conditional Requests, section 4.1</a>
*/
int NOT_MODIFIED() { return 304 }
/**
* {@code 305 Use Proxy}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.5">HTTP/1.1: Semantics and Content, section 6.4.5</a>
* @deprecated due to security concerns regarding in-band configuration of a proxy
*/
@Deprecated
int USE_PROXY() { return 305 }
/**
* {@code 307 Temporary Redirect}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.4.7">HTTP/1.1: Semantics and Content, section 6.4.7</a>
*/
int TEMPORARY_REDIRECT() { return 307 }
/**
* {@code 308 Permanent Redirect}.
* @see <a href="http://tools.ietf.org/html/rfc7238">RFC 7238</a>
*/
int PERMANENT_REDIRECT() { return 308 }
// --- 4xx Client Error ---
/**
* {@code 400 Bad Request}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.1">HTTP/1.1: Semantics and Content, section 6.5.1</a>
*/
int BAD_REQUEST() { return 400 }
/**
* {@code 401 Unauthorized}.
* @see <a href="http://tools.ietf.org/html/rfc7235#section-3.1">HTTP/1.1: Authentication, section 3.1</a>
*/
int UNAUTHORIZED() { return 401 }
/**
* {@code 402 Payment Required}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.2">HTTP/1.1: Semantics and Content, section 6.5.2</a>
*/
int PAYMENT_REQUIRED() { return 402 }
/**
* {@code 403 Forbidden}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.3">HTTP/1.1: Semantics and Content, section 6.5.3</a>
*/
int FORBIDDEN() { return 403 }
/**
* {@code 404 Not Found}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.4">HTTP/1.1: Semantics and Content, section 6.5.4</a>
*/
int NOT_FOUND() { return 404 }
/**
* {@code 405 Method Not Allowed}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.5">HTTP/1.1: Semantics and Content, section 6.5.5</a>
*/
int METHOD_NOT_ALLOWED() { return 405 }
/**
* {@code 406 Not Acceptable}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.6">HTTP/1.1: Semantics and Content, section 6.5.6</a>
*/
int NOT_ACCEPTABLE() { return 406 }
/**
* {@code 407 Proxy Authentication Required}.
* @see <a href="http://tools.ietf.org/html/rfc7235#section-3.2">HTTP/1.1: Authentication, section 3.2</a>
*/
int PROXY_AUTHENTICATION_REQUIRED() { return 407 }
/**
* {@code 408 Request Timeout}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.7">HTTP/1.1: Semantics and Content, section 6.5.7</a>
*/
int REQUEST_TIMEOUT() { return 408 }
/**
* {@code 409 Conflict}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.8">HTTP/1.1: Semantics and Content, section 6.5.8</a>
*/
int CONFLICT() { return 409 }
/**
* {@code 410 Gone}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.9">HTTP/1.1: Semantics and Content, section 6.5.9</a>
*/
int GONE() { return 410 }
/**
* {@code 411 Length Required}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.10">HTTP/1.1: Semantics and Content, section 6.5.10</a>
*/
int LENGTH_REQUIRED() { return 411 }
/**
* {@code 412 Precondition failed}.
* @see <a href="http://tools.ietf.org/html/rfc7232#section-4.2">HTTP/1.1: Conditional Requests, section 4.2</a>
*/
int PRECONDITION_FAILED() { return 412 }
/**
* {@code 413 Payload Too Large}.
* @since 4.1
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.11">HTTP/1.1: Semantics and Content, section 6.5.11</a>
*/
int PAYLOAD_TOO_LARGE() { return 413 }
/**
* {@code 413 Request Entity Too Large}.
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.14">HTTP/1.1, section 10.4.14</a>
* @deprecated in favor of {@link #PAYLOAD_TOO_LARGE} which will be returned from {@code HttpStatus.valueOf(413)}
*/
@Deprecated
int REQUEST_ENTITY_TOO_LARGE() { return 413 }
/**
* {@code 414 URI Too Long}.
* @since 4.1
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.12">HTTP/1.1: Semantics and Content, section 6.5.12</a>
*/
int URI_TOO_LONG() { return 414 }
/**
* {@code 414 Request-URI Too Long}.
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.15">HTTP/1.1, section 10.4.15</a>
* @deprecated in favor of {@link #URI_TOO_LONG} which will be returned from {@code HttpStatus.valueOf(414)}
*/
@Deprecated
int REQUEST_URI_TOO_LONG() { return 414 }
/**
* {@code 415 Unsupported Media Type}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.13">HTTP/1.1: Semantics and Content, section 6.5.13</a>
*/
int UNSUPPORTED_MEDIA_TYPE() { return 415 }
/**
* {@code 416 Requested Range Not Satisfiable}.
* @see <a href="http://tools.ietf.org/html/rfc7233#section-4.4">HTTP/1.1: Range Requests, section 4.4</a>
*/
int REQUESTED_RANGE_NOT_SATISFIABLE() { return 416 }
/**
* {@code 417 Expectation Failed}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.5.14">HTTP/1.1: Semantics and Content, section 6.5.14</a>
*/
int EXPECTATION_FAILED() { return 417 }
/**
* {@code 418 I'm a teapot}.
* @see <a href="http://tools.ietf.org/html/rfc2324#section-2.3.2">HTCPCP/1.0</a>
*/
int I_AM_A_TEAPOT() { return 418 }
/**
* @deprecated See <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">WebDAV Draft Changes</a>
*/
@Deprecated
int INSUFFICIENT_SPACE_ON_RESOURCE() { return 419 }
/**
* @deprecated See <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">WebDAV Draft Changes</a>
*/
@Deprecated
int METHOD_FAILURE() { return 420 }
/**
* @deprecated See <a href="http://tools.ietf.org/rfcdiff?difftype=--hwdiff&url2=draft-ietf-webdav-protocol-06.txt">WebDAV Draft Changes</a>
*/
@Deprecated
int DESTINATION_LOCKED() { return 421 }
/**
* {@code 422 Unprocessable Entity}.
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a>
*/
int UNPROCESSABLE_ENTITY() { return 422 }
/**
* {@code 423 Locked}.
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.3">WebDAV</a>
*/
int LOCKED() { return 423 }
/**
* {@code 424 Failed Dependency}.
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.4">WebDAV</a>
*/
int FAILED_DEPENDENCY() { return 424 }
/**
* {@code 426 Upgrade Required}.
* @see <a href="http://tools.ietf.org/html/rfc2817#section-6">Upgrading to TLS Within HTTP/1.1</a>
*/
int UPGRADE_REQUIRED() { return 426 }
/**
* {@code 428 Precondition Required}.
* @see <a href="http://tools.ietf.org/html/rfc6585#section-3">Additional HTTP Status Codes</a>
*/
int PRECONDITION_REQUIRED() { return 428 }
/**
* {@code 429 Too Many Requests}.
* @see <a href="http://tools.ietf.org/html/rfc6585#section-4">Additional HTTP Status Codes</a>
*/
int TOO_MANY_REQUESTS() { return 429 }
/**
* {@code 431 Request Header Fields Too Large}.
* @see <a href="http://tools.ietf.org/html/rfc6585#section-5">Additional HTTP Status Codes</a>
*/
int REQUEST_HEADER_FIELDS_TOO_LARGE() { return 431 }
/**
* {@code 451 Unavailable For Legal Reasons}.
* @see <a href="https://tools.ietf.org/html/draft-ietf-httpbis-legally-restricted-status-04">
* An HTTP Status Code to Report Legal Obstacles</a>
* @since 4.3
*/
int UNAVAILABLE_FOR_LEGAL_REASONS() { return 451 }
// --- 5xx Server Error ---
/**
* {@code 500 Internal Server Error}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.1">HTTP/1.1: Semantics and Content, section 6.6.1</a>
*/
int INTERNAL_SERVER_ERROR() { return 500 }
/**
* {@code 501 Not Implemented}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.2">HTTP/1.1: Semantics and Content, section 6.6.2</a>
*/
int NOT_IMPLEMENTED() { return 501 }
/**
* {@code 502 Bad Gateway}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.3">HTTP/1.1: Semantics and Content, section 6.6.3</a>
*/
int BAD_GATEWAY() { return 502 }
/**
* {@code 503 Service Unavailable}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.4">HTTP/1.1: Semantics and Content, section 6.6.4</a>
*/
int SERVICE_UNAVAILABLE() { return 503 }
/**
* {@code 504 Gateway Timeout}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.5">HTTP/1.1: Semantics and Content, section 6.6.5</a>
*/
int GATEWAY_TIMEOUT() { return 504 }
/**
* {@code 505 HTTP Version Not Supported}.
* @see <a href="http://tools.ietf.org/html/rfc7231#section-6.6.6">HTTP/1.1: Semantics and Content, section 6.6.6</a>
*/
int HTTP_VERSION_NOT_SUPPORTED() { return 505 }
/**
* {@code 506 Variant Also Negotiates}
* @see <a href="http://tools.ietf.org/html/rfc2295#section-8.1">Transparent Content Negotiation</a>
*/
int VARIANT_ALSO_NEGOTIATES() { return 506 }
/**
* {@code 507 Insufficient Storage}
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.5">WebDAV</a>
*/
int INSUFFICIENT_STORAGE() { return 507 }
/**
* {@code 508 Loop Detected}
* @see <a href="http://tools.ietf.org/html/rfc5842#section-7.2">WebDAV Binding Extensions</a>
*/
int LOOP_DETECTED() { return 508 }
/**
* {@code 509 Bandwidth Limit Exceeded}
*/
int BANDWIDTH_LIMIT_EXCEEDED() { return 509 }
/**
* {@code 510 Not Extended}
* @see <a href="http://tools.ietf.org/html/rfc2774#section-7">HTTP Extension Framework</a>
*/
int NOT_EXTENDED() { return 510 }
/**
* {@code 511 Network Authentication Required}.
* @see <a href="http://tools.ietf.org/html/rfc6585#section-6">Additional HTTP Status Codes</a>
*/
int NETWORK_AUTHENTICATION_REQUIRED() { return 511 }
}

View File

@@ -35,7 +35,8 @@ import java.util.regex.Pattern
class Response extends Common {
@Delegate ServerPatternValueDslProperty property = new ServerPatternValueDslProperty()
@Delegate HttpStatus httpStatus = new HttpStatus()
DslProperty status
DslProperty delay
Headers headers

View File

@@ -182,7 +182,7 @@ then:
url "/${index}"
}
response {
status 200
status OK()
}
}
def b = Contract.make {
@@ -194,7 +194,7 @@ then:
url "/${index}"
}
response {
status 200
status OK()
}
}
a == b
@@ -212,7 +212,7 @@ then:
url "/${index}"
}
response {
status 200
status OK()
}
}
int index2 = 2
@@ -225,7 +225,7 @@ then:
url "/${index2}"
}
response {
status 200
status OK()
}
}
a != b
@@ -249,7 +249,7 @@ then:
}
}
response {
status 200
status OK()
body(
id: [value: '132'],
surname: 'Kowalsky',
@@ -277,7 +277,7 @@ then:
}
}
response {
status 200
status OK()
body(
id: [value: '132'],
surname: 'Kowalsky',

View File

@@ -0,0 +1,278 @@
package org.springframework.cloud.contract.spec.internal;
import org.assertj.core.api.BDDAssertions;
import org.junit.Test;
/**
* @author Marcin Grzejszczak
*/
public class HttpStatusTests {
@Test public void CONTINUE() {
BDDAssertions.then(new HttpStatus().CONTINUE()).isEqualTo(100);
}
@Test public void SWITCHING_PROTOCOLS() {
BDDAssertions.then(new HttpStatus().SWITCHING_PROTOCOLS()).isEqualTo(101);
}
@Test public void PROCESSING() {
BDDAssertions.then(new HttpStatus().PROCESSING()).isEqualTo(102);
}
@Test public void CHECKPOINT() {
BDDAssertions.then(new HttpStatus().CHECKPOINT()).isEqualTo(103);
}
@Test public void OK() {
BDDAssertions.then(new HttpStatus().OK()).isEqualTo(200);
}
@Test public void CREATED() {
BDDAssertions.then(new HttpStatus().CREATED()).isEqualTo(201);
}
@Test public void ACCEPTED() {
BDDAssertions.then(new HttpStatus().ACCEPTED()).isEqualTo(202);
}
@Test public void NON_AUTHORITATIVE_INFORMATION() {
BDDAssertions.then(new HttpStatus().NON_AUTHORITATIVE_INFORMATION()).isEqualTo(203);
}
@Test public void NO_CONTENT() {
BDDAssertions.then(new HttpStatus().NO_CONTENT()).isEqualTo(204);
}
@Test public void RESET_CONTENT() {
BDDAssertions.then(new HttpStatus().RESET_CONTENT()).isEqualTo(205);
}
@Test public void PARTIAL_CONTENT() {
BDDAssertions.then(new HttpStatus().PARTIAL_CONTENT()).isEqualTo(206);
}
@Test public void MULTI_STATUS() {
BDDAssertions.then(new HttpStatus().MULTI_STATUS()).isEqualTo(207);
}
@Test public void ALREADY_REPORTED() {
BDDAssertions.then(new HttpStatus().ALREADY_REPORTED()).isEqualTo(208);
}
@Test public void IM_USED() {
BDDAssertions.then(new HttpStatus().IM_USED()).isEqualTo(226);
}
@Test public void MULTIPLE_CHOICES() {
BDDAssertions.then(new HttpStatus().MULTIPLE_CHOICES()).isEqualTo(300);
}
@Test public void MOVED_PERMANENTLY() {
BDDAssertions.then(new HttpStatus().MOVED_PERMANENTLY()).isEqualTo(301);
}
@Test public void FOUND() {
BDDAssertions.then(new HttpStatus().FOUND()).isEqualTo(302);
}
@Test public void MOVED_TEMPORARILY() {
BDDAssertions.then(new HttpStatus().MOVED_TEMPORARILY()).isEqualTo(302);
}
@Test public void SEE_OTHER() {
BDDAssertions.then(new HttpStatus().SEE_OTHER()).isEqualTo(303);
}
@Test public void NOT_MODIFIED() {
BDDAssertions.then(new HttpStatus().NOT_MODIFIED()).isEqualTo(304);
}
@Test public void USE_PROXY() {
BDDAssertions.then(new HttpStatus().USE_PROXY()).isEqualTo(305);
}
@Test public void TEMPORARY_REDIRECT() {
BDDAssertions.then(new HttpStatus().TEMPORARY_REDIRECT()).isEqualTo(307);
}
@Test public void PERMANENT_REDIRECT() {
BDDAssertions.then(new HttpStatus().PERMANENT_REDIRECT()).isEqualTo(308);
}
@Test public void BAD_REQUEST() {
BDDAssertions.then(new HttpStatus().BAD_REQUEST()).isEqualTo(400);
}
@Test public void UNAUTHORIZED() {
BDDAssertions.then(new HttpStatus().UNAUTHORIZED()).isEqualTo(401);
}
@Test public void PAYMENT_REQUIRED() {
BDDAssertions.then(new HttpStatus().PAYMENT_REQUIRED()).isEqualTo(402);
}
@Test public void FORBIDDEN() {
BDDAssertions.then(new HttpStatus().FORBIDDEN()).isEqualTo(403);
}
@Test public void NOT_FOUND() {
BDDAssertions.then(new HttpStatus().NOT_FOUND()).isEqualTo(404);
}
@Test public void METHOD_NOT_ALLOWED() {
BDDAssertions.then(new HttpStatus().METHOD_NOT_ALLOWED()).isEqualTo(405);
}
@Test public void NOT_ACCEPTABLE() {
BDDAssertions.then(new HttpStatus().NOT_ACCEPTABLE()).isEqualTo(406);
}
@Test public void PROXY_AUTHENTICATION_REQUIRED() {
BDDAssertions.then(new HttpStatus().PROXY_AUTHENTICATION_REQUIRED()).isEqualTo(407);
}
@Test public void REQUEST_TIMEOUT() {
BDDAssertions.then(new HttpStatus().REQUEST_TIMEOUT()).isEqualTo(408);
}
@Test public void CONFLICT() {
BDDAssertions.then(new HttpStatus().CONFLICT()).isEqualTo(409);
}
@Test public void GONE() {
BDDAssertions.then(new HttpStatus().GONE()).isEqualTo(410);
}
@Test public void LENGTH_REQUIRED() {
BDDAssertions.then(new HttpStatus().LENGTH_REQUIRED()).isEqualTo(411);
}
@Test public void PRECONDITION_FAILED() {
BDDAssertions.then(new HttpStatus().PRECONDITION_FAILED()).isEqualTo(412);
}
@Test public void PAYLOAD_TOO_LARGE() {
BDDAssertions.then(new HttpStatus().PAYLOAD_TOO_LARGE()).isEqualTo(413);
}
@Test public void REQUEST_ENTITY_TOO_LARGE() {
BDDAssertions.then(new HttpStatus().REQUEST_ENTITY_TOO_LARGE()).isEqualTo(413);
}
@Test public void URI_TOO_LONG() {
BDDAssertions.then(new HttpStatus().URI_TOO_LONG()).isEqualTo(414);
}
@Test public void REQUEST_URI_TOO_LONG() {
BDDAssertions.then(new HttpStatus().REQUEST_URI_TOO_LONG()).isEqualTo(414);
}
@Test public void UNSUPPORTED_MEDIA_TYPE() {
BDDAssertions.then(new HttpStatus().UNSUPPORTED_MEDIA_TYPE()).isEqualTo(415);
}
@Test public void REQUESTED_RANGE_NOT_SATISFIABLE() {
BDDAssertions.then(new HttpStatus().REQUESTED_RANGE_NOT_SATISFIABLE()).isEqualTo(416);
}
@Test public void EXPECTATION_FAILED() {
BDDAssertions.then(new HttpStatus().EXPECTATION_FAILED()).isEqualTo(417);
}
@Test public void I_AM_A_TEAPOT() {
BDDAssertions.then(new HttpStatus().I_AM_A_TEAPOT()).isEqualTo(418);
}
@Test public void INSUFFICIENT_SPACE_ON_RESOURCE() {
BDDAssertions.then(new HttpStatus().INSUFFICIENT_SPACE_ON_RESOURCE()).isEqualTo(419);
}
@Test public void METHOD_FAILURE() {
BDDAssertions.then(new HttpStatus().METHOD_FAILURE()).isEqualTo(420);
}
@Test public void DESTINATION_LOCKED() {
BDDAssertions.then(new HttpStatus().DESTINATION_LOCKED()).isEqualTo(421);
}
@Test public void UNPROCESSABLE_ENTITY() {
BDDAssertions.then(new HttpStatus().UNPROCESSABLE_ENTITY()).isEqualTo(422);
}
@Test public void LOCKED() {
BDDAssertions.then(new HttpStatus().LOCKED()).isEqualTo(423);
}
@Test public void FAILED_DEPENDENCY() {
BDDAssertions.then(new HttpStatus().FAILED_DEPENDENCY()).isEqualTo(424);
}
@Test public void UPGRADE_REQUIRED() {
BDDAssertions.then(new HttpStatus().UPGRADE_REQUIRED()).isEqualTo(426);
}
@Test public void PRECONDITION_REQUIRED() {
BDDAssertions.then(new HttpStatus().PRECONDITION_REQUIRED()).isEqualTo(428);
}
@Test public void TOO_MANY_REQUESTS() {
BDDAssertions.then(new HttpStatus().TOO_MANY_REQUESTS()).isEqualTo(429);
}
@Test public void REQUEST_HEADER_FIELDS_TOO_LARGE() {
BDDAssertions.then(new HttpStatus().REQUEST_HEADER_FIELDS_TOO_LARGE()).isEqualTo(431);
}
@Test public void UNAVAILABLE_FOR_LEGAL_REASONS() {
BDDAssertions.then(new HttpStatus().UNAVAILABLE_FOR_LEGAL_REASONS()).isEqualTo(451);
}
@Test public void INTERNAL_SERVER_ERROR() {
BDDAssertions.then(new HttpStatus().INTERNAL_SERVER_ERROR()).isEqualTo(500);
}
@Test public void NOT_IMPLEMENTED() {
BDDAssertions.then(new HttpStatus().NOT_IMPLEMENTED()).isEqualTo(501);
}
@Test public void BAD_GATEWAY() {
BDDAssertions.then(new HttpStatus().BAD_GATEWAY()).isEqualTo(502);
}
@Test public void SERVICE_UNAVAILABLE() {
BDDAssertions.then(new HttpStatus().SERVICE_UNAVAILABLE()).isEqualTo(503);
}
@Test public void GATEWAY_TIMEOUT() {
BDDAssertions.then(new HttpStatus().GATEWAY_TIMEOUT()).isEqualTo(504);
}
@Test public void HTTP_VERSION_NOT_SUPPORTED() {
BDDAssertions.then(new HttpStatus().HTTP_VERSION_NOT_SUPPORTED()).isEqualTo(505);
}
@Test public void VARIANT_ALSO_NEGOTIATES() {
BDDAssertions.then(new HttpStatus().VARIANT_ALSO_NEGOTIATES()).isEqualTo(506);
}
@Test public void INSUFFICIENT_STORAGE() {
BDDAssertions.then(new HttpStatus().INSUFFICIENT_STORAGE()).isEqualTo(507);
}
@Test public void LOOP_DETECTED() {
BDDAssertions.then(new HttpStatus().LOOP_DETECTED()).isEqualTo(508);
}
@Test public void BANDWIDTH_LIMIT_EXCEEDED() {
BDDAssertions.then(new HttpStatus().BANDWIDTH_LIMIT_EXCEEDED()).isEqualTo(509);
}
@Test public void NOT_EXTENDED() {
BDDAssertions.then(new HttpStatus().NOT_EXTENDED()).isEqualTo(510);
}
@Test public void NETWORK_AUTHENTICATION_REQUIRED() {
BDDAssertions.then(new HttpStatus().NETWORK_AUTHENTICATION_REQUIRED()).isEqualTo(511);
}
}

View File

@@ -585,7 +585,7 @@ request {
method GET()
}
response {
status 200
status OK()
body(
foo: "foo"
}
@@ -601,7 +601,7 @@ request {
method GET()
}
response {
status 200
status OK()
body(
bar: "bar"
}

View File

@@ -14,7 +14,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body( """{
"fraudCheckStatus": "${value(c('FRAUD'), p(regex('[A-Z]{5}')))}",
"rejectionReason": "Amount too high"

View File

@@ -14,7 +14,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body( """{
"fraudCheckStatus": "${value(c('FRAUD'), p(regex('[A-Z]{5}')))}",
"rejectionReason": "Amount too high"

View File

@@ -110,7 +110,7 @@ class RecursiveFilesConverterSpec extends Specification {
method "GET"
}
response {
status 200
status OK()
}
}
"""
@@ -140,7 +140,7 @@ class RecursiveFilesConverterSpec extends Specification {
method "GET"
}
response {
status 200
status OK()
}
}
"""

View File

@@ -59,7 +59,7 @@ class DslToWireMockClientConverterSpec extends Specification {
url \$(consumer(~/\\/[0-9]{2}/), producer('/12'))
}
response {
status 200
status OK()
}
}
""")
@@ -94,7 +94,7 @@ class DslToWireMockClientConverterSpec extends Specification {
url "/${index}"
}
response {
status 200
status OK()
}
}
}
@@ -160,7 +160,7 @@ class DslToWireMockClientConverterSpec extends Specification {
url '/foo'
}
response {
status 200
status OK()
fixedDelayMilliseconds 1000
}
}
@@ -230,7 +230,7 @@ class DslToWireMockClientConverterSpec extends Specification {
'''
}
response {
status 200
status OK()
}
}
""")
@@ -338,7 +338,7 @@ class DslToWireMockClientConverterSpec extends Specification {
urlPath '/foos'
}
response {
status 200
status OK()
body([[id: value(
consumer('123'),
producer(regex('[0-9]+'))
@@ -383,7 +383,7 @@ class DslToWireMockClientConverterSpec extends Specification {
urlPath '/foos'
}
response {
status 200
status OK()
body(
digit: \$(producer(regex('[0-9]{1}'))),
id: \$(producer(regex(number())))
@@ -537,7 +537,7 @@ class DslToWireMockClientConverterSpec extends Specification {
}
}
response {
status 200
status OK()
body([
duck: 123,
alpha: "abc",

View File

@@ -70,7 +70,7 @@ class WireMockToDslConverterSpec extends Specification {
}
}
response {
status 200
status OK()
body("""{
"id": {
"value": "132"
@@ -131,7 +131,7 @@ class WireMockToDslConverterSpec extends Specification {
}
}
response {
status 200
status OK()
body( """{
"status": "OK"
}""")
@@ -185,7 +185,7 @@ class WireMockToDslConverterSpec extends Specification {
}
}
response {
status 200
status OK()
body(200)
headers {
header 'Content-Type': 'application/json'
@@ -236,7 +236,7 @@ class WireMockToDslConverterSpec extends Specification {
}
}
response {
status 200
status OK()
body( """[
{
"a": 1,
@@ -290,7 +290,7 @@ class WireMockToDslConverterSpec extends Specification {
}
}
response {
status 200
status OK()
body("""[
{
"amount": 1.01,
@@ -350,7 +350,7 @@ class WireMockToDslConverterSpec extends Specification {
body ('''{"property1":"abc", "property2":"2017-01", "property3":"666", "property4":1428566412}''')
}
response {
status 200
status OK()
}
}
when:
@@ -390,7 +390,7 @@ class WireMockToDslConverterSpec extends Specification {
body $(consumer(~/1/), producer('1'))
}
response {
status 200
status OK()
}
}
when:
@@ -431,7 +431,7 @@ class WireMockToDslConverterSpec extends Specification {
body '''{"pan":"4855141150107894", "expirationDate":"2017-01", "dcvx":"178"}'''
}
response {
status 200
status OK()
}
}
when:
@@ -471,7 +471,7 @@ class WireMockToDslConverterSpec extends Specification {
body '''{"pan":"4855141150107894", "expirationDate":"2017-01", "dcvx":"178"}'''
}
response {
status 200
status OK()
}
}
when:
@@ -511,7 +511,7 @@ class WireMockToDslConverterSpec extends Specification {
body $(consumer(~/1/), producer('1'))
}
response {
status 200
status OK()
}
}
when:
@@ -549,7 +549,7 @@ class WireMockToDslConverterSpec extends Specification {
url '/test'
}
response {
status 200
status OK()
}
}
when:

View File

@@ -22,6 +22,6 @@ Contract.make {
url '/login'
}
response {
status 200
status OK()
}
}

View File

@@ -22,6 +22,6 @@ Contract.make {
url '/cart'
}
response {
status 200
status OK()
}
}

View File

@@ -22,6 +22,6 @@ Contract.make {
url '/logout'
}
response {
status 200
status OK()
}
}

View File

@@ -25,6 +25,6 @@ Contract.make {
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status 200
status OK()
}
}

View File

@@ -26,7 +26,7 @@ import org.springframework.cloud.contract.spec.Contract
url "/${index}"
}
response {
status 200
status OK()
}
}
}

View File

@@ -27,7 +27,7 @@ import org.springframework.cloud.contract.spec.Contract
url "/${index}"
}
response {
status 200
status OK()
}
}
}

View File

@@ -25,6 +25,6 @@ Contract.make {
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status 200
status OK()
}
}

View File

@@ -25,6 +25,6 @@ Contract.make {
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status 200
status OK()
}
}

View File

@@ -25,6 +25,6 @@ Contract.make {
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status 200
status OK()
}
}

View File

@@ -38,6 +38,6 @@ Contract.make {
path: $(consumer('/api/12'), producer(regex('^/api/[0-9]{2}$'))),
correlationId: $(consumer('1223456'), producer(execute('isProperCorrelationId($it)')))
)
status 200
status OK()
}
}

View File

@@ -31,7 +31,7 @@ Contract.make {
}
response {
status 200
status OK()
body( """{
"fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}",
"rejectionReason": "Amount too high"

View File

@@ -32,7 +32,7 @@ Contract.make {
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))

View File

@@ -32,7 +32,7 @@ Contract.make {
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))

View File

@@ -32,7 +32,7 @@ Contract.make {
}
response {
status 200
status OK()
body( """{
"fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}",
"rejectionReason": "Amount too high"

View File

@@ -26,7 +26,7 @@ org.springframework.cloud.contract.spec.Contract.make {
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -25,7 +25,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -26,7 +26,7 @@ org.springframework.cloud.contract.spec.Contract.make {
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -25,7 +25,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -26,7 +26,7 @@ org.springframework.cloud.contract.spec.Contract.make {
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -26,7 +26,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -26,7 +26,7 @@ org.springframework.cloud.contract.spec.Contract.make {
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -25,7 +25,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -30,7 +30,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body( """{
"fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}",
"rejectionReason": "Amount too high"

View File

@@ -31,7 +31,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))

View File

@@ -30,7 +30,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body( """{
"fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}",
"rejectionReason": "Amount too high"

View File

@@ -31,7 +31,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))

View File

@@ -10,7 +10,7 @@ io.codearte.accurest.dsl.GroovyDsl.make {
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -25,7 +25,7 @@ import org.springframework.cloud.contract.spec.Contract
url('/users/1')
}
response {
status 200
status OK()
}
},
Contract.make {
@@ -34,7 +34,7 @@ import org.springframework.cloud.contract.spec.Contract
url('/users/2')
}
response {
status 200
status OK()
}
}
]

View File

@@ -28,7 +28,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body(
id: 1,
content: "Hello, Something!"

View File

@@ -24,7 +24,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body(
id: 1,
content: "Hello, World!"

View File

@@ -26,7 +26,7 @@ org.springframework.cloud.contract.spec.Contract.make {
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -28,7 +28,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body (
id: 1,
content: "Hello, Something!"

View File

@@ -24,7 +24,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body (
id: 1,
content: "Hello, World!"

View File

@@ -28,7 +28,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body(
id: 1,
content: "Hello, Something!"

View File

@@ -24,7 +24,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response {
status 200
status OK()
body(
id: 1,
content: "Hello, World!"

View File

@@ -26,7 +26,7 @@ org.springframework.cloud.contract.spec.Contract.make {
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
status OK()
headers {
header 'Location': '/users/john'
}

View File

@@ -13,7 +13,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
}
response { // (6)
status 200 // (7)
status OK() // (7)
body([ // (8)
fraudCheckStatus: "FRAUD",
rejectionReason: "Amount too high"

View File

@@ -17,7 +17,7 @@ org.springframework.cloud.contract.spec.Contract.make {
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))

View File

@@ -10,7 +10,7 @@ import org.springframework.cloud.contract.spec.Contract
url '/frauds'
}
response {
status 200
status OK()
body([
count: 200
])
@@ -25,7 +25,7 @@ import org.springframework.cloud.contract.spec.Contract
url '/drunks'
}
response {
status 200
status OK()
body([
count: 100
])

View File

@@ -197,7 +197,7 @@ class ContractHttpDocsSpec extends Specification {
response {
// Status code sent by the server
// in response to request specified above.
status 200
status OK()
}
}
// end::response[]
@@ -210,7 +210,7 @@ class ContractHttpDocsSpec extends Specification {
url $(consumer(~/\/[0-9]{2}/), producer('/12'))
}
response {
status 200
status OK()
body(
id: $(anyNumber()),
surname: $(
@@ -305,7 +305,7 @@ class ContractHttpDocsSpec extends Specification {
path: $(consumer('/api/12'), producer(regex('^/api/[0-9]{2}$'))),
correlationId: $(consumer('1223456'), producer(execute('isProperCorrelationId($it)')))
)
status 200
status OK()
}
}
// end::method[]

View File

@@ -42,7 +42,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """{
"property1": "a",
"property2": "b"
@@ -75,7 +75,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """{
"property1": "true",
"property2": null,
@@ -110,7 +110,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property1: 'a',
property2: [
@@ -149,7 +149,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property1: 'a',
property2: [
@@ -190,7 +190,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
)
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -221,7 +221,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
)
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -248,7 +248,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """[
{
"property1": "a"
@@ -283,7 +283,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """{
"property1": [
{ "property2": "test1"},
@@ -317,7 +317,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body '''\
{
"property1": "a",
@@ -351,7 +351,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property1: "a",
property2: value(
@@ -390,7 +390,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body("""{"property1":"a","property2":"${value(consumer('123'), producer(regex('[0-9]{3}')))}"}""")
headers {
header('Content-Type': 'application/json')
@@ -425,7 +425,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
}
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -457,7 +457,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
body ''
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -500,7 +500,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
}
}
response {
status 200
status OK()
body """
{
"property1": "a",
@@ -557,7 +557,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
}
}
response {
status 200
status OK()
body """
{
"property1": "a",
@@ -630,7 +630,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body "test"
}
}
@@ -661,7 +661,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "/v1/some_cool_requests/e86df6f693de4b35ae648464c5b0dc08"
}
response {
status 200
status OK()
headers {
contentType(applicationJson())
}
@@ -708,7 +708,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
}
}
response {
status 200
status OK()
body """
{
"property1": "a"
@@ -764,7 +764,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
urlPath '/get'
}
response {
status 200
status OK()
body([
fraudCheckStatus: "OK",
rejectionReason : [
@@ -805,7 +805,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
urlPath '/get'
}
response {
status 200
status OK()
body([
[
name: $(consumer("userName 1"), producer(execute('assertThatUserNameIsNotNull($it)')))
@@ -838,7 +838,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
urlPath '/get'
}
response {
status 200
status OK()
body([
[
name: $(consumer("userName 1"), producer(execute('assertThatUserNameIsNotNull($it)')))
@@ -868,8 +868,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url '/get'
}
response {
status 200
status 200
status OK()
status OK()
body(value(stub("HELLO FROM STUB"), server(regex(".*"))))
}
}
@@ -893,8 +893,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url '/get'
}
response {
status 200
status 200
status OK()
status OK()
body(value(stub("HELLO FROM STUB"), server(regex(".*"))))
}
}
@@ -918,8 +918,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url '/get'
}
response {
status 200
status 200
status OK()
status OK()
body(value(stub("HELLO FROM STUB"), server(execute('foo($it)'))))
}
}
@@ -941,8 +941,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url '/get'
}
response {
status 200
status 200
status OK()
status OK()
body(value(stub("HELLO FROM STUB"), server(execute('foo($it)'))))
}
}
@@ -966,7 +966,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property1: "a",
property2: $(
@@ -1028,7 +1028,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
}
}
response {
status 200
status OK()
body([
alpha: $(anyAlphaUnicode()),
number: $(anyNumber()),

View File

@@ -49,7 +49,7 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
body ([
myArray:[
[
@@ -117,7 +117,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
urlPath '/foo'
}
response {
status 200
status OK()
body (
foo: ["my.dotted.response" : $(c('foo'), p(execute('"foo".equals($it)')))]
)
@@ -167,7 +167,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
}
}
response {
status 200
status OK()
headers {
contentType(applicationJson())
}
@@ -220,7 +220,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
)
}
response {
status 200
status OK()
}
}
//end::body_execute[]
@@ -257,7 +257,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
])
}
response {
status 200
status OK()
headers {
contentType(applicationPdf())
header('Content-Length': 4)
@@ -289,7 +289,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
url "test"
}
response {
status 200
status OK()
body(
"createdAt": 1502766000000,
"updatedAt": 1499476115000
@@ -327,7 +327,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
}
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -358,7 +358,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
body("""{ "name": "My name" }""")
}
response {
status 200
status OK()
body fromRequest().body('$.name')
}
}
@@ -395,7 +395,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
body("""{ "name": "My name" }""")
}
response {
status 200
status OK()
body (
foo: fromRequest().query("foo"),
number: fromRequest().query("number")
@@ -440,7 +440,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
url '/'
}
response {
status 200
status OK()
body("Ryan")
headers {
contentType(textHtml())
@@ -472,7 +472,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
url "test"
}
response {
status 200
status OK()
async()
fixedDelayMilliseconds(10000)
body(a: 'foo')
@@ -507,7 +507,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
body('a=abc&b=123')
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -537,7 +537,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
url '/api/users'
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)

View File

@@ -16,7 +16,7 @@ class MethodBuilderSpec extends Specification {
urlPath '/foo'
}
response {
status 200
status OK()
body(foo: "foo")
headers {
contentType(applicationJson())

View File

@@ -115,7 +115,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """{
"property1": "a",
"property2": "b"
@@ -148,7 +148,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """{
"property1": "true",
"property2": null,
@@ -183,7 +183,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property1: 'a',
property2: [
@@ -222,7 +222,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property1: 'a',
property2: [
@@ -263,7 +263,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
)
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -294,7 +294,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
)
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -322,7 +322,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property: [
14: 0.0,
@@ -356,7 +356,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """[
{
"property1": "a"
@@ -391,7 +391,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body """{
"property1": [
{ "property2": "test1"},
@@ -425,7 +425,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body '''\
{
"property1": "a",
@@ -459,7 +459,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body(
property1: "a",
property2: value(
@@ -497,7 +497,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body("""{"property1":"a","property2":"${
value(consumer('123'), producer(regex('[0-9]{3}')))
}"}""")
@@ -532,7 +532,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body("""{"property":" ${
value(consumer('123'), producer(regex('\\d+')))
}"}""")
@@ -578,7 +578,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
}
}
response {
status 200
status OK()
body """
{
"property1": "a",
@@ -636,7 +636,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
}
}
response {
status 200
status OK()
body """
{
"property1": "a",
@@ -709,7 +709,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
url "test"
}
response {
status 200
status OK()
body "test"
}
}
@@ -832,7 +832,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
}
response {
status 200
status OK()
body(errors: [
[property: "bank_account_number", message: "incorrect_format"]
])
@@ -995,7 +995,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
}
response {
status 200
status OK()
body("""{
"fraudCheckStatus": "OK",
"rejectionReason": ${
@@ -1072,7 +1072,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
)
}
response {
status 200
status OK()
headers {
contentType(applicationJson())
}
@@ -1115,7 +1115,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
)
}
response {
status 200
status OK()
headers {
contentType(applicationJson())
}
@@ -1147,7 +1147,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
World.''')
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -1191,7 +1191,7 @@ World.'''"""
)
}
response {
status 200
status OK()
}
}
// end::multipartdsl[]
@@ -1237,7 +1237,7 @@ World.'''"""
)
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -1287,7 +1287,7 @@ World.'''"""
)
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -1322,7 +1322,7 @@ World.'''"""
}
}
response {
status 200
status OK()
body(
authorities: [
value(consumer('ROLE_ADMIN'), producer(regex('^[a-zA-Z0-9_\\- ]+$')))
@@ -1358,7 +1358,7 @@ World.'''"""
}
}
response {
status 200
status OK()
body(
authorities: [
value(consumer('ROLE_ADMIN'), producer(regex('^[a-zA-Z0-9_\\- ]+$')))
@@ -1385,7 +1385,7 @@ World.'''"""
url '/fraudcheck'
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))
@@ -1416,7 +1416,7 @@ World.'''"""
urlPath '/foos'
}
response {
status 200
status OK()
body([[id: value(
consumer('123'),
producer(regex('[0-9]+'))
@@ -1449,7 +1449,7 @@ World.'''"""
urlPath '/api/tags'
}
response {
status 200
status OK()
body(["Java", "Java8", "Spring", "SpringBoot", "Stream"])
headers {
header('Content-Type': 'application/json;charset=UTF-8')
@@ -1486,7 +1486,7 @@ World.'''"""
urlPath '/api/tags'
}
response {
status 200
status OK()
body(["Java", "Java8", "Spring", "SpringBoot", "Stream"])
headers {
header('Content-Type': 'application/json;charset=UTF-8')
@@ -1522,7 +1522,7 @@ World.'''"""
urlPath '/api/categories'
}
response {
status 200
status OK()
body([["Programming", "Java"], ["Programming", "Java", "Spring", "Boot"]])
headers {
header('Content-Type': 'application/json;charset=UTF-8')
@@ -1556,7 +1556,7 @@ World.'''"""
url '/test'
}
response {
status 200
status OK()
async()
}
}
@@ -1590,7 +1590,7 @@ World.'''"""
}
}
response {
status 200
status OK()
async()
}
}
@@ -1620,7 +1620,7 @@ World.'''"""
urlPath '/api/tags'
}
response {
status 200
status OK()
body('''{
"partners":[
{
@@ -1656,7 +1656,7 @@ World.'''"""
urlPath '/get'
}
response {
status 200
status OK()
body( code: 9, message: $(consumer('Wrong credentials'), producer(regex('^(?!\\s*$).+'))) )
}
}
@@ -1712,7 +1712,7 @@ World.'''"""
'''
}
response {
status 200
status OK()
}
}
// end::dsl_example[]
@@ -1731,7 +1731,7 @@ World.'''"""
}
}
response {
status 200
status OK()
body([
responseElement: $(producer(regex('[0-9]{7}')))
])
@@ -1772,7 +1772,7 @@ World.'''"""
urlPath '/get'
}
response {
status 200
status OK()
body([
fraudCheckStatus: "OK",
rejectionReason : [
@@ -1804,7 +1804,7 @@ World.'''"""
urlPath '/get'
}
response {
status 200
status OK()
body([
[
name: $(consumer("userName 1"), producer(execute('assertThatUserNameIsNotNull($it)')))
@@ -1834,7 +1834,7 @@ World.'''"""
urlPath '/get'
}
response {
status 200
status OK()
body([
[
name: $(consumer("userName 1"), producer(execute('assertThatUserNameIsNotNull($it)')))
@@ -1867,7 +1867,7 @@ World.'''"""
}
}
response {
status 200
status OK()
body([
fraudCheckStatus: "OK",
rejectionReason : [
@@ -1899,7 +1899,7 @@ World.'''"""
url '/get'
}
response {
status 200
status OK()
body(value(stub("HELLO FROM STUB"), server(regex(".*"))))
}
}
@@ -1923,7 +1923,7 @@ World.'''"""
url '/get'
}
response {
status 200
status OK()
body(value(stub("HELLO FROM STUB"), server(execute('foo($it)'))))
}
}
@@ -1953,7 +1953,7 @@ World.'''"""
}
}
response {
status 200
status OK()
body([
fraudCheckStatus: "OK",
rejectionReason : [
@@ -2007,7 +2007,7 @@ World.'''"""
}
}
response {
status 200
status OK()
body([
alpha: $(anyAlphaUnicode()),
number: $(anyNumber()),
@@ -2086,7 +2086,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
}
}
response {
status 200
status OK()
headers {
contentType("application/vnd.fraud.v1+json")
}
@@ -2186,7 +2186,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
url '/foo'
}
response {
status 200
status OK()
headers {
contentType(applicationJsonUtf8())
}
@@ -2225,7 +2225,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
headers { header('Content-Type', 'application/json;charset=UTF-8') }
}
response {
status 200
status OK()
body(
bar: $(producer(regex('some value \u0022with quote\u0022|bar')))
)
@@ -2257,7 +2257,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
url $(c("foo"), p(execute("executedMethod()")))
}
response {
status 200
status OK()
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
@@ -2291,7 +2291,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
url '/api/v1/xxxx'
}
response {
status 200
status OK()
body([
status: '200',
list: [],
@@ -2327,7 +2327,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
body(12000)
}
response {
status 200
status OK()
body(12000)
}
}
@@ -2369,7 +2369,7 @@ DocumentContext parsedJson = JsonPath.parse(json);
body(foo: "bar", baz: 5)
}
response {
status 200
status OK()
headers {
header(authorization(), "foo ${fromRequest().header(authorization())} bar")
}

View File

@@ -73,7 +73,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
}
}
response {
status 200
status OK()
body([
duck: 123,
alpha: "abc",
@@ -200,7 +200,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
url 'person'
}
response {
status 200
status OK()
body([
"firstName": "Jane",
"lastName": "Doe",
@@ -270,7 +270,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
url 'person'
}
response {
status 200
status OK()
body([
"phoneNumbers": [
number: "foo"
@@ -323,7 +323,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
url 'person'
}
response {
status 200
status OK()
body([
"phoneNumbers": [
number: "foo"
@@ -358,7 +358,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
url 'person'
}
response {
status 200
status OK()
body([
"phoneNumbers": [
number: "foo"
@@ -394,7 +394,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
body(12000)
}
response {
status 200
status OK()
body ([[
[ access_token: '123']
]])
@@ -434,7 +434,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
headers { header "accept", "application/...json" }
}
response {
status 200
status OK()
body("""
{
"items": [
@@ -481,7 +481,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
headers { header "accept", "application/...json" }
}
response {
status 200
status OK()
body([
"items": [
"id" : "35309",

View File

@@ -123,7 +123,7 @@ class SingleTestGeneratorSpec extends Specification {
url 'url'
}
response {
status 200
status OK()
}
}
""")
@@ -226,7 +226,7 @@ class SingleTestGeneratorSpec extends Specification {
}
}
response {
status 200
status OK()
body(foo:"foo", bar:"bar")
headers {
contentType(applicationJson())
@@ -246,7 +246,7 @@ class SingleTestGeneratorSpec extends Specification {
}
}
response {
status 200
status OK()
body(foo:"foo", bar:"bar")
headers {
contentType(applicationJson())
@@ -369,7 +369,7 @@ class SingleTestGeneratorSpec extends Specification {
url 'url'
}
response {
status 200
status OK()
}
}
""")
@@ -433,7 +433,7 @@ class SingleTestGeneratorSpec extends Specification {
url '/my-context-path/url'
}
response {
status 200
status OK()
}
}
// end::context_path_contract[]
@@ -466,7 +466,7 @@ class SingleTestGeneratorSpec extends Specification {
url 'url'
}
response {
status 200
status OK()
}
}
""")
@@ -498,7 +498,7 @@ class SingleTestGeneratorSpec extends Specification {
url "/${index}"
}
response {
status 200
status OK()
}
}
}''')
@@ -530,7 +530,7 @@ class SingleTestGeneratorSpec extends Specification {
url "/${index}"
}
response {
status 200
status OK()
}
}
}''')

View File

@@ -45,7 +45,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
url $(consumer(~/\/[0-9]{2}/), producer('/12'))
}
response {
status 200
status OK()
body(
id: value(
consumer('123'),
@@ -98,7 +98,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
body(
ingredients: [
[type: 'MALT', quantity: 100],
@@ -196,7 +196,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
url $(consumer(~/\/[0-9]{2}/), producer('/12'))
}
response {
status 200
status OK()
body("""\
{
"id": "${value(consumer('123'), producer('321'))}",
@@ -254,7 +254,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
"""
}
response {
status 200
status OK()
body("""\
{
"name": "Jan"
@@ -312,7 +312,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
)
}
response {
status 200
status OK()
}
}
when:
@@ -359,7 +359,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
"""
}
response {
status 200
status OK()
}
}
when:
@@ -403,7 +403,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}</jobId></foo>"""
}
response {
status 200
status OK()
}
}
when:
@@ -446,7 +446,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}</jobId></user>"""
}
response {
status 200
status OK()
}
}
when:
@@ -481,7 +481,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
url "/users"
}
response {
status 200
status OK()
body """<user><name>${value(consumer('Jozo'), producer('Denis'))}</name><jobId>${
value(consumer("<test>"), producer('1234567890'))
}</jobId></user>"""
@@ -516,7 +516,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
body equalToJson('''{"name":"Jan"}''')
}
response {
status 200
status OK()
}
}
when:
@@ -554,7 +554,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}</jobId></foo>""")
}
response {
status 200
status OK()
}
}
when:
@@ -594,7 +594,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
"""
}
response {
status 200
status OK()
body("""\
{
"name": "Jan"
@@ -651,7 +651,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
response {
status 200
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))
@@ -714,7 +714,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
when:
@@ -774,7 +774,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
when:
@@ -815,7 +815,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
when:
@@ -851,7 +851,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
urlPath $(consumer("boxes"), producer("items"))
}
response {
status 200
status OK()
}
}
when:
@@ -881,7 +881,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
urlPath "boxes"
}
response {
status 200
status OK()
}
}
when:
@@ -916,7 +916,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
then:
@@ -936,7 +936,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
then:
@@ -956,7 +956,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
then:
@@ -982,7 +982,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
},
{
@@ -995,7 +995,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
},
{
@@ -1008,7 +1008,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
]
@@ -1027,7 +1027,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
when:
@@ -1083,7 +1083,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
"""
}
response {
status 200
status OK()
body("""\
{
"name": "Jan"
@@ -1145,7 +1145,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
)
}
response {
status 200
status OK()
body '''
{
"status": "OK"
@@ -1266,7 +1266,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
)
}
response {
status 200
status OK()
}
}
when:
@@ -1302,7 +1302,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
)
}
response {
status 200
status OK()
}
}
when:
@@ -1562,7 +1562,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
)
}
response {
status 200
status OK()
}
}
// end::multipartdsl[]
@@ -1626,7 +1626,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
body(
content: [[
id : '00000000-0000-0000-0000-000000000000',
@@ -1698,7 +1698,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
body('')
}
}
@@ -1724,7 +1724,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
body('')
}
}
@@ -1753,7 +1753,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
body(foo: "bar", baz: 5)
}
response {
status 200
status OK()
headers {
header(authorization(), "${fromRequest().header(authorization())};foo")
}
@@ -1850,7 +1850,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
}
}
when:
@@ -1960,7 +1960,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
}
}
response {
status 200
status OK()
body("""
{
"code": 91015,

View File

@@ -41,7 +41,7 @@ class ContractVerifierDslConverterSpec extends Specification {
url("/1")
}
response {
status 200
status OK()
body(""" { "status" : "OK" } """)
headers {
contentType(textPlain())
@@ -60,7 +60,7 @@ class ContractVerifierDslConverterSpec extends Specification {
url("/${index}")
}
response {
status 200
status OK()
body(""" { "status" : "OK" } """)
headers {
contentType(textPlain())

View File

@@ -10,7 +10,7 @@ Contract.make {
url("/1")
}
response {
status 200
status OK()
body(file("response.json"))
headers {
contentType(textPlain())

View File

@@ -26,7 +26,7 @@ Contract.make {
url("/1")
}
response {
status 200
status OK()
body(""" { "status" : "OK" } """)
headers {
contentType(textPlain())

View File

@@ -32,7 +32,7 @@ Contract.make {
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status 200
status OK()
body("""\
{
"name": "Jan",

View File

@@ -32,7 +32,7 @@ Contract.make {
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status 200
status OK()
body("""\
{
"name": "Jan",

View File

@@ -26,7 +26,7 @@ import org.springframework.cloud.contract.spec.Contract
url("/${index}")
}
response {
status 200
status OK()
body(""" { "status" : "OK" } """)
headers {
contentType(textPlain())