Skip to content

Commit 4c7fb61

Browse files
authored
Merge pull request #36 from YOU54F/main
chore(deps): main - Java17 / Pact 4.6.5
2 parents c642c73 + 1aaafde commit 4c7fb61

File tree

11 files changed

+117
-59
lines changed

11 files changed

+117
-59
lines changed

.github/workflows/test.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: 17
21+
distribution: 'temurin'
22+
23+
- name: Test consumer tests
24+
run: ./gradlew consumer:test
25+
- name: Test consumer pact tests
26+
run: ./gradlew consumer:test --tests '*Pact*Test'
27+
- uses: KengoTODA/actions-setup-docker-compose@v1
28+
if: ${{ env.ACT }}
29+
name: Install `docker-compose` for use with act
30+
with:
31+
version: '2.24.1'
32+
- name: Start broker
33+
run: docker-compose up -d
34+
- name: Publish consumer pacts
35+
run: ./gradlew consumer:test --tests '*PactTest*' pactPublish
36+
- name: Test provider pact tests
37+
run: ./gradlew provider:test --tests '*Pact*Test'

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ build/
33
!../gradle/wrapper/gradle-wrapper.jar
44
!**/src/main/**/build/
55
!**/src/test/**/build/
6-
6+
consumer/bin
7+
provider/bin
78
provider/src/test/resources/pacts
89

910
### STS ###
@@ -47,3 +48,7 @@ gradle-app.setting
4748

4849
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
4950
# gradle/wrapper/gradle-wrapper.properties
51+
52+
## MacOS
53+
54+
.DS_Store

.java-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17.0

README.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,14 @@ This test starts a mock server on a random port that acts as our provider servic
317317
To run only the Pact tests:
318318

319319
```console
320-
> ./gradlew consumer:test --tests *PactTest
320+
> ./gradlew consumer:test --tests '*PactTest'
321321

322322
```
323323

324324
Running this test still passes, but it creates a pact file which we can use to validate our assumptions on the provider side, and have conversation around.
325325

326326
```console
327-
./gradlew consumer:test --tests *PactTest
327+
./gradlew consumer:test --tests '*PactTest'
328328
329329
BUILD SUCCESSFUL in 6s
330330
```
@@ -386,13 +386,13 @@ public class ProductPactProviderTest {
386386
To run only the verification tests:
387387

388388
```console
389-
> ./gradlew provider:test --tests *Pact*Test
389+
> ./gradlew provider:test --tests '*Pact*Test'
390390
```
391391

392392
We now need to validate the pact generated by the consumer is valid, by executing it against the running service provider, which should fail:
393393

394394
```console
395-
./gradlew provider:test --tests *Pact*Test
395+
./gradlew provider:test --tests '*Pact*Test'
396396

397397
...
398398
...
@@ -476,7 +476,7 @@ Copy the updated contract located in `consumer/build/pacts/FrontendApplication-P
476476
Run the command:
477477

478478
```console
479-
./gradlew provider:test --tests *Pact*Test
479+
./gradlew provider:test --tests '*Pact*Test'
480480

481481
...
482482
...
@@ -545,14 +545,14 @@ In `consumer/src/test/java/au/com/dius/pactworkshop/consumer/ProductConsumerPact
545545

546546
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
547547
() -> new ProductService(restTemplate).getProduct("11"));
548-
assertEquals(404, e.getRawStatusCode());
548+
assertEquals(404, e.getStatusCode().value());
549549
}
550550
```
551551

552552
Notice that our new tests look almost identical to our previous tests, and only differ on the expectations of the _response_ - the HTTP request expectations are exactly the same.
553553

554554
```console
555-
./gradlew consumer:test --tests *PactTest
555+
./gradlew consumer:test --tests '*PactTest'
556556
557557
BUILD SUCCESSFUL in 1s
558558
```
@@ -568,7 +568,7 @@ What does our provider have to say about this new test. Again, copy the updated
568568
and run the command:
569569

570570
```console
571-
./gradlew provider:test --tests *Pact*Test
571+
./gradlew provider:test --tests '*Pact*Test'
572572

573573
...
574574
...
@@ -818,7 +818,7 @@ public class ProductConsumerPactTest {
818818

819819
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
820820
() -> new ProductService(restTemplate).getAllProducts());
821-
assertEquals(401, e.getRawStatusCode());
821+
assertEquals(401, e.getStatusCode().value());
822822
}
823823

824824
@Test
@@ -846,7 +846,7 @@ public class ProductConsumerPactTest {
846846

847847
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
848848
() -> new ProductService(restTemplate).getProduct("11"));
849-
assertEquals(404, e.getRawStatusCode());
849+
assertEquals(404, e.getStatusCode().value());
850850
}
851851

852852
@Test
@@ -858,7 +858,7 @@ public class ProductConsumerPactTest {
858858

859859
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
860860
() -> new ProductService(restTemplate).getProduct("10"));
861-
assertEquals(401, e.getRawStatusCode());
861+
assertEquals(401, e.getStatusCode().value());
862862
}
863863

864864
private Map<String, String> headers() {
@@ -1084,7 +1084,7 @@ pact {
10841084
pactBrokerUrl = 'http://localhost:8000/'
10851085
pactBrokerUsername = getOrDefault('PACT_BROKER_USERNAME', 'pact_workshop')
10861086
pactBrokerPassword = getOrDefault('PACT_BROKER_PASSWORD', 'pact_workshop')
1087-
tags = [getGitBranch(), 'test', 'prod']
1087+
consumerBranch = getGitBranch()
10881088
consumerVersion = getGitHash()
10891089
}
10901090
}
@@ -1093,10 +1093,11 @@ pact {
10931093
Now run
10941094

10951095
```console
1096-
./gradlew consumer:test --tests *PactTest* pactPublish
1096+
./gradlew consumer:test --tests '*PactTest*' pactPublish
10971097
10981098
> Task :consumer:pactPublish
1099-
Publishing 'FrontendApplication-ProductService.json' with tags step11, test, prod ... OK
1099+
Publishing 'FrontendApplication-ProductService.json'
1100+
OK
11001101
11011102
BUILD SUCCESSFUL in 11s
11021103

@@ -1150,9 +1151,9 @@ def getGitBranch = { ->
11501151
test {
11511152
useJUnitPlatform()
11521153
1154+
systemProperty 'pact.provider.branch', getGitBranch()
11531155
if (System.getProperty('pactPublishResults') == 'true') {
11541156
systemProperty 'pact.provider.version', getGitHash()
1155-
systemProperty 'pact.provider.tag', getGitBranch()
11561157
systemProperty 'pact.verifier.publishResults', 'true'
11571158
}
11581159
}

consumer/build.gradle

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ buildscript {
33
mavenCentral()
44
}
55
dependencies {
6-
classpath 'au.com.dius.pact.provider:gradle:4.1.7'
6+
classpath 'au.com.dius.pact.provider:gradle:4.6.5'
77
}
88
}
99

1010
plugins {
11-
id 'org.springframework.boot' version '2.3.4.RELEASE'
12-
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
13-
id 'au.com.dius.pact' version '4.1.7'
11+
// Stopped from moving to 3.2.x due to wiremock issue
12+
// https://github.com/wiremock/wiremock/issues/2395
13+
id 'org.springframework.boot' version '3.1.8'
14+
id 'io.spring.dependency-management' version '1.1.4'
15+
id 'au.com.dius.pact' version '4.6.5'
1416
}
1517

1618
group = 'au.com.dius.pactworkshop'
1719
version = '0.0.1-SNAPSHOT'
18-
sourceCompatibility = '8'
20+
sourceCompatibility = '17'
1921

2022

2123

@@ -26,9 +28,8 @@ dependencies {
2628
testImplementation('org.springframework.boot:spring-boot-starter-test') {
2729
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
2830
}
29-
testImplementation 'com.github.tomakehurst:wiremock:2.27.2'
30-
testImplementation 'au.com.dius.pact.consumer:java8:4.1.7'
31-
testImplementation 'au.com.dius.pact.consumer:junit5:4.1.7'
31+
testImplementation 'com.github.tomakehurst:wiremock:3.0.1'
32+
testImplementation 'au.com.dius.pact.consumer:junit5:4.6.5'
3233
}
3334

3435
test {
@@ -70,7 +71,7 @@ pact {
7071
pactBrokerUrl = 'http://localhost:8000/'
7172
pactBrokerUsername = 'pact_workshop'
7273
pactBrokerPassword = 'pact_workshop'
73-
tags = [getGitBranch(), 'test', 'prod']
74+
consumerBranch = getGitBranch()
7475
consumerVersion = getGitHash()
7576
}
7677
}

consumer/src/test/java/au/com/dius/pactworkshop/consumer/ProductConsumerPactTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
import org.springframework.boot.web.client.RestTemplateBuilder;
1212
import org.springframework.web.client.HttpClientErrorException;
1313
import org.springframework.web.client.RestTemplate;
14-
14+
import au.com.dius.pact.core.model.PactSpecVersion; // required for v4.6.x to set pactVersion
1515
import java.util.Collections;
1616
import java.util.Arrays;
1717
import java.util.HashMap;
1818
import java.util.List;
1919
import java.util.Map;
2020

21-
import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArrayMinLike;
22-
import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody;
21+
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonArrayMinLike;
22+
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonBody;
2323
import static org.junit.jupiter.api.Assertions.assertEquals;
2424
import static org.junit.jupiter.api.Assertions.assertThrows;
2525

@@ -113,7 +113,7 @@ RequestResponsePact singleProductnoAuthToken(PactDslWithProvider builder) {
113113
}
114114

115115
@Test
116-
@PactTestFor(pactMethod = "getAllProducts")
116+
@PactTestFor(pactMethod = "getAllProducts", pactVersion = PactSpecVersion.V3)
117117
void getAllProducts_whenProductsExist(MockServer mockServer) {
118118
Product product = new Product();
119119
product.setId("09");
@@ -130,7 +130,7 @@ void getAllProducts_whenProductsExist(MockServer mockServer) {
130130
}
131131

132132
@Test
133-
@PactTestFor(pactMethod = "noProductsExist")
133+
@PactTestFor(pactMethod = "noProductsExist", pactVersion = PactSpecVersion.V3)
134134
void getAllProducts_whenNoProductsExist(MockServer mockServer) {
135135
RestTemplate restTemplate = new RestTemplateBuilder()
136136
.rootUri(mockServer.getUrl())
@@ -141,19 +141,19 @@ void getAllProducts_whenNoProductsExist(MockServer mockServer) {
141141
}
142142

143143
@Test
144-
@PactTestFor(pactMethod = "allProductsNoAuthToken")
144+
@PactTestFor(pactMethod = "allProductsNoAuthToken", pactVersion = PactSpecVersion.V3)
145145
void getAllProducts_whenNoAuth(MockServer mockServer) {
146146
RestTemplate restTemplate = new RestTemplateBuilder()
147147
.rootUri(mockServer.getUrl())
148148
.build();
149149

150150
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
151151
() -> new ProductService(restTemplate).getAllProducts());
152-
assertEquals(401, e.getRawStatusCode());
152+
assertEquals(401, e.getStatusCode().value());
153153
}
154154

155155
@Test
156-
@PactTestFor(pactMethod = "getOneProduct")
156+
@PactTestFor(pactMethod = "getOneProduct", pactVersion = PactSpecVersion.V3)
157157
void getProductById_whenProductWithId10Exists(MockServer mockServer) {
158158
Product expected = new Product();
159159
expected.setId("10");
@@ -169,27 +169,27 @@ void getProductById_whenProductWithId10Exists(MockServer mockServer) {
169169
}
170170

171171
@Test
172-
@PactTestFor(pactMethod = "productDoesNotExist")
172+
@PactTestFor(pactMethod = "productDoesNotExist", pactVersion = PactSpecVersion.V3)
173173
void getProductById_whenProductWithId11DoesNotExist(MockServer mockServer) {
174174
RestTemplate restTemplate = new RestTemplateBuilder()
175175
.rootUri(mockServer.getUrl())
176176
.build();
177177

178178
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
179179
() -> new ProductService(restTemplate).getProduct("11"));
180-
assertEquals(404, e.getRawStatusCode());
180+
assertEquals(404, e.getStatusCode().value());
181181
}
182182

183183
@Test
184-
@PactTestFor(pactMethod = "singleProductnoAuthToken")
184+
@PactTestFor(pactMethod = "singleProductnoAuthToken", pactVersion = PactSpecVersion.V3)
185185
void getProductById_whenNoAuth(MockServer mockServer) {
186186
RestTemplate restTemplate = new RestTemplateBuilder()
187187
.rootUri(mockServer.getUrl())
188188
.build();
189189

190190
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
191191
() -> new ProductService(restTemplate).getProduct("10"));
192-
assertEquals(401, e.getRawStatusCode());
192+
assertEquals(401, e.getStatusCode().value());
193193
}
194194

195195
private Map<String, String> headers() {

docker-compose.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ services:
1212
POSTGRES_PASSWORD: password
1313
POSTGRES_DB: postgres
1414

15-
broker_app:
16-
image: pactfoundation/pact-broker
15+
pact-broker:
16+
image: pactfoundation/pact-broker:latest-multi
1717
links:
1818
- postgres
1919
ports:
2020
- 8000:9292
21+
restart: always
2122
environment:
2223
PACT_BROKER_BASIC_AUTH_USERNAME: pact_workshop
2324
PACT_BROKER_BASIC_AUTH_PASSWORD: pact_workshop
2425
PACT_BROKER_DATABASE_USERNAME: postgres
2526
PACT_BROKER_DATABASE_PASSWORD: password
2627
PACT_BROKER_DATABASE_HOST: postgres
2728
PACT_BROKER_DATABASE_NAME: postgres
29+
PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "10"
30+
PACT_BROKER_PUBLIC_HEARTBEAT: "true"
31+
PACT_BROKER_WEBHOOK_SCHEME_WHITELIST: http
32+
PACT_BROKER_WEBHOOK_HOST_WHITELIST: host.docker.internal
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

provider/build.gradle

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
plugins {
2-
id 'org.springframework.boot' version '2.3.4.RELEASE'
3-
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
2+
id 'org.springframework.boot' version '3.2.2'
3+
id 'io.spring.dependency-management' version '1.1.4'
44
}
55

66
group = 'au.com.dius.pactworkshop'
77
version = '0.0.1-SNAPSHOT'
8-
sourceCompatibility = '8'
8+
sourceCompatibility = '17'
99

1010
dependencies {
1111
implementation 'org.springframework.boot:spring-boot-starter'
1212
implementation 'org.springframework.boot:spring-boot-starter-web'
13-
13+
implementation 'org.apache.httpcomponents:httpcore:4.4.1'
14+
implementation 'org.apache.httpcomponents:httpclient:4.5'
1415
testImplementation('org.springframework.boot:spring-boot-starter-test') {
1516
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
1617
}
17-
testImplementation("au.com.dius.pact.provider:junit5:4.1.7")
18+
testImplementation("au.com.dius.pact.provider:junit5:4.6.5")
1819
}
1920

2021
def getGitHash = { ->
@@ -38,9 +39,9 @@ def getGitBranch = { ->
3839
test {
3940
useJUnitPlatform()
4041

42+
systemProperty 'pact.provider.branch', getGitBranch()
4143
if (System.getProperty('pactPublishResults') == 'true') {
4244
systemProperty 'pact.provider.version', getGitHash()
43-
systemProperty 'pact.provider.tag', getGitBranch()
4445
systemProperty 'pact.verifier.publishResults', 'true'
4546
}
4647
}

0 commit comments

Comments
 (0)