diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4f53792 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: CI +on: + push: + pull_request: + branches: + - master +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 8 + uses: actions/setup-java@v4 + with: + java-version: 8 + distribution: 'zulu' + + - name: Test consumer tests + run: ./gradlew consumer:test + - name: Test provider pact tests + run: ./gradlew provider:test \ No newline at end of file diff --git a/.java-version b/.java-version new file mode 100644 index 0000000..6259340 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +1.8 diff --git a/consumer/build.gradle b/consumer/build.gradle index c073585..2f7bd82 100644 --- a/consumer/build.gradle +++ b/consumer/build.gradle @@ -9,7 +9,7 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.junit.jupiter:junit-jupiter:5.5.1' - testImplementation 'au.com.dius:pact-jvm-consumer-junit5:4.0.0-beta.5' + 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' } diff --git a/consumer/src/test/kotlin/io/pactflow/providerstatesexample/consumer/TransactionPactTest.kt b/consumer/src/test/kotlin/io/pactflow/providerstatesexample/consumer/TransactionPactTest.kt index 1b42b8e..847e142 100644 --- a/consumer/src/test/kotlin/io/pactflow/providerstatesexample/consumer/TransactionPactTest.kt +++ b/consumer/src/test/kotlin/io/pactflow/providerstatesexample/consumer/TransactionPactTest.kt @@ -39,18 +39,18 @@ class TransactionPactTest { .integerType("version", 0) .stringType("name", "Test") .stringValue("accountRef", "Test001") - .timestamp("createdDate", "yyyy-MM-dd'T'HH:mm:ss.SZ") - .timestamp("lastModifiedDate", "yyyy-MM-dd'T'HH:mm:ss.SZ") + .datetime("createdDate", "yyyy-MM-dd'T'HH:mm:ss.SZ") + .datetime("lastModifiedDate", "yyyy-MM-dd'T'HH:mm:ss.SZ") .`object`("accountNumber") .valueFromProviderState("id", "\${accountNumber}", 100) - .closeObject() - .`object`("_links") + .closeObject()!! + .`object`("_links") .`object`("self") - .matchUrl("href", "http://localhost:8080", "/accounts", RegexMatcher("\\d+", "100")) - .closeObject() + .matchUrl("href", "http://localhost:8080" as String?, "/accounts" as Any, RegexMatcher("\\d+", "100") as Any) + .closeObject()!! .`object`("account") - .matchUrl("href", "http://localhost:8080", "/accounts", RegexMatcher("\\d+", "200")) - .closeObject() + .matchUrl("href", "http://localhost:8080" as String?, "/accounts" as Any, RegexMatcher("\\d+", "200") as Any) + .closeObject()!! .closeObject() ).toPact() diff --git a/provider/build.gradle b/provider/build.gradle index 47dcb76..2df03f0 100644 --- a/provider/build.gradle +++ b/provider/build.gradle @@ -12,7 +12,7 @@ dependencies { testCompile('org.springframework.boot:spring-boot-starter-test') testImplementation 'org.junit.jupiter:junit-jupiter:5.5.1' - testImplementation 'au.com.dius:pact-jvm-provider-junit5:4.0.0-beta.5' + testImplementation 'au.com.dius.pact.provider:junit5:4.1.43' } bootJar { diff --git a/provider/src/test/kotlin/io/pactflow/providerstatesexample/provider/PactVerificationTest.kt b/provider/src/test/kotlin/io/pactflow/providerstatesexample/provider/PactVerificationTest.kt index 4afc39c..f26a188 100644 --- a/provider/src/test/kotlin/io/pactflow/providerstatesexample/provider/PactVerificationTest.kt +++ b/provider/src/test/kotlin/io/pactflow/providerstatesexample/provider/PactVerificationTest.kt @@ -1,8 +1,8 @@ package io.pactflow.providerstatesexample.provider -import au.com.dius.pact.provider.junit.Provider -import au.com.dius.pact.provider.junit.State -import au.com.dius.pact.provider.junit.loader.PactFolder +import au.com.dius.pact.provider.junitsupport.Provider +import au.com.dius.pact.provider.junitsupport.State +import au.com.dius.pact.provider.junitsupport.loader.PactFolder import au.com.dius.pact.provider.junit5.PactVerificationContext import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider import org.junit.jupiter.api.TestTemplate @@ -12,7 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest @Provider("AccountService") @PactFolder("pacts") -@SpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) class PactVerificationTest { @Autowired diff --git a/provider/src/test/resources/pacts/TransactionService-AccountService.json b/provider/src/test/resources/pacts/TransactionService-AccountService.json index dea84f1..c704a3d 100644 --- a/provider/src/test/resources/pacts/TransactionService-AccountService.json +++ b/provider/src/test/resources/pacts/TransactionService-AccountService.json @@ -1,159 +1,161 @@ { - "provider": { - "name": "AccountService" - }, "consumer": { "name": "TransactionService" }, "interactions": [ { "description": "a request to get the account details", + "providerStates": [ + { + "name": "Account Test001 exists", + "params": { + "accountRef": "Test001" + } + } + ], "request": { + "generators": { + "query": { + "accountNumber": { + "dataType": "STRING", + "expression": "${accountNumber}", + "type": "ProviderState" + } + } + }, "method": "GET", "path": "/accounts/search/findOneByAccountNumberId", "query": { "accountNumber": [ "100" ] - }, - "generators": { - "query": { - "accountNumber": { - "type": "ProviderState", - "expression": "${accountNumber}" - } - } } }, "response": { - "status": 200, - "headers": { - "Content-Type": "application/hal+json" - }, "body": { - "createdDate": "2000-02-01T00:00:00.0+1100", - "lastModifiedDate": "2000-02-01T00:00:00.0+1100", "_links": { - "self": { - "href": "http://localhost:8080//accounts/100" - }, "account": { "href": "http://localhost:8080//accounts/200" + }, + "self": { + "href": "http://localhost:8080//accounts/100" } }, - "name": "Test", - "id": 1, - "accountRef": "Test001", "accountNumber": { "id": 100 }, + "accountRef": "Test001", + "createdDate": "2000-01-31T13:00:00.0+0000", + "id": 1, + "lastModifiedDate": "2000-01-31T13:00:00.0+0000", + "name": "Test", "version": 0 }, + "generators": { + "body": { + "$.accountNumber.id": { + "dataType": "INTEGER", + "expression": "${accountNumber}", + "type": "ProviderState" + }, + "$.createdDate": { + "format": "yyyy-MM-dd'T'HH:mm:ss.SZ", + "type": "DateTime" + }, + "$.lastModifiedDate": { + "format": "yyyy-MM-dd'T'HH:mm:ss.SZ", + "type": "DateTime" + } + } + }, + "headers": { + "Content-Type": "application/hal+json" + }, "matchingRules": { "body": { - "$.id": { + "$._links.account.href": { + "combine": "AND", "matchers": [ { - "match": "integer" + "match": "regex", + "regex": ".*\\Q/accounts\\E\\/\\d+$" } - ], - "combine": "AND" + ] }, - "$.version": { + "$._links.self.href": { + "combine": "AND", "matchers": [ { - "match": "integer" + "match": "regex", + "regex": ".*\\Q/accounts\\E\\/\\d+$" } - ], - "combine": "AND" + ] }, - "$.name": { + "$.accountNumber.id": { + "combine": "AND", "matchers": [ { "match": "type" } - ], - "combine": "AND" + ] }, "$.createdDate": { + "combine": "AND", "matchers": [ { - "match": "timestamp", - "timestamp": "yyyy-MM-dd\u0027T\u0027HH:mm:ss.SZ" + "format": "yyyy-MM-dd'T'HH:mm:ss.SZ", + "match": "timestamp" } - ], - "combine": "AND" + ] }, - "$.lastModifiedDate": { + "$.id": { + "combine": "AND", "matchers": [ { - "match": "timestamp", - "timestamp": "yyyy-MM-dd\u0027T\u0027HH:mm:ss.SZ" + "match": "integer" } - ], - "combine": "AND" + ] }, - "$.accountNumber.id": { + "$.lastModifiedDate": { + "combine": "AND", "matchers": [ { - "match": "type" + "format": "yyyy-MM-dd'T'HH:mm:ss.SZ", + "match": "timestamp" } - ], - "combine": "AND" + ] }, - "$._links.self.href": { + "$.name": { + "combine": "AND", "matchers": [ { - "match": "regex", - "regex": ".*\\Q/accounts\\E\\/\\d+$" + "match": "type" } - ], - "combine": "AND" + ] }, - "$._links.account.href": { + "$.version": { + "combine": "AND", "matchers": [ { - "match": "regex", - "regex": ".*\\Q/accounts\\E\\/\\d+$" + "match": "integer" } - ], - "combine": "AND" + ] } } }, - "generators": { - "body": { - "$.createdDate": { - "type": "DateTime", - "format": "yyyy-MM-dd\u0027T\u0027HH:mm:ss.SZ" - }, - "$.lastModifiedDate": { - "type": "DateTime", - "format": "yyyy-MM-dd\u0027T\u0027HH:mm:ss.SZ" - }, - "$.accountNumber.id": { - "type": "ProviderState", - "expression": "${accountNumber}" - } - } - } - }, - "providerStates": [ - { - "name": "Account Test001 exists", - "params": { - "accountRef": "Test001" - } - } - ] + "status": 200 + } } ], "metadata": { + "pact-jvm": { + "version": "4.1.43" + }, "pactSpecification": { "version": "3.0.0" - }, - "pact-jvm": { - "version": "4.0.0-beta.5" } + }, + "provider": { + "name": "AccountService" } -} \ No newline at end of file +}