Skip to content

Commit

Permalink
Merge pull request #13 from YOU54F/step9
Browse files Browse the repository at this point in the history
Step9
  • Loading branch information
YOU54F authored Jan 30, 2024
2 parents 5cf128a + 9fcb561 commit d4ed293
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 60 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Maven CI

on:
push:
branches:
- step9
pull_request:
branches:
- step9

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'

- name: Consumer - Pact tests
run: ./mvnw verify
working-directory: consumer

- name: Consumer - Move Contracts to Provider
run: cp consumer/target/pacts/ProductCatalogue-ProductService.json provider/pacts

- name: Provider - Pact verification
run: ./mvnw verify || true
working-directory: provider
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ If running this as a team workshop format, you may want to take a look through t

## Requirements

<<<<<<< HEAD
- JDK 8 or above
- Maven 3
=======
- JDK 17+
- Maven 3+
>>>>>>> step10
- Docker for step 11

## Scenario
Expand Down Expand Up @@ -126,7 +131,8 @@ You can see the client interface test we created in `consumer/src/test/java/io/p
);

Product product = productServiceClient.getProductById(10);
assertThat(product, is(equalTo(new Product(10L, "28 Degrees", "CREDIT_CARD", "v1"))));
assertThat(product, is(equalTo(new Product(10L, "28 Degrees", "CREDIT_CARD", "v1", null))));

}
```

Expand All @@ -146,7 +152,7 @@ consumer ❯ ./mvnw verify
[INFO] Building product-catalogue 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ product-catalogue ---
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @ product-catalogue ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
Expand All @@ -155,7 +161,7 @@ consumer ❯ ./mvnw verify
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ product-catalogue ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ product-catalogue ---
[INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) @ product-catalogue ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /home/ronald/Development/Projects/Pact/pact-workshop-Maven-Springboot-JUnit5/consumer/src/test/resources
Expand All @@ -181,7 +187,7 @@ consumer ❯ ./mvnw verify
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ product-catalogue ---
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ product-catalogue ---
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ product-catalogue ---
[INFO] Replacing main artifact with repackaged archive
Expand Down Expand Up @@ -356,7 +362,7 @@ class ProductServiceClientPactTest {
}

@Test
@PactTestFor(pactMethod = "allProducts", port="9999")
@PactTestFor(pactMethod = "allProducts", pactVersion = PactSpecVersion.V3)
void testAllProducts(MockServer mockServer) throws IOException {
productServiceClient.setBaseUrl(mockServer.getUrl());
List<Product> products = productServiceClient.fetchProducts().getProducts();
Expand All @@ -365,7 +371,7 @@ class ProductServiceClientPactTest {
}

@Test
@PactTestFor(pactMethod = "singleProduct", port="9999")
@PactTestFor(pactMethod = "singleProduct", pactVersion = PactSpecVersion.V3)
void testSingleProduct(MockServer mockServer) throws IOException {
Product product = productServiceClient.getProductById(10L);
assertThat(product, is(equalTo(new Product(10L, "28 Degrees", "CREDIT_CARD", "v1", "CC_001"))));
Expand All @@ -390,7 +396,7 @@ consumer ❯ ./mvnw verify
[INFO] Building product-catalogue 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ product-catalogue ---
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @ product-catalogue ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
Expand All @@ -399,7 +405,7 @@ consumer ❯ ./mvnw verify
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ product-catalogue ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ product-catalogue ---
[INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) @ product-catalogue ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /home/ronald/Development/Projects/Pact/pact-workshop-Maven-Springboot-JUnit5/consumer/src/test/resources
Expand All @@ -422,7 +428,7 @@ consumer ❯ ./mvnw verify
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ product-catalogue ---
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ product-catalogue ---
[INFO] Building jar: /home/ronald/Development/Projects/Pact/pact-workshop-Maven-Springboot-JUnit5/consumer/target/product-catalogue-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ product-catalogue ---
Expand Down Expand Up @@ -575,7 +581,7 @@ consumer ❯ ./mvnw verify
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ product-catalogue ---
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ product-catalogue ---
[INFO] Building jar: /home/ronald/Development/Projects/Pact/pact-workshop-Maven-Springboot-JUnit5/consumer/target/product-catalogue-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ product-catalogue ---
Expand Down Expand Up @@ -663,7 +669,7 @@ In `consumer/src/test/java/io/pact/workshop/product_catalogue/clients/ProductSer
}

@Test
@PactTestFor(pactMethod = "noProducts")
@PactTestFor(pactMethod = "noProducts", pactVersion = PactSpecVersion.V3)
void testNoProducts(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
ProductServiceResponse products = productServiceClient.fetchProducts();
Expand All @@ -682,7 +688,7 @@ In `consumer/src/test/java/io/pact/workshop/product_catalogue/clients/ProductSer
}

@Test
@PactTestFor(pactMethod = "singleProductNotExists")
@PactTestFor(pactMethod = "singleProductNotExists", pactVersion = PactSpecVersion.V3)
void testSingleProductNotExists(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
try {
Expand All @@ -708,7 +714,7 @@ consumer ❯ ./mvnw verify
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ product-catalogue ---
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ product-catalogue ---
[INFO] Building jar: /home/ronald/Development/Projects/Pact/pact-workshop-Maven-Springboot-JUnit5/consumer/target/product-catalogue-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ product-catalogue ---
Expand Down Expand Up @@ -877,7 +883,7 @@ provider ❯ ./mvnw verify
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ product-service ---
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ product-service ---
[INFO] Building jar: /home/ronald/Development/Projects/Pact/pact-workshop-Maven-Springboot-JUnit5/provider/target/product-service-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
Expand Down Expand Up @@ -957,7 +963,7 @@ to all the interactions and two new interactions:
}

@Test
@PactTestFor(pactMethod = "noAuthToken")
@PactTestFor(pactMethod = "noAuthToken", pactVersion = PactSpecVersion.V3)
void testNoAuthToken(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
try {
Expand All @@ -979,7 +985,7 @@ to all the interactions and two new interactions:
}

@Test
@PactTestFor(pactMethod = "noAuthToken2")
@PactTestFor(pactMethod = "noAuthToken2", pactVersion = PactSpecVersion.V3)
void testNoAuthToken2(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
try {
Expand Down
22 changes: 11 additions & 11 deletions consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<version>3.1.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.pact.workshop</groupId>
Expand All @@ -15,9 +15,9 @@
<description>Product Catalogue service for Pact Workshop</description>

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
Expand All @@ -40,14 +40,14 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.27.2</version>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>

Expand All @@ -68,20 +68,20 @@
<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>junit5</artifactId>
<version>4.1.7</version>
<version>4.6.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
<version>4.4</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.1</version>
<version>4.12.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import au.com.dius.pact.consumer.junit5.PactTestFor;
import au.com.dius.pact.core.model.RequestResponsePact;
import au.com.dius.pact.core.model.annotations.Pact;
import au.com.dius.pact.core.model.PactSpecVersion; // required for v4.6.x to set pactVersion
import io.pact.workshop.product_catalogue.models.Product;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.client.HttpClientErrorException;

import java.io.IOException;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -53,7 +53,7 @@ public RequestResponsePact allProducts(PactDslWithProvider builder) {
}

@Test
@PactTestFor(pactMethod = "allProducts")
@PactTestFor(pactMethod = "allProducts", pactVersion = PactSpecVersion.V3)
void testAllProducts(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
List<Product> products = productServiceClient.fetchProducts().getProducts();
Expand Down Expand Up @@ -82,7 +82,7 @@ public RequestResponsePact singleProduct(PactDslWithProvider builder) {
}

@Test
@PactTestFor(pactMethod = "singleProduct")
@PactTestFor(pactMethod = "singleProduct", pactVersion = PactSpecVersion.V3)
void testSingleProduct(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
Product product = productServiceClient.getProductById(10L);
Expand All @@ -105,7 +105,7 @@ public RequestResponsePact noProducts(PactDslWithProvider builder) {
}

@Test
@PactTestFor(pactMethod = "noProducts")
@PactTestFor(pactMethod = "noProducts", pactVersion = PactSpecVersion.V3)
void testNoProducts(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
ProductServiceResponse products = productServiceClient.fetchProducts();
Expand All @@ -125,7 +125,7 @@ public RequestResponsePact singleProductNotExists(PactDslWithProvider builder) {
}

@Test
@PactTestFor(pactMethod = "singleProductNotExists")
@PactTestFor(pactMethod = "singleProductNotExists", pactVersion = PactSpecVersion.V3)
void testSingleProductNotExists(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
try {
Expand All @@ -147,7 +147,7 @@ public RequestResponsePact noAuthToken(PactDslWithProvider builder) {
}

@Test
@PactTestFor(pactMethod = "noAuthToken")
@PactTestFor(pactMethod = "noAuthToken", pactVersion = PactSpecVersion.V3)
void testNoAuthToken(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
try {
Expand All @@ -169,7 +169,7 @@ public RequestResponsePact noAuthToken2(PactDslWithProvider builder) {
}

@Test
@PactTestFor(pactMethod = "noAuthToken2")
@PactTestFor(pactMethod = "noAuthToken2", pactVersion = PactSpecVersion.V3)
void testNoAuthToken2(MockServer mockServer) {
productServiceClient.setBaseUrl(mockServer.getUrl());
try {
Expand Down
1 change: 1 addition & 0 deletions provider/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.jpa.defer-datasource-initialization=true
19 changes: 10 additions & 9 deletions provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<version>3.1.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.pact.workshop</groupId>
<artifactId>product-service</artifactId>
<version>1.0-SNAPSHOT</version>
<description>Product Service for Pact Workshop</description>

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>


<dependencies>
<dependency>
Expand Down Expand Up @@ -51,7 +52,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

Expand All @@ -65,13 +66,13 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
<version>4.4</version>
</dependency>

<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5spring</artifactId>
<version>4.1.17</version>
<version>4.6.5</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Base64;
Expand Down
Loading

0 comments on commit d4ed293

Please sign in to comment.