Skip to content

Commit a061f16

Browse files
Added standalone samples
1 parent 99ca103 commit a061f16

File tree

233 files changed

+14493
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+14493
-10
lines changed

pom.xml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
<activeByDefault>true</activeByDefault>
3131
</activation>
3232
<modules>
33+
<!-- standalone -->
34+
<module>standalone/contracts</module>
35+
<module>standalone/dsl/http-server</module>
36+
<module>standalone/dsl/http-client</module>
37+
<module>standalone/restdocs/http-server</module>
38+
<module>standalone/restdocs/http-client</module>
39+
<module>standalone/webclient/http-server</module>
40+
<module>standalone/webclient/http-client</module>
41+
3342
<module>common</module>
3443
<module>wiremock</module>
3544
<module>wiremock-for-contract-docs</module>
@@ -93,6 +102,15 @@
93102
<activeByDefault>false</activeByDefault>
94103
</activation>
95104
<modules>
105+
<!-- standalone -->
106+
<module>standalone/contracts</module>
107+
<module>standalone/dsl/http-server</module>
108+
<module>standalone/dsl/http-client</module>
109+
<module>standalone/restdocs/http-server</module>
110+
<module>standalone/restdocs/http-client</module>
111+
<module>standalone/webclient/http-server</module>
112+
<module>standalone/webclient/http-client</module>
113+
96114
<module>beer_contracts</module>
97115
<module>wiremock</module>
98116
<module>wiremock-for-contract-docs</module>
@@ -149,16 +167,6 @@
149167
<module>consumer_kotlin</module>
150168
</modules>
151169
</profile>
152-
<profile>
153-
<id>highmem</id>
154-
<activation>
155-
<activeByDefault>false</activeByDefault>
156-
</activation>
157-
<modules>
158-
<module>producer_java</module>
159-
<module>consumer_java</module>
160-
</modules>
161-
</profile>
162170
</profiles>
163171

164172
</project>

scripts/runGradleBuilds.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ function build_gradle() {
6060
if [[ "${BUILD_COMMON}" == "true" ]]; then
6161
build common
6262
fi
63+
# Standalone
64+
build standalone/contracts
65+
build standalone/dsl/http-server
66+
build standalone/dsl/http-client
67+
build standalone/restdocs/http-server
68+
build standalone/restdocs/http-client
69+
build standalone/webclient/http-server
70+
build standalone/webclient/http-client
71+
6372
build producer
6473
build producer_testng
6574
# build producer_jaxrs
48.4 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip

standalone/contracts/README.adoc

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
= Common contracts repo
2+
3+
This repo contains all contracts for apps in the system.
4+
5+
== As a consumer
6+
7+
You are working offline in order to play around with the API of the producer.
8+
What you need to do is to have the producer's stubs installed locally. To do that
9+
you have to (from the root of the repo)
10+
11+
[source,bash]
12+
----
13+
cd com/example/server/
14+
mvn clean install -DskipTests
15+
----
16+
17+
Then if you do `ls ./target` you'll see `server-0.0.1-SNAPSHOT-stubs.jar`. This jar will
18+
contain the stubs generated from your contracts. That way you
19+
can reference the `com.example:server:+:stubs` dependency in your consumer tests.
20+
21+
== As a producer
22+
23+
Assuming that the consumers have filed a PR with the proposed contract the producers
24+
can work offline to generate tests and stubs. To work offline, as a producer you just have
25+
to go to the root folder of the contracts and:
26+
27+
[source,bash]
28+
----
29+
./mvnw clean install -DskipTests
30+
----
31+
32+
Then if you do `ls ./target` you'll see `contracts-0.0.1-SNAPSHOT.jar`. This file contains
33+
all DSL contracts, for all applications.
34+
35+
Now the producer can include the `contracts-0.0.1-SNAPSHOT.jar` from your local maven repository.
36+
You can achieve that by setting the proper flag in plugin properties.
37+
38+
Example for Maven
39+
40+
[source,xml]
41+
----
42+
<plugin>
43+
<groupId>org.springframework.cloud</groupId>
44+
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
45+
<configuration>
46+
<contractsMode>LOCAL</contractsMode>
47+
<contractDependency>
48+
<groupId>com.example.standalone</groupId>
49+
<artifactId>contracts</artifactId>
50+
</contractDependency>
51+
</configuration>
52+
</plugin>
53+
----
54+
55+
and for Gradle:
56+
57+
[source,groovy]
58+
----
59+
contracts {
60+
testFramework ='Spock'
61+
testMode = 'JaxRsClient'
62+
baseClassForTests = 'org.springframework.cloud.MvcSpec'
63+
stubsMode = 'LOCAL'
64+
contractDependency {
65+
stringNotation = "com.example:contracts"
66+
}
67+
}
68+
----
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package contracts
18+
19+
org.springframework.cloud.contract.spec.Contract.make {
20+
request { // (1)
21+
method 'PUT' // (2)
22+
url '/fraudcheck' // (3)
23+
body([ // (4)
24+
clientId : $(regex('[0-9]{10}')),
25+
loanAmount: 99999
26+
])
27+
headers { // (5)
28+
contentType('application/vnd.fraud.v1+json')
29+
}
30+
}
31+
response { // (6)
32+
status OK() // (7)
33+
body([ // (8)
34+
fraudCheckStatus: "FRAUD",
35+
rejectionReason : "Amount too high"
36+
])
37+
headers { // (9)
38+
contentType('application/vnd.fraud.v1+json')
39+
}
40+
}
41+
}
42+
43+
/*
44+
Since we don't want to force on the user to hardcode values of fields that are dynamic
45+
(timestamps, database ids etc.), one can parametrize those entries. If you wrap your field's
46+
value in a `$(...)` or `value(...)` and provide a dynamic value of a field then
47+
the concrete value will be generated for you. If you want to be really explicit about
48+
which side gets which value you can do that by using the `value(consumer(...), producer(...))` notation.
49+
That way what's present in the `consumer` section will end up in the produced stub. What's
50+
there in the `producer` will end up in the autogenerated test. If you provide only the
51+
regular expression side without the concrete value then Spring Cloud Contract will generate one for you.
52+
53+
From the Consumer perspective, when shooting a request in the integration test:
54+
55+
(1) - If the consumer sends a request
56+
(2) - With the "PUT" method
57+
(3) - to the URL "/fraudcheck"
58+
(4) - with the JSON body that
59+
* has a field `clientId` that matches a regular expression `[0-9]{10}`
60+
* has a field `loanAmount` that is equal to `99999`
61+
(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
62+
(6) - then the response will be sent with
63+
(7) - status equal `200`
64+
(8) - and JSON body equal to
65+
{ "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
66+
(9) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
67+
68+
From the Producer perspective, in the autogenerated producer-side test:
69+
70+
(1) - A request will be sent to the producer
71+
(2) - With the "PUT" method
72+
(3) - to the URL "/fraudcheck"
73+
(4) - with the JSON body that
74+
* has a field `clientId` that will have a generated value that matches a regular expression `[0-9]{10}`
75+
* has a field `loanAmount` that is equal to `99999`
76+
(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
77+
(6) - then the test will assert if the response has been sent with
78+
(7) - status equal `200`
79+
(8) - and JSON body equal to
80+
{ "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
81+
(9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*`
82+
*/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package contracts
18+
19+
org.springframework.cloud.contract.spec.Contract.make {
20+
request { // (1)
21+
method 'PUT' // (2)
22+
url '/fraudcheck2' // (3)
23+
body([ // (4)
24+
clientId : value(consumer(regex('[0-9]{10}'))),
25+
loanAmount: 99999
26+
])
27+
headers { // (5)
28+
header('Content-Type', 'application/vnd.fraud.v1+json')
29+
}
30+
}
31+
response { // (6)
32+
status OK() // (7)
33+
body([ // (8)
34+
fraudCheckStatus: "FRAUD",
35+
rejectionReason : "Amount too high"
36+
])
37+
headers { // (9)
38+
header('Content-Type': value(
39+
producer(regex('application/vnd.fraud.v1.json.*')),
40+
consumer('application/vnd.fraud.v1+json'))
41+
)
42+
}
43+
}
44+
}
45+
46+
/*
47+
Since we don't want to force on the user to hardcode values of fields that are dynamic
48+
(timestamps, database ids etc.), one can provide parametrize those entries by using the
49+
`value(consumer(...), producer(...))` method. That way what's present in the `consumer`
50+
section will end up in the produced stub. What's there in the `producer` will end up in the
51+
autogenerated test. If you provide only the regular expression side without the concrete
52+
value then Spring Cloud Contract will generate one for you.
53+
54+
From the Consumer perspective, when shooting a request in the integration test:
55+
56+
(1) - If the consumer sends a request
57+
(2) - With the "PUT" method
58+
(3) - to the URL "/fraudcheck"
59+
(4) - with the JSON body that
60+
* has a field `clientId` that matches a regular expression `[0-9]{10}`
61+
* has a field `loanAmount` that is equal to `99999`
62+
(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
63+
(6) - then the response will be sent with
64+
(7) - status equal `200`
65+
(8) - and JSON body equal to
66+
{ "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
67+
(9) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
68+
69+
From the Producer perspective, in the autogenerated producer-side test:
70+
71+
(1) - A request will be sent to the producer
72+
(2) - With the "PUT" method
73+
(3) - to the URL "/fraudcheck"
74+
(4) - with the JSON body that
75+
* has a field `clientId` that will have a generated value that matches a regular expression `[0-9]{10}`
76+
* has a field `loanAmount` that is equal to `99999`
77+
(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
78+
(6) - then the test will assert if the response has been sent with
79+
(7) - status equal `200`
80+
(8) - and JSON body equal to
81+
{ "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
82+
(9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*`
83+
*/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package contracts
18+
19+
org.springframework.cloud.contract.spec.Contract.make {
20+
request { // (1)
21+
method 'PUT' // (2)
22+
url '/fraudcheck3' // (3)
23+
body([ // (4)
24+
clientId : value(consumer(regex('[0-9]{10}'))),
25+
loanAmount: 99999
26+
])
27+
headers { // (5)
28+
header('Content-Type', 'application/vnd.fraud.v1+json')
29+
}
30+
}
31+
response { // (6)
32+
status OK() // (7)
33+
body([ // (8)
34+
fraudCheckStatus: "FRAUD",
35+
rejectionReason : "Amount too high"
36+
])
37+
headers { // (9)
38+
header('Content-Type': value(
39+
producer(regex('application/vnd.fraud.v1.json.*')),
40+
consumer('application/vnd.fraud.v1+json'))
41+
)
42+
}
43+
}
44+
}
45+
46+
/*
47+
Since we don't want to force on the user to hardcode values of fields that are dynamic
48+
(timestamps, database ids etc.), one can provide parametrize those entries by using the
49+
`value(consumer(...), producer(...))` method. That way what's present in the `consumer`
50+
section will end up in the produced stub. What's there in the `producer` will end up in the
51+
autogenerated test. If you provide only the regular expression side without the concrete
52+
value then Spring Cloud Contract will generate one for you.
53+
54+
From the Consumer perspective, when shooting a request in the integration test:
55+
56+
(1) - If the consumer sends a request
57+
(2) - With the "PUT" method
58+
(3) - to the URL "/fraudcheck"
59+
(4) - with the JSON body that
60+
* has a field `clientId` that matches a regular expression `[0-9]{10}`
61+
* has a field `loanAmount` that is equal to `99999`
62+
(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
63+
(6) - then the response will be sent with
64+
(7) - status equal `200`
65+
(8) - and JSON body equal to
66+
{ "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
67+
(9) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
68+
69+
From the Producer perspective, in the autogenerated producer-side test:
70+
71+
(1) - A request will be sent to the producer
72+
(2) - With the "PUT" method
73+
(3) - to the URL "/fraudcheck"
74+
(4) - with the JSON body that
75+
* has a field `clientId` that will have a generated value that matches a regular expression `[0-9]{10}`
76+
* has a field `loanAmount` that is equal to `99999`
77+
(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
78+
(6) - then the test will assert if the response has been sent with
79+
(7) - status equal `200`
80+
(8) - and JSON body equal to
81+
{ "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
82+
(9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*`
83+
*/

0 commit comments

Comments
 (0)