diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..29bf349 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 \ No newline at end of file diff --git a/.java-version b/.java-version new file mode 100644 index 0000000..03b6389 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +17.0 diff --git a/README.md b/README.md index 3076491..8404fd4 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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)))); + } ``` @@ -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 @@ -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 @@ -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 @@ -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 products = productServiceClient.fetchProducts().getProducts(); @@ -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")))); @@ -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 @@ -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 @@ -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 --- @@ -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 --- @@ -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(); @@ -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 { @@ -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 --- @@ -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 @@ -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 { @@ -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 { diff --git a/consumer/pom.xml b/consumer/pom.xml index 8582364..bfc42ca 100644 --- a/consumer/pom.xml +++ b/consumer/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.3 + 3.1.8 io.pact.workshop @@ -15,9 +15,9 @@ Product Catalogue service for Pact Workshop - 1.8 - 8 - 8 + 17 + 17 + 17 @@ -40,14 +40,14 @@ org.projectlombok lombok - 1.18.16 + 1.18.30 provided - com.github.tomakehurst - wiremock-jre8 - 2.27.2 + org.wiremock + wiremock + 3.0.1 test @@ -68,20 +68,20 @@ au.com.dius.pact.consumer junit5 - 4.1.7 + 4.6.5 test org.apache.commons commons-collections4 - 4.1 + 4.4 com.squareup.okhttp3 okhttp - 4.9.1 + 4.12.0 diff --git a/consumer/src/test/java/io/pact/workshop/product_catalogue/clients/ProductServiceClientPactTest.java b/consumer/src/test/java/io/pact/workshop/product_catalogue/clients/ProductServiceClientPactTest.java index 2e39fde..874e524 100644 --- a/consumer/src/test/java/io/pact/workshop/product_catalogue/clients/ProductServiceClientPactTest.java +++ b/consumer/src/test/java/io/pact/workshop/product_catalogue/clients/ProductServiceClientPactTest.java @@ -7,6 +7,7 @@ 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; @@ -14,7 +15,6 @@ 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; @@ -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 products = productServiceClient.fetchProducts().getProducts(); @@ -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); @@ -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(); @@ -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 { @@ -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 { @@ -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 { diff --git a/provider/application.properties b/provider/application.properties new file mode 100644 index 0000000..4d2c43a --- /dev/null +++ b/provider/application.properties @@ -0,0 +1 @@ +spring.jpa.defer-datasource-initialization=true diff --git a/provider/pom.xml b/provider/pom.xml index edc1095..e136047 100644 --- a/provider/pom.xml +++ b/provider/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.3 + 3.1.8 io.pact.workshop @@ -14,11 +14,12 @@ 1.0-SNAPSHOT Product Service for Pact Workshop - - 1.8 - 8 - 8 - + + 17 + 17 + 17 + + @@ -51,7 +52,7 @@ org.projectlombok lombok - 1.18.16 + 1.18.30 provided @@ -65,13 +66,13 @@ org.apache.commons commons-collections4 - 4.1 + 4.4 au.com.dius.pact.provider junit5spring - 4.1.17 + 4.6.5 test diff --git a/provider/src/main/java/io/pact/workshop/product_service/config/BearerAuthorizationFilter.java b/provider/src/main/java/io/pact/workshop/product_service/config/BearerAuthorizationFilter.java index 5416b18..0af6c9d 100644 --- a/provider/src/main/java/io/pact/workshop/product_service/config/BearerAuthorizationFilter.java +++ b/provider/src/main/java/io/pact/workshop/product_service/config/BearerAuthorizationFilter.java @@ -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; diff --git a/provider/src/main/java/io/pact/workshop/product_service/config/WebSecurityConfig.java b/provider/src/main/java/io/pact/workshop/product_service/config/WebSecurityConfig.java index 5415b0b..07ea4b9 100644 --- a/provider/src/main/java/io/pact/workshop/product_service/config/WebSecurityConfig.java +++ b/provider/src/main/java/io/pact/workshop/product_service/config/WebSecurityConfig.java @@ -1,19 +1,18 @@ package io.pact.workshop.product_service.config; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @Configuration -@EnableWebSecurity -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable() - .addFilterBefore(new BearerAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class) - .authorizeRequests() - .anyRequest().authenticated(); +public class WebSecurityConfig { + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http.csrf(Customizer.withDefaults()) + .addFilterBefore(new BearerAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class); + return http.build(); } } diff --git a/provider/src/main/java/io/pact/workshop/product_service/products/Product.java b/provider/src/main/java/io/pact/workshop/product_service/products/Product.java index 8fe430e..9c8b651 100644 --- a/provider/src/main/java/io/pact/workshop/product_service/products/Product.java +++ b/provider/src/main/java/io/pact/workshop/product_service/products/Product.java @@ -4,8 +4,8 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity @Data diff --git a/provider/src/test/java/io/pact/workshop/product_service/PactVerificationTest.java b/provider/src/test/java/io/pact/workshop/product_service/PactVerificationTest.java index 9775632..2c0ef12 100644 --- a/provider/src/test/java/io/pact/workshop/product_service/PactVerificationTest.java +++ b/provider/src/test/java/io/pact/workshop/product_service/PactVerificationTest.java @@ -14,7 +14,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.test.web.server.LocalServerPort; import java.util.Arrays; import java.util.Map;