Skip to content

Commit

Permalink
chore(deps): pact-jvm to 4.6 / java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Oct 9, 2024
1 parent 11e2266 commit bbbb304
Show file tree
Hide file tree
Showing 16 changed files with 321 additions and 273 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Test consumer tests
Expand Down
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8
17.0
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:3.3.4")
}
}

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.41'
id 'org.jetbrains.kotlin.jvm' version '2.0.20'
id 'org.jetbrains.kotlin.plugin.spring' version '2.0.20'
}

repositories {
Expand All @@ -32,13 +32,13 @@ subprojects {

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}
}
16 changes: 8 additions & 8 deletions consumer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.9'
implementation('io.github.microutils:kotlin-logging:1.4.4') {
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.17.2'
implementation('io.github.oshai:kotlin-logging:7.0.0') {
exclude group: 'org.jetbrains.kotlin'
}

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.1'
testImplementation 'au.com.dius.pact.consumer:junit5:4.1.43'
testImplementation 'ch.qos.logback:logback-core:1.2.3'
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.2'
testImplementation 'au.com.dius.pact.consumer:junit5:4.6.14'
testImplementation 'ch.qos.logback:logback-core:1.5.8'
testImplementation 'ch.qos.logback:logback-classic:1.5.8'
}

bootJar {
baseName = 'consumer'
archivesBaseName = 'consumer'
version = '0.0.0'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.pactflow.providerstatesexample.consumer

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import mu.KLogging
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.context.annotation.Bean
import org.springframework.core.ParameterizedTypeReference
import org.springframework.hateoas.Resource
import org.springframework.hateoas.EntityModel
import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.RequestMapping
Expand Down Expand Up @@ -40,23 +40,24 @@ class TransactionController {
@Value("\${provider.url}")
lateinit var providerUrl: String

private val logger = KotlinLogging.logger {}

@RequestMapping("/transactions", method = [RequestMethod.POST])
fun new(@RequestParam accountNumber: Int): Map<String, Any> {
logger.info { "Creating a new transaction for account $accountNumber" }
val url = "$providerUrl/accounts/search/findOneByAccountNumberId?accountNumber=$accountNumber"
logger.info { "Getting account details -> $url" }
val responseEntity = restTemplate.exchange(url, HttpMethod.GET, null,
object : ParameterizedTypeReference<Resource<Account>>() {})
return if (responseEntity.statusCode == HttpStatus.OK) {
logger.info { "Got response ${responseEntity.body}" }
logger.info { " Id ${responseEntity.body.id}" }
val account = responseEntity.body.content
object : ParameterizedTypeReference<EntityModel<Account>>(){})
return if (responseEntity.statusCode == HttpStatus.OK) {
logger.info { "Got response $responseEntity.body" }
logger.info { " Id $responseEntity.body.content.id" }
val account: Account = responseEntity.body.content
logger.info { " Content $account" }
mapOf("account" to account)
} else emptyMap()
}

companion object: KLogging()
}

@SpringBootApplication
Expand All @@ -65,7 +66,7 @@ class App {
fun restTemplate(builder: RestTemplateBuilder) = builder.build()

@Bean
fun objectMapper() = ObjectMapper().registerModule(KotlinModule())
fun objectMapper() = ObjectMapper().registerKotlinModule()
}

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 au.com.dius.pact.core.model.PactSpecVersion; // required for v4.6.x to set pactVersion

@ExtendWith(PactConsumerTestExt::class)
@PactTestFor(providerName = "AccountService")
Expand All @@ -39,23 +40,23 @@ class TransactionPactTest {
.integerType("version", 0)
.stringType("name", "Test")
.stringValue("accountRef", "Test001")
.datetime("createdDate", "yyyy-MM-dd'T'HH:mm:ss.SZ")
.datetime("lastModifiedDate", "yyyy-MM-dd'T'HH:mm:ss.SZ")
.datetime("createdDate", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
.datetime("lastModifiedDate", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
.`object`("accountNumber")
.valueFromProviderState("id", "\${accountNumber}", 100)
.closeObject()!!
.`object`("_links")
.`object`("self")
.matchUrl("href", "http://localhost:8080" as String?, "/accounts" as Any, RegexMatcher("\\d+", "100") as Any)
.matchUrl("href", "http://localhost:8080" as String?, "accounts" as Any, RegexMatcher("\\d+", "100") as Any)
.closeObject()!!
.`object`("account")
.matchUrl("href", "http://localhost:8080" as String?, "/accounts" as Any, RegexMatcher("\\d+", "200") as Any)
.matchUrl("href", "http://localhost:8080" as String?, "accounts" as Any, RegexMatcher("\\d+", "200") as Any)
.closeObject()!!
.closeObject()
.closeObject() as PactDslJsonBody
).toPact()

@Test
@PactTestFor(pactMethod = "accounts")
@PactTestFor(pactMethod = "accounts", pactVersion = PactSpecVersion.V3)
fun testNewTransaction(mockServer: MockServer) {
controller.providerUrl = mockServer.getUrl()
val result = controller.new(100)
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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-5.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit bbbb304

Please sign in to comment.