Skip to content

Commit 1386d4a

Browse files
authored
chore(deps): step7 - Java17 / Pact 4.6.5 (#31)
1 parent 7d822e2 commit 1386d4a

File tree

10 files changed

+68
-31
lines changed

10 files changed

+68
-31
lines changed

.github/workflows/test.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- step7
6+
pull_request:
7+
branches:
8+
- step7
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+
- name: Copy consumer pacts
28+
run: ./gradlew consumer:copyPacts
29+
- name: Test provider pact tests
30+
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

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ step of the workshop just check out the branch for that step (i.e. `git checkout
77

88
## Requirements
99

10-
* JDK 8+
10+
* JDK 17+
1111
* Docker for step 11
1212

1313
## Workshop outline:
@@ -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
...

consumer/build.gradle

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
plugins {
2-
id 'org.springframework.boot' version '2.3.4.RELEASE'
3-
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
2+
// Stopped from moving to 3.2.x due to wiremock issue
3+
// https://github.com/wiremock/wiremock/issues/2395
4+
id 'org.springframework.boot' version '3.1.8'
5+
id 'io.spring.dependency-management' version '1.1.4'
46
}
57

68
group = 'au.com.dius.pactworkshop'
79
version = '0.0.1-SNAPSHOT'
8-
sourceCompatibility = '8'
10+
sourceCompatibility = '17'
911

1012
dependencies {
1113
implementation 'org.springframework.boot:spring-boot-starter'
@@ -14,9 +16,8 @@ dependencies {
1416
testImplementation('org.springframework.boot:spring-boot-starter-test') {
1517
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
1618
}
17-
testImplementation 'com.github.tomakehurst:wiremock:2.27.2'
18-
testImplementation 'au.com.dius.pact.consumer:java8:4.1.7'
19-
testImplementation 'au.com.dius.pact.consumer:junit5:4.1.7'
19+
testImplementation 'com.github.tomakehurst:wiremock:3.0.1'
20+
testImplementation 'au.com.dius.pact.consumer:junit5:4.6.5'
2021
}
2122

2223
test {

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

+8-8
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

@@ -87,7 +87,7 @@ RequestResponsePact productDoesNotExist(PactDslWithProvider builder) {
8787
}
8888

8989
@Test
90-
@PactTestFor(pactMethod = "getAllProducts")
90+
@PactTestFor(pactMethod = "getAllProducts", pactVersion = PactSpecVersion.V3)
9191
void getAllProducts_whenProductsExist(MockServer mockServer) {
9292
Product product = new Product();
9393
product.setId("09");
@@ -104,7 +104,7 @@ void getAllProducts_whenProductsExist(MockServer mockServer) {
104104
}
105105

106106
@Test
107-
@PactTestFor(pactMethod = "noProductsExist")
107+
@PactTestFor(pactMethod = "noProductsExist", pactVersion = PactSpecVersion.V3)
108108
void getAllProducts_whenNoProductsExist(MockServer mockServer) {
109109
RestTemplate restTemplate = new RestTemplateBuilder()
110110
.rootUri(mockServer.getUrl())
@@ -115,7 +115,7 @@ void getAllProducts_whenNoProductsExist(MockServer mockServer) {
115115
}
116116

117117
@Test
118-
@PactTestFor(pactMethod = "getOneProduct")
118+
@PactTestFor(pactMethod = "getOneProduct", pactVersion = PactSpecVersion.V3)
119119
void getProductById_whenProductWithId10Exists(MockServer mockServer) {
120120
Product expected = new Product();
121121
expected.setId("10");
@@ -131,15 +131,15 @@ void getProductById_whenProductWithId10Exists(MockServer mockServer) {
131131
}
132132

133133
@Test
134-
@PactTestFor(pactMethod = "productDoesNotExist")
134+
@PactTestFor(pactMethod = "productDoesNotExist", pactVersion = PactSpecVersion.V3)
135135
void getProductById_whenProductWithId11DoesNotExist(MockServer mockServer) {
136136
RestTemplate restTemplate = new RestTemplateBuilder()
137137
.rootUri(mockServer.getUrl())
138138
.build();
139139

140140
HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
141141
() -> new ProductService(restTemplate).getProduct("11"));
142-
assertEquals(404, e.getRawStatusCode());
142+
assertEquals(404, e.getStatusCode().value());
143143
}
144144

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void getAllProducts() {
6060

6161
@Test
6262
void getProductById() {
63-
wireMockServer.stubFor(get(urlPathEqualTo("/products/50"))
63+
wireMockServer.stubFor(get(urlPathEqualTo("/product/50"))
6464
.willReturn(aResponse()
6565
.withStatus(200)
6666
.withHeader("Content-Type", "application/json")
+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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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'
@@ -14,7 +14,7 @@ dependencies {
1414
testImplementation('org.springframework.boot:spring-boot-starter-test') {
1515
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
1616
}
17-
testImplementation("au.com.dius.pact.provider:junit5:4.1.7")
17+
testImplementation("au.com.dius.pact.provider:junit5:4.6.5")
1818
}
1919

2020
test {

provider/src/test/java/au/com/dius/pactworkshop/provider/ProductPactProviderTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.junit.jupiter.api.extension.ExtendWith;
1212
import org.springframework.boot.test.context.SpringBootTest;
1313
import org.springframework.boot.test.mock.mockito.MockBean;
14-
import org.springframework.boot.web.server.LocalServerPort;
14+
import org.springframework.boot.test.web.server.LocalServerPort;
1515
import org.springframework.test.context.junit.jupiter.SpringExtension;
1616

1717
import java.util.Arrays;

0 commit comments

Comments
 (0)