diff --git a/.travis.yml b/.travis.yml index fe47e618..047b8615 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,6 @@ jdk: - oraclejdk8 sudo: required script: - - ./gradlew test \ No newline at end of file + - ./gradlew test +after_success: + - ./gradlew cobertura coveralls \ No newline at end of file diff --git a/README.md b/README.md index 819dc52b..cbf0b774 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,26 @@ sh u-integration-test.sh ``` ## Running Contract Tests +Start the domain services with internal mocks so that only the endpoints will be tested. ```bash -sh u-contract-test.sh +docker-compose -f docker-compose-internal-mocked.yml start +``` +Start the PactBroker service and check `http://localhost:8089` that it is live. +```bash +docker-compose -f ./pact-broker/docker-compose.yml start +``` +Generate the PACTs and execute them. +```bash +sh ./scripts/generate-publish-pact-tests.sh +sh ./scripts/run-pact-tests.sh +``` +Stop the PactBroker. +```bash +docker-compose -f ./pact-broker/docker-compose.yml down +``` +Stop the services with internal mocks. +```bash +docker-compose -f docker-compose-internal-mocked.yml down ``` ## Running Service Readiness Tests diff --git a/build.gradle b/build.gradle index 5bc1c958..c41d32a8 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,10 @@ subprojects { project -> apply plugin: 'checkstyle' apply plugin: 'jacoco' apply plugin: 'groovy' + apply plugin: 'net.saliman.cobertura' + apply plugin: 'com.github.kt3k.coveralls' + + cobertura.coverageFormats = ['html', 'xml'] if(project.name != 'api') { apply plugin: "application" @@ -129,6 +133,19 @@ subprojects { project -> } } if(project.name != 'api') { + + task clearPactBroker() { + doLast() { + def services = ['Customers', 'AccountCmd', 'AccountQuery', 'Transactions'] + for (service in services) { + println "http://localhost:8089/pacticipants/" + service + def p = ['curl', '-X', 'DELETE', "http://localhost:8089/pacticipants/" + service]. + execute() + println p.text + } + } + } + pact { serviceProviders { // You can define as many as you need, but each must have a unique name @@ -178,7 +195,12 @@ subprojects { project -> } publish { - pactDirectory = '../pact-tests' // defaults to $buildDir/pacts + def folder = new File('./pact-tests') + if (folder.exists()) { + pactDirectory = './pact-tests' + } else { + pactDirectory = '../pact-tests' + } pactBrokerUrl = 'http://localhost:8089' } } @@ -191,12 +213,3 @@ subprojects { project -> test.finalizedBy(jacocoTestCoverageVerification) } - -task clearPactBroker() { - def services = ['Customers', 'AccountCmd', 'AccountQuery', 'Transactions'] - for(service in services) { - println "http://localhost:8089/pacticipants/" + service - def p = ['curl', '-X', 'DELETE', "http://localhost:8089/pacticipants/" + service].execute() - println p.text - } -} diff --git a/misc-docker-images/docker-compose.yml b/pact-broker/docker-compose.yml similarity index 100% rename from misc-docker-images/docker-compose.yml rename to pact-broker/docker-compose.yml diff --git a/scripts/generate-publish-pact-tests.sh b/scripts/generate-publish-pact-tests.sh new file mode 100644 index 00000000..6b30b116 --- /dev/null +++ b/scripts/generate-publish-pact-tests.sh @@ -0,0 +1,15 @@ +'#!/bin/sh' + +# Generate the Pact JSON files in the root of the project in 'pact-tests'. +# To change the target directory see `systemProperties['pact.rootDir'] = "../pact-tests"` +# An example change could be `systemProperties['pact.rootDir'] = "${buildDir}/pact-tests"` to +# store them in each projects directory, but then the publish location needs to be created for each +# provider. +./gradlew :account-cmd:test --tests "*.contract.consumer.*" +./gradlew :account-query:test --tests "*.contract.consumer.*" +./gradlew :customers:test --tests "*.contract.consumer.*" +./gradlew :transactions:test --tests "*.contract.consumer.*" + +# Since the PACT plugin is global to all projects this will publish all provider pacts, not just +# transactions. +./gradlew :transactions:pactPublish \ No newline at end of file diff --git a/scripts/pact-tests.sh b/scripts/pact-tests.sh deleted file mode 100644 index 065eec72..00000000 --- a/scripts/pact-tests.sh +++ /dev/null @@ -1,4 +0,0 @@ -'#!/bin/sh' -./gradlew :transactions:test --tests "*.contract.consumer.*" -./gradlew :customers:pactVerify -./gradlew :customers:pactPublish \ No newline at end of file diff --git a/scripts/run-pact-tests.sh b/scripts/run-pact-tests.sh new file mode 100644 index 00000000..573652eb --- /dev/null +++ b/scripts/run-pact-tests.sh @@ -0,0 +1,5 @@ +'#!/bin/sh' +./gradlew :customers:pactVerify_AccountCmd +./gradlew :customers:pactVerify_AccountQuery +./gradlew :customers:pactVerify_Customers +./gradlew :customers:pactVerify_Transactions \ No newline at end of file