{"id":15650149,"url":"https://github.com/srinivasantarget/contracttestingboilerplate","last_synced_at":"2025-04-30T17:10:15.377Z","repository":{"id":37783060,"uuid":"254882564","full_name":"SrinivasanTarget/ContractTestingBoilerplate","owner":"SrinivasanTarget","description":"Contract Testing Boilerplate for the microservices developed using Spring Boot and Kafka in a maven multi-module project.","archived":false,"fork":false,"pushed_at":"2023-03-14T23:57:00.000Z","size":260,"stargazers_count":37,"open_issues_count":15,"forks_count":26,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-19T07:46:55.781Z","etag":null,"topics":["age-consumer-microservice","cloud","consumer-driven-contracts","contract-testing","kafka","maven-multi","microservices","microservices-testing","pact","pact-broker","pact-broker-postgres","pact-jvm","pactbroker","provider-microservice","spring","spring-boot","spring-cloud-contract","swagger-validator","testing-tools","wiremock-pact-generator"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SrinivasanTarget.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-11T14:14:31.000Z","updated_at":"2023-08-17T09:03:48.000Z","dependencies_parsed_at":"2024-10-03T12:43:49.313Z","dependency_job_id":null,"html_url":"https://github.com/SrinivasanTarget/ContractTestingBoilerplate","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SrinivasanTarget%2FContractTestingBoilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SrinivasanTarget%2FContractTestingBoilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SrinivasanTarget%2FContractTestingBoilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SrinivasanTarget%2FContractTestingBoilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SrinivasanTarget","download_url":"https://codeload.github.com/SrinivasanTarget/ContractTestingBoilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251748950,"owners_count":21637418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["age-consumer-microservice","cloud","consumer-driven-contracts","contract-testing","kafka","maven-multi","microservices","microservices-testing","pact","pact-broker","pact-broker-postgres","pact-jvm","pactbroker","provider-microservice","spring","spring-boot","spring-cloud-contract","swagger-validator","testing-tools","wiremock-pact-generator"],"created_at":"2024-10-03T12:33:36.674Z","updated_at":"2025-04-30T17:10:15.112Z","avatar_url":"https://github.com/SrinivasanTarget.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Contract Testing Boilerplate\n\nContract Testing Boilerplate has two microservices developed using Spring Boot in a maven multi-module project.\n\n## What is Contract Testing?\nAn integration contract test is a test at the boundary of an external service verifying that it meets the contract expected by a consuming service.\n\n  - Date Provider MicroService - /provider/validDate - Validates whether given date is a valid date or not\n  - Age Consumer MicroService - /age-calculate - Returns age of a person based on given date\n  \n  \n![Microservices](images/microservices.png)\n\nStart Date Provider MicroService by default runs in port 8080: \n\n```shell script\nmvn spring-boot:run -pl date-provider\n```\n\nStart Age Consumer MicroService by default runs in port 8081: \n\n```shell script\nmvn spring-boot:run -pl age-consumer\n```\n\n## Pact Tests\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand!\u003c/summary\u003e\n\nPact is a contract testing tool. Contract testing is a way to ensure that services (such as an API provider and a client) can communicate with each other. Without contract testing, the only way to know that services can communicate is by using expensive and brittle integration tests.\n\n### Run Consumer contract Tests\n```shell script\nmvn clean test -pl age-consumer\n```\n\nGenerated Pact file:\n```json\n{\n  \"provider\": {\n    \"name\": \"dateProvider\"\n  },\n  \"consumer\": {\n    \"name\": \"ageConsumer\"\n  },\n  \"interactions\": [\n    {\n      \"description\": \"valid date from provider\",\n      \"request\": {\n        \"method\": \"GET\",\n        \"path\": \"/provider/validDate\",\n        \"query\": {\n          \"date\": [\n            \"2001-02-03\"\n          ]\n        },\n        \"matchingRules\": {\n          \"query\": {\n            \"date\": {\n              \"matchers\": [\n                {\n                  \"match\": \"date\",\n                  \"date\": \"2001-02-03\"\n                }\n              ],\n              \"combine\": \"AND\"\n            }\n          }\n        },\n        \"generators\": {\n          \"body\": {\n            \"date\": {\n              \"type\": \"Date\",\n              \"format\": \"2001-02-03\"\n            }\n          }\n        }\n      },\n      \"response\": {\n        \"status\": 200,\n        \"headers\": {\n          \"content-type\": \"application/json\",\n          \"Content-Type\": \"application/json; charset=UTF-8\"\n        },\n        \"body\": {\n          \"month\": 8,\n          \"year\": 2000,\n          \"isValidDate\": true,\n          \"day\": 3\n        },\n        \"matchingRules\": {\n          \"body\": {\n            \"$.year\": {\n              \"matchers\": [\n                {\n                  \"match\": \"number\"\n                }\n              ],\n              \"combine\": \"AND\"\n            },\n            \"$.month\": {\n              \"matchers\": [\n                {\n                  \"match\": \"number\"\n                }\n              ],\n              \"combine\": \"AND\"\n            },\n            \"$.day\": {\n              \"matchers\": [\n                {\n                  \"match\": \"number\"\n                }\n              ],\n              \"combine\": \"AND\"\n            },\n            \"$.isValidDate\": {\n              \"matchers\": [\n                {\n                  \"match\": \"type\"\n                }\n              ],\n              \"combine\": \"AND\"\n            }\n          },\n          \"header\": {\n            \"Content-Type\": {\n              \"matchers\": [\n                {\n                  \"match\": \"regex\",\n                  \"regex\": \"application/json(;\\\\s?charset=[\\\\w\\\\-]+)?\"\n                }\n              ],\n              \"combine\": \"AND\"\n            }\n          }\n        }\n      },\n      \"providerStates\": [\n        {\n          \"name\": \"\"\n        }\n      ]\n    }\n  ],\n  \"metadata\": {\n    \"pactSpecification\": {\n      \"version\": \"3.0.0\"\n    },\n    \"pact-jvm\": {\n      \"version\": \"4.0.9\"\n    }\n  }\n}\n```\n\n### Start Pact Broker at default port `:8282`\n```dockerfile\ndocker-compose up -d\n```\n\n### Publish Pact Files in Pact Broker\n```shell script\n$ cd age-consumer\n$ mvn pact:publish\n```\n\n### Verify Pacts in Pact Broker at Provider side\n```shell script\nmvn clean -Dtest=PactAgeProviderTest test -pl date-provider\n```\n\n![Pact Broker](images/PactBroker.png)\n\n\u003c/details\u003e\n\n## Spring Cloud Contract Tests\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand!\u003c/summary\u003e\n\nSpring Cloud Contract is an umbrella project holds solutions to help users implement contract tests. It has two main modules:\n\n* Spring Cloud Contract Verifier, which is used mainly by the producer side.\n* Spring Cloud Contract Stub Runner, which is used by the consumer side.\n\n\u003c/details\u003e\n\n## Blogs\n\n* [Consumer Driven Contract Testing [Webinar Recording]](https://blog.testproject.io/2020/06/15/consumer-driven-contract-testing-the-ultimate-guide-to-testing-microservices/)\n* [Introduction to consumer-driven contracts](https://blog.testproject.io/2020/04/27/introduction-to-consumer-contract-testing/)\n* [Consumer-Driven Contract Testing using Pact Java](https://blog.testproject.io/2020/05/27/consumer-driven-contract-testing-using-pact-java/)\n* [Consumer-Driven Contract Testing using Spring Cloud Contracts](https://blog.testproject.io/2020/05/20/consumer-driven-contract-testing-using-spring-cloud-contract/)\n* [Event-Driven Architecture: How to Perform Contract Testing in Kafka/pubSub](https://blog.testproject.io/2020/06/03/event-driven-architecture-how-to-perform-contract-testing-in-kafka-pubsub/)\n* [Integrating Contract Testing in Build Pipelines](https://blog.testproject.io/2020/06/09/integrating-consumer-contract-testing-in-build-pipelines/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrinivasantarget%2Fcontracttestingboilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrinivasantarget%2Fcontracttestingboilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrinivasantarget%2Fcontracttestingboilerplate/lists"}