Skip to content

Commit

Permalink
Revert "Revert "Update java, kotlin, spring and pact (#8)" (#10)" (#12)
Browse files Browse the repository at this point in the history
This reverts commit e8eb194.
  • Loading branch information
rogervinas committed Nov 11, 2023
1 parent 3d27dc3 commit c64d739
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: '21'
distribution: 'temurin'

- name: Gradle Cache
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![CI](https://github.com/rogervinas/contract-testing-with-pact/actions/workflows/ci.yml/badge.svg)](https://github.com/rogervinas/contract-testing-with-pact/actions/workflows/ci.yml)
![Java](https://img.shields.io/badge/Java-11-blue?labelColor=black)
![Kotlin](https://img.shields.io/badge/Kotlin-1.7.20-blue?labelColor=black)
![SpringBoot](https://img.shields.io/badge/SpringBoot-2.7.4-blue?labelColor=black)
![Pact](https://img.shields.io/badge/Pact-4.3.15-blue?labelColor=black)
![Java](https://img.shields.io/badge/Java-21-blue?labelColor=black)
![Kotlin](https://img.shields.io/badge/Kotlin-1.9.20-blue?labelColor=black)
![SpringBoot](https://img.shields.io/badge/SpringBoot-3.1.5-blue?labelColor=black)
![Pact](https://img.shields.io/badge/Pact-4.6.3-blue?labelColor=black)

# Contract Testing with Pact

Expand Down Expand Up @@ -285,15 +285,15 @@ We start with this:
@WebFluxTest(controllers = [SampleApiController::class])
@Provider("Sample API Server")
@PactFolder("../sample-api-client/build/pacts")
@ExtendWith(PactVerificationSpringProvider::class)
@ExtendWith(PactVerificationSpring6Provider::class)
class SampleApiControllerContractTest {

@Autowired
private lateinit var webTestClient: WebTestClient

@BeforeEach
fun beforeEach(context: PactVerificationContext) {
context.target = WebTestClientTarget(webTestClient)
context.target = WebTestClientSpring6Target(webTestClient)
}

@TestTemplate
Expand All @@ -318,7 +318,7 @@ Note that:
* Just temporarily we use `@PactFolder` annotation to **read the "contract" from the local directory** where `sample-api-client` has generated it. No need for a [PactBroker](https://docs.pact.io/pact_broker) yet.
* We use `@Provider` annotation to specify that we are executing tests for the "Sample API Server" provider.
* We have to create as many methods annotated with `@State` as states the "contract" expects. We leave them empty for now but we will have to properly set the state there.
* Finally `PactVerificationSpringProvider` junit5 extension and `pactVerificationTestTemplate` method annotated with junit5's `@TestTemplate` will create tests dynamically following the "contract". Again ✨magic✨
* Finally `PactVerificationSpring6Provider` junit5 extension and `pactVerificationTestTemplate` method annotated with junit5's `@TestTemplate` will create tests dynamically following the "contract". Again ✨magic✨

If we create an empty `SampleApiController` to make this test compile:
```kotlin
Expand Down Expand Up @@ -371,7 +371,7 @@ class SampleApiController(private val repository: SampleRepository) {
@WebFluxTest(controllers = [SampleApiController::class])
@Provider("Sample API Server")
@PactFolder("../sample-api-client/build/pacts")
@ExtendWith(PactVerificationSpringProvider::class)
@ExtendWith(PactVerificationSpring6Provider::class)
class SampleApiControllerContractTest {

@Autowired
Expand All @@ -382,7 +382,7 @@ class SampleApiControllerContractTest {

@BeforeEach
fun beforeEach(context: PactVerificationContext) {
context.target = WebTestClientTarget(webTestClient)
context.target = WebTestClientSpring6Target(webTestClient)
}

@TestTemplate
Expand Down Expand Up @@ -419,7 +419,7 @@ Finally, in a real scenario we will use `@PactBroker` instead of `@PactFolder` i
@WebFluxTest(controllers = [SampleApiController::class])
@Provider("Sample API Server")
@PactBroker
@ExtendWith(PactVerificationSpringProvider::class)
@ExtendWith(PactVerificationSpring6Provider::class)
class SampleApiControllerContractTest {
// ...
}
Expand All @@ -436,7 +436,7 @@ We can also test the "contract" against the whole application using a [SpringBoo
@SpringBootTest(webEnvironment = DEFINED_PORT)
@Provider("Sample API Server")
@PactBroker
@ExtendWith(PactVerificationSpringProvider::class)
@ExtendWith(PactVerificationSpring6Provider::class)
class SampleApiServerContractTest {

@TestTemplate
Expand All @@ -461,7 +461,7 @@ And a little extra code if we want to start the application using a random port:
@SpringBootTest(webEnvironment = RANDOM_PORT)
@Provider("Sample API Server")
@PactBroker
@ExtendWith(PactVerificationSpringProvider::class)
@ExtendWith(PactVerificationSpring6Provider::class)
class SampleApiServerContractTest {

@LocalServerPort
Expand Down Expand Up @@ -618,7 +618,7 @@ Some, I hope useful, implementation details of this PoC:

* We use [au.com.dius.pact](https://plugins.gradle.org/plugin/au.com.dius.pact) gradle plugin both for the consumer and the provider.
* We use [au.com.dius.pact.consumer:junit5](https://mvnrepository.com/artifact/au.com.dius.pact.consumer/junit5) dependency for the consumer.
* We use [au.com.dius.pact.provider:junit5spring](https://mvnrepository.com/artifact/au.com.dius.pact.provider/junit5spring) dependency for the provider.
* We use [au.com.dius.pact.provider:spring6](https://mvnrepository.com/artifact/au.com.dius.pact.provider/spring6) dependency for the provider.
* All [these system properties are available](https://docs.pact.io/implementation_guides/jvm/docs/system-properties).
* Properties used in this PoC for the consumer:
* `project.extra["pacticipant"] = "Sample API Client"` and `project.extra["pacticipantVersion"] = version` so we do not need to pass them everytime in the `canIDeploy` task.
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:

pactbroker:
image: pactfoundation/pact-broker:2.104.0.0
image: pactfoundation/pact-broker:2.107.0.1
environment:
PACT_BROKER_DATABASE_ADAPTER: sqlite
PACT_BROKER_DATABASE_NAME: pactbroker
Expand Down
8 changes: 4 additions & 4 deletions sample-api-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED

plugins {
id("org.jetbrains.kotlin.jvm") version "1.7.20"
id("au.com.dius.pact") version "4.3.15"
id("org.jetbrains.kotlin.jvm") version "1.9.20"
id("au.com.dius.pact") version "4.6.3"
application
}

Expand All @@ -32,12 +32,12 @@ dependencies {

testImplementation("org.junit.jupiter:junit-jupiter:5.9.0")
testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
testImplementation("au.com.dius.pact.consumer:junit5:4.3.15")
testImplementation("au.com.dius.pact.consumer:junit5:4.6.3")
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SampleApiClientContractTest {

private val THING123_ID = SampleThingId(123)
private val THING123_ID_JSON_PACT = PactDslJsonBody()
.integerType("id", 123)
.integerType("id", 123L)
}

@Pact(provider = "Sample API Server", consumer = "Sample API Client")
Expand Down
16 changes: 8 additions & 8 deletions sample-api-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED

plugins {
id("org.springframework.boot") version "2.7.4"
id("io.spring.dependency-management") version "1.0.14.RELEASE"
kotlin("jvm") version "1.7.20"
kotlin("plugin.spring") version "1.7.20"
id("au.com.dius.pact") version "4.3.15"
id("org.springframework.boot") version "3.1.5"
id("io.spring.dependency-management") version "1.1.3"
kotlin("jvm") version "1.9.20"
kotlin("plugin.spring") version "1.9.20"
id("au.com.dius.pact") version "4.6.3"
}

version = "1.0"
Expand All @@ -32,14 +32,14 @@ dependencies {
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")

testImplementation("au.com.dius.pact.provider:junit5spring:4.3.15")
testImplementation("au.com.dius.pact.provider:spring6:4.6.3")

testImplementation("com.ninja-squad:springmockk:3.1.1")
testImplementation("com.ninja-squad:springmockk:4.0.2")
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import au.com.dius.pact.provider.junit5.PactVerificationContext
import au.com.dius.pact.provider.junitsupport.Provider
import au.com.dius.pact.provider.junitsupport.State
import au.com.dius.pact.provider.junitsupport.loader.PactBroker
import au.com.dius.pact.provider.spring.junit5.PactVerificationSpringProvider
import au.com.dius.pact.provider.spring.junit5.WebTestClientTarget
import au.com.dius.pact.provider.spring.spring6.PactVerificationSpring6Provider
import au.com.dius.pact.provider.spring.spring6.WebTestClientSpring6Target
import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import org.junit.jupiter.api.BeforeEach
Expand All @@ -19,7 +19,7 @@ import java.time.LocalDate
@WebFluxTest(controllers = [SampleApiController::class])
@Provider("Sample API Server")
@PactBroker
@ExtendWith(PactVerificationSpringProvider::class)
@ExtendWith(PactVerificationSpring6Provider::class)
class SampleApiControllerContractTest {

@Autowired
Expand All @@ -30,7 +30,7 @@ class SampleApiControllerContractTest {

@BeforeEach
fun beforeEach(context: PactVerificationContext) {
context.target = WebTestClientTarget(webTestClient)
context.target = WebTestClientSpring6Target(webTestClient)
}

@TestTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import au.com.dius.pact.provider.junit5.PactVerificationContext
import au.com.dius.pact.provider.junitsupport.Provider
import au.com.dius.pact.provider.junitsupport.State
import au.com.dius.pact.provider.junitsupport.loader.PactBroker
import au.com.dius.pact.provider.spring.junit5.PactVerificationSpringProvider
import au.com.dius.pact.provider.spring.spring6.PactVerificationSpring6Provider
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestTemplate
import org.junit.jupiter.api.extension.ExtendWith
Expand All @@ -19,7 +19,7 @@ import java.time.LocalDate
@SpringBootTest(webEnvironment = RANDOM_PORT)
@Provider("Sample API Server")
@PactBroker
@ExtendWith(PactVerificationSpringProvider::class)
@ExtendWith(PactVerificationSpring6Provider::class)
class SampleApiServerContractTest {

@LocalServerPort
Expand Down

0 comments on commit c64d739

Please sign in to comment.