Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): step6 - Java17 / Pact 4.6.5 #30

Merged
merged 31 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4ab0c02
Step 7 - Implement provider states
Oct 9, 2020
1b1e5a5
Step 8 - Update consumer pact to require authorization
Oct 9, 2020
2f06276
Merge pull request #7 from pendsley/step7
uglyog Apr 12, 2021
e2babbe
Merge pull request #8 from pendsley/step8
uglyog Apr 12, 2021
01cce9f
chore: make build scripts executable
Sep 15, 2021
b092056
chore: make build scripts executable
Sep 15, 2021
4ebbd5d
chore: fix step 8 readme
Sep 15, 2021
78a6aab
feat: Step 1 - Add simple consumer calling provider
Oct 8, 2020
d007995
chore: make build scripts executable
Sep 15, 2021
738bcc6
chore: update to support JDK 8 + add outline
Sep 16, 2021
e45c198
chore: support JDK 8
Sep 16, 2021
85fea16
chore: update to support JDK 8
Sep 16, 2021
7f3e37d
chore: update readme
Sep 16, 2021
e22181b
chore: update readme
Sep 16, 2021
c729655
chore: update readme
Sep 16, 2021
7d822e2
chore: update readme + JDK 8 fix
Sep 16, 2021
6ab8d6c
feat: Step 1 - Add simple consumer calling provider
Oct 8, 2020
82ad1ea
chore: make build scripts executable
Sep 15, 2021
0a6e8c5
chore: update to support JDK 8 + add outline
Sep 16, 2021
d1eb4af
chore: support JDK 8
Sep 16, 2021
d979c4a
chore: update to support JDK 8
Sep 16, 2021
57af277
chore: update readme
Sep 16, 2021
8fd7547
chore: update readme
Sep 16, 2021
edd9f9f
chore: update readme
Sep 16, 2021
4dc48b6
chore: update readme + JDK 8 fix
Sep 16, 2021
879b0be
chore: update readme
Sep 16, 2021
90d5805
chore: update readme
Sep 16, 2021
cae51e3
chore: step8 update
YOU54F Feb 1, 2024
57909a8
chore: rm dep
YOU54F Feb 1, 2024
01f1984
Merge branch 'step8' into step7
YOU54F Feb 1, 2024
a95bdec
Merge branch 'step7' into step6
YOU54F Feb 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI
on:
push:
branches:
- step6
pull_request:
branches:
- step6
jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'

- name: Test consumer tests
run: ./gradlew consumer:test
- name: Test consumer pact tests
run: ./gradlew consumer:test --tests '*Pact*Test'
- name: Copy consumer pacts
run: ./gradlew consumer:copyPacts
- name: Test provider pact tests
run: ./gradlew provider:test --tests '*Pact*Test' || true
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ build/
!../gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

consumer/bin
provider/bin
provider/src/test/resources/pacts

### STS ###
Expand Down Expand Up @@ -47,3 +48,7 @@ gradle-app.setting

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

## MacOS

.DS_Store
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ step of the workshop just check out the branch for that step (i.e. `git checkout

## Requirements

* JDK 8+
* JDK 17+
* Docker for step 11

## Workshop outline:
Expand Down Expand Up @@ -317,14 +317,14 @@ This test starts a mock server on a random port that acts as our provider servic
To run only the Pact tests:

```console
> ./gradlew consumer:test --tests *PactTest
> ./gradlew consumer:test --tests '*PactTest'

```

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.

```console
❯ ./gradlew consumer:test --tests *PactTest
❯ ./gradlew consumer:test --tests '*PactTest'

BUILD SUCCESSFUL in 6s
```
Expand Down Expand Up @@ -386,13 +386,13 @@ public class ProductPactProviderTest {
To run only the verification tests:

```console
> ./gradlew provider:test --tests *Pact*Test
> ./gradlew provider:test --tests '*Pact*Test'
```

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

```console
❯ ./gradlew provider:test --tests *Pact*Test
❯ ./gradlew provider:test --tests '*Pact*Test'

...
...
Expand Down Expand Up @@ -476,7 +476,7 @@ Copy the updated contract located in `consumer/build/pacts/FrontendApplication-P
Run the command:

```console
❯ ./gradlew provider:test --tests *Pact*Test
❯ ./gradlew provider:test --tests '*Pact*Test'

...
...
Expand Down Expand Up @@ -545,14 +545,14 @@ In `consumer/src/test/java/au/com/dius/pactworkshop/consumer/ProductConsumerPact

HttpClientErrorException e = assertThrows(HttpClientErrorException.class,
() -> new ProductService(restTemplate).getProduct("11"));
assertEquals(404, e.getRawStatusCode());
assertEquals(404, e.getStatusCode().value());
}
```

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.

```console
❯ ./gradlew consumer:test --tests *PactTest
❯ ./gradlew consumer:test --tests '*PactTest'

BUILD SUCCESSFUL in 1s
```
Expand All @@ -568,7 +568,7 @@ What does our provider have to say about this new test. Again, copy the updated
and run the command:

```console
❯ ./gradlew provider:test --tests *Pact*Test
❯ ./gradlew provider:test --tests '*Pact*Test'

...
...
Expand Down
13 changes: 7 additions & 6 deletions consumer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
// Stopped from moving to 3.2.x due to wiremock issue
// https://github.com/wiremock/wiremock/issues/2395
id 'org.springframework.boot' version '3.1.8'
id 'io.spring.dependency-management' version '1.1.4'
}

group = 'au.com.dius.pactworkshop'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'
sourceCompatibility = '17'

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
Expand All @@ -14,9 +16,8 @@ dependencies {
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'com.github.tomakehurst:wiremock:2.27.2'
testImplementation 'au.com.dius.pact.consumer:java8:4.1.7'
testImplementation 'au.com.dius.pact.consumer:junit5:4.1.7'
testImplementation 'com.github.tomakehurst:wiremock:3.0.1'
testImplementation 'au.com.dius.pact.consumer:junit5:4.6.5'
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import au.com.dius.pact.core.model.PactSpecVersion; // required for v4.6.x to set pactVersion
import java.util.Collections;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArrayMinLike;
import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody;
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonArrayMinLike;
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonBody;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -87,7 +87,7 @@ RequestResponsePact productDoesNotExist(PactDslWithProvider builder) {
}

@Test
@PactTestFor(pactMethod = "getAllProducts")
@PactTestFor(pactMethod = "getAllProducts", pactVersion = PactSpecVersion.V3)
void getAllProducts_whenProductsExist(MockServer mockServer) {
Product product = new Product();
product.setId("09");
Expand All @@ -104,7 +104,7 @@ void getAllProducts_whenProductsExist(MockServer mockServer) {
}

@Test
@PactTestFor(pactMethod = "noProductsExist")
@PactTestFor(pactMethod = "noProductsExist", pactVersion = PactSpecVersion.V3)
void getAllProducts_whenNoProductsExist(MockServer mockServer) {
RestTemplate restTemplate = new RestTemplateBuilder()
.rootUri(mockServer.getUrl())
Expand All @@ -115,7 +115,7 @@ void getAllProducts_whenNoProductsExist(MockServer mockServer) {
}

@Test
@PactTestFor(pactMethod = "getOneProduct")
@PactTestFor(pactMethod = "getOneProduct", pactVersion = PactSpecVersion.V3)
void getProductById_whenProductWithId10Exists(MockServer mockServer) {
Product expected = new Product();
expected.setId("10");
Expand All @@ -131,15 +131,15 @@ void getProductById_whenProductWithId10Exists(MockServer mockServer) {
}

@Test
@PactTestFor(pactMethod = "productDoesNotExist")
@PactTestFor(pactMethod = "productDoesNotExist", pactVersion = PactSpecVersion.V3)
void getProductById_whenProductWithId11DoesNotExist(MockServer mockServer) {
RestTemplate restTemplate = new RestTemplateBuilder()
.rootUri(mockServer.getUrl())
.build();

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

private Map<String, String> headers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void getAllProducts() {

@Test
void getProductById() {
wireMockServer.stubFor(get(urlPathEqualTo("/products/50"))
wireMockServer.stubFor(get(urlPathEqualTo("/product/50"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 4 additions & 4 deletions provider/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.4'
}

group = 'au.com.dius.pactworkshop'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'
sourceCompatibility = '17'

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
Expand All @@ -14,7 +14,7 @@ dependencies {
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation("au.com.dius.pact.provider:junit5:4.1.7")
testImplementation("au.com.dius.pact.provider:junit5:4.6.5")
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@Provider("ProductService")
Expand Down