PageSourceSearch

https://docs-pactflow-preview.netlify.app/assets/js/90dc510d.4c15afda.js

js docs-pactflow-preview.netlify.app collected 2026-10-03 10:40:09 UTC 18,676 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkpartners=self.webpackChunkpartners||[]).push([[4249],{15680:(e,t,a)=>{a.d(t,{xA:()=>c,yg:()=>g});var o=a(96540);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function r(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,o)}return a}function n(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?r(Object(a),!0).forEach((function(t){i(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function l(e,t){if(null==e)return{};var a,o,i=function(e,t){if(null==e)return{};var a,o,i={},r=Object.keys(e);for(o=0;o<r.length;o++)a=r[o],t.indexOf(a)>=0||(i[a]=e[a]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o<r.length;o++)a=r[o],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(i[a]=e[a])}return i}var s=o.createContext({}),p=function(e){var t=o.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):n(n({},t),e)),a},c=function(e){var t=p(e.components);return o.createElement(s.Provider,{value:t},e.children)},m="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return o.createElement(o.Fragment,{},t)}},u=o.forwardRef((function(e,t){var a=e.components,i=e.mdxType,r=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),m=p(a),u=i,g=m["".concat(s,".").concat(u)]||m[u]||d[u]||r;return a?o.createElement(g,n(n({ref:t},c),{},{components:a})):o.createElement(g,n({ref:t},c))}));function g(e,t){var a=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var r=a.length,n=new Array(r);n[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:i,n[1]=l;for(var p=2;p<r;p++)n[p]=a[p];return o.createElement.apply(null,n)}return o.createElement.apply(null,a)}u.displayName="MDXCreateElement"},55518:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>s,contentTitle:()=>n,default:()=>d,frontMatter:()=>r,metadata:()=>l,toc:()=>p});var o=a(58168),i=(a(96540),a(15680));const r={custom_edit_url:"https://github.com/pactflow/example-bi-directional-consumer-wiremock/edit/master/README.md",title:"Example Java Consumer - Wiremock (BYO Adapter)",sidebar_label:"Example Java Consumer - Wiremock (BYO Adapter)"},n=void 0,l={unversionedId:"docs/examples/bi-directional/consumer/wiremock/readme",id:"docs/examples/bi-directional/consumer/wiremock/readme",title:"Example Java Consumer - Wiremock (BYO Adapter)",description:"Source Code",source:"@site/docs/docs/examples/bi-directional/consumer/wiremock/readme.md",sourceDirName:"docs/examples/bi-directional/consumer/wiremock",slug:"/docs/examples/bi-directional/consumer/wiremock/",permalink:"/docs/examples/bi-directional/consumer/wiremock/",draft:!1,editUrl:"https://github.com/pactflow/example-bi-directional-consumer-wiremock/edit/master/README.md",tags:[],version:"current",lastUpdatedBy:"Github Action",lastUpdatedAt:1716552828,formattedLastUpdatedAt:"May 24, 2024",frontMatter:{custom_edit_url:"https://github.com/pactflow/example-bi-directional-consumer-wiremock/edit/master/README.md",title:"Example Java Consumer - Wiremock (BYO Adapter)",sidebar_label:"Example Java Consumer - Wiremock (BYO Adapter)"},sidebar:"examples",previous:{title:"Example NodeJS/React Consumer - Nock (BYO Adapter)",permalink:"/docs/examples/bi-directional/consumer/recordreplay/"},next:{title:"Example NodeJS/React Consumer - Cypress (BYO Adapter)",permalink:"/docs/examples/bi-directional/consumer/cypress/"}},s={},p=[{value:"Source Code",id:"source-code",level:2},{value:"Overview of Example",id:"overview-of-example",level:2},{value:"Overview of Part of Bi-Directional Contract Testing Flow",id:"overview-of-part-of-bi-directional-contract-testing-flow",level:2},{value:"Compatibile with Providers",id:"compatibile-with-providers",level:2},{value:"Pre-requisites",id:"pre-requisites",level:2}
1,{value:"Environment variables",id:"environment-variables",level:3},{value:"Usage",id:"usage",level:2},{value:"Steps",id:"steps",level:3},{value:"OS/Platform specific considerations",id:"osplatform-specific-considerations",level:2},{value:"Windows",id:"windows",level:3},{value:"Caveats",id:"caveats",level:2},{value:"Related topics / posts / discussions",id:"related-topics--posts--discussions",level:2},{value:"Other examples of how to do this form of testing",id:"other-examples-of-how-to-do-this-form-of-testing",level:2},{value:"Found an issue?",id:"found-an-issue",level:2}],c={toc:p},m="wrapper";function d(e){let{components:t,...a}=e;return(0,i.yg)(m,(0,o.A)({},c,a,{components:t,mdxType:"MDXLayout"}),(0,i.yg)("h2",{id:"source-code"},"Source Code"),(0,i.yg)("p",null,(0,i.yg)("a",{parentName:"p",href:"https://github.com/pactflow/example-bi-directional-consumer-wiremock"},"https://github.com/pactflow/example-bi-directional-consumer-wiremock")),(0,i.yg)("p",null,(0,i.yg)("a",{parentName:"p",href:"https://github.com/pactflow/example-consumer-wiremock/actions/workflows/build.yml"},(0,i.yg)("img",{parentName:"a",src:"https://github.com/pactflow/example-consumer-wiremock/workflows/Build/badge.svg",alt:"Build"}))),(0,i.yg)("p",null,(0,i.yg)("a",{parentName:"p",href:"https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-wiremock/branches/master/latest-version/can-i-deploy/to-environment/production/badge"},(0,i.yg)("img",{parentName:"a",src:"https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-wiremock/branches/master/latest-version/can-i-deploy/to-environment/production/badge",alt:"Can I deploy Status"}))),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#example-java-consumer---wiremock-byo-adapter"},"Example Java Consumer - Wiremock (BYO Adapter)"),(0,i.yg)("ul",{parentName:"li"},(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#overview-of-example"},"Overview of Example")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#overview-of-part-of-bi-directional-contract-testing-flow"},"Overview of Part of Bi-Directional Contract Testing Flow")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#compatibile-with-providers"},"Compatibile with Providers")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#pre-requisites"},"Pre-requisites"),(0,i.yg)("ul",{parentName:"li"},(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#environment-variables"},"Environment variables")))),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#usage"},"Usage"),(0,i.yg)("ul",{parentName:"li"},(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#steps"},"Steps")))),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#osplatform-specific-considerations"},"OS/Platform specific considerations"),(0,i.yg)("ul",{parentName:"li"},(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#windows"},"Windows")))),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#caveats"},"Caveats")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#related-topics--posts--discussions"},"Related topics / posts / discussions")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#other-examples-of-how-to-do-this-form-of-testing"},"Other examples of how to do this form of testing")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"#found-an-issue"},"Found an issue?"))))),(0,i.yg)("h2",{id:"overview-of-example"},"Overview of Example"),(0,i.yg)("p",null,'This is an example of a Java "Product" API consumer that uses Wiremock, Pact, ',(0,i.yg)("a",{parentName:"p",href:"https://pactflow.io"},"PactFlow")," and GitHub Actions to generate and publish Pact consumer contracts."),(0,i.yg)("p",null,"It performs pre-deployment cross-compatibility checks to ensure that it is compatible with specified providers using the Bi-Directional contract capability of PactFlow."),(0,i.yg)("p",null,"See the full ",(0,i.yg)("a",{parentName:"p",href:"https://docs.pactflow.io/docs/workshops/bi-directional-contract-testing"},"PactFlow Bi-Directional Workshop"),' for which this can be substituted in as the "consumer".'),(0,i.yg)("h2",{id:"overview-of-part-of-bi-directional-contract-testing-flow"},"Overview of Part of Bi-Directional Contract Testing Flow"),(0,i.yg)("p",null,"In the following diagram, You can see how the consumer testing process works - it's the same as the current Pact process."),(0,i.yg)("p",null,'When we call "can-i-deploy" the cross-contract validation process kicks off on PactFlow, to ensure any consumer consumes a valid subset of the OAS for the provider.'),(0,i.yg)("p",null,(0,i.yg)("img",{parentName:"p",src:"https://raw.githubusercontent.com/pactflow/example-bi-directional-consumer-wiremock/master/docs/consumer-scope.png",alt:"Consumer Test"})),(0,i.yg)("p",null,"The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy."),(0,i.yg)("p",null,"When you run the CI pipeline (see below for doing this), the pipeline should perform the following activities (simplified):"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},"Test",(0,i.yg)("ul",{parentName:"li"},(0,i.yg)("li",{parentName:"ul"},"Run tests (including the pact tests that generate the contract)"),(0,i.yg)("li",{parentName:"ul"},"Publish pacts, tagging the consumer version with the name of the current branch"),(0,i.yg)("li",{parentName:"ul"},"Check if we are safe to deploy to Production with ",(0,i.yg)("inlineCode",{parentName:"li"},"can-i-deploy")," (ie. has the cross-contract validation has been successfully performed)"))),(0,i.yg)("li",{parentName:"ul"},"Deploy (only from master)",(0,i.yg)("ul",{parentName:"li"},(0,i.yg)("li",{parentName:"ul"},"Deploy app to Production"),(0,i.yg)("li",{parentName:"ul"},"Record the Production deployment in the Pact Broker")))),(0,i.yg)("p",null,(0,i.yg)("img",{parentName:"p",src:"https://raw.githubusercontent.com/pactflow/example-bi-directional-consumer-wiremock/master/docs./../docs/consumer-pipeline.png",alt:"Consumer Pipeline"})),(0,i.yg)("h2",{id:"compatibile-with-providers"},"Compatibile with Providers"),(0,i.yg)("p",null,"This project is currently compatible with the following provider(s):"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"https://github.com/pactflow/example-bi-directional-prov
1ider-dredd"},"pactflow-example-bi-directional-provider-dredd")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"https://github.com/pactflow/example-provider-restassured"},"pactflow-example-bi-directional-provider-restassured")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"https://github.com/pactflow/example-bi-directional-provider-postman"},"pactflow-example-bi-directional-provider-postman"))),(0,i.yg)("p",null,"See ",(0,i.yg)("a",{parentName:"p",href:"#environment-variables"},"Environment variables")," on how to set these up."),(0,i.yg)("h2",{id:"pre-requisites"},"Pre-requisites"),(0,i.yg)("p",null,(0,i.yg)("strong",{parentName:"p"},"Software"),":"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},"Tools listed at: ",(0,i.yg)("a",{parentName:"li",href:"https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/"},"https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/")),(0,i.yg)("li",{parentName:"ul"},"A pactflow.io account with an valid ",(0,i.yg)("a",{parentName:"li",href:"https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token"},"API token"))),(0,i.yg)("h3",{id:"environment-variables"},"Environment variables"),(0,i.yg)("p",null,"To be able to run some of the commands locally, you will need to export the following environment variables into your shell:"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"PACT_BROKER_TOKEN"),": a valid ",(0,i.yg)("a",{parentName:"li",href:"https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token"},"API token")," for PactFlow"),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"PACT_BROKER_BASE_URL"),": a fully qualified domain name with protocol to your pact broker e.g. ",(0,i.yg)("a",{parentName:"li",href:"https://testdemo.pactflow.io"},"https://testdemo.pactflow.io"))),(0,i.yg)("p",null,"Set ",(0,i.yg)("inlineCode",{parentName:"p"},"PACT_PROVIDER")," to one of the following"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"PACT_PROVIDER=pactflow-example-bi-directional-provider-dredd"),": Dredd - (",(0,i.yg)("a",{parentName:"li",href:"https://github.com/pactflow/example-bi-directional-provider-dredd"},"https://github.com/pactflow/example-bi-directional-provider-dredd"),")"),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"PACT_PROVIDER=pactflow-example-bi-directional-provider-postman"),": Postman - (",(0,i.yg)("a",{parentName:"li",href:"https://github.com/pactflow/example-bi-directional-provider-postman"},"https://github.com/pactflow/example-bi-directional-provider-postman"),")"),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"PACT_PROVIDER=pactflow-example-bi-directional-provider-restassured"),":  Rest Assured - (",(0,i.yg)("a",{parentName:"li",href:"https://github.com/pactflow/example-bi-directional-provider-restassured"},"https://github.com/pactflow/example-bi-directional-provider-restassured"),")")),(0,i.yg)("p",null,"NOTE:- It defaults to ",(0,i.yg)("inlineCode",{parentName:"p"},"pactflow-example-bi-directional-provider-restassured")," for compatibility with the ",(0,i.yg)("a",{parentName:"p",href:"https://github.com/pactflow/example-bi-directional-provider-restassured"},"Java RestAssured")," provider"),(0,i.yg)("h2",{id:"usage"},"Usage"),(0,i.yg)("h3",{id:"steps"},"Steps"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"make test")," - run the tests locally"),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"make fake_ci")," - run the CI process, but locally")),(0,i.yg)("h2",{id:"osplatform-specific-considerations"},"OS/Platform specific considerations"),(0,i.yg)("p",null,"The makefile is configured to run on Unix based systems such as you would find in most common CI/CD pipelines. "),(0,i.yg)("p",null,"They can be run locally on Unix/Mac, or on Windows via ",(0,i.yg)("a",{parentName:"p",href:"https://docs.microsoft.com/en-us/windows/wsl/install"},"WSL2"),". "),(0,i.yg)("h3",{id:"windows"},"Windows"),(0,i.yg)("p",null,"You can still try this example locally on Windows using powershell and running commands manually. "),(0,i.yg)("details",null,(0,i.yg)("summary",null,"Click to see windows specific instructions here"),(0,i.yg)("p",null,"  These will be the same commands that are used in the makefile with a few manual tweaks."),(0,i.yg)("ol",null,(0,i.yg)("li",{parentName:"ol"},(0,i.yg)("p",{parentName:"li"},"Make sure you have set all of the environment variables, in powershell they can be set like so."),(0,i.yg)("pre",{parentName:"li"},(0,i.yg)("code",{parentName:"pre"},' $env:GIT_BRANCH="main"\n'))),(0,i.yg)("li",{parentName:"ol"},(0,i.yg)("p",{parentName:"li"},"Publish the pact that was generated. The step uses the pact-cli docker image to publish the pact to your pactflow account.\nThe path for ",(0,i.yg)("inlineCode",{parentName:"p"},"<path_to_project_root>")," needs to be converted from Windows paths to UNIX ones as the Docker 
1container is using UNIX. Either hard code this or set it as another environment variable."),(0,i.yg)("pre",{parentName:"li"},(0,i.yg)("code",{parentName:"pre"},"`C:\\Users\\Person\\Documents\\example-bi-directional-consumer-dotnet` \n\nbecomes\n\n`/c/Users/Candy/Documents/PactFlow/example-bi-directional-consumer-dotnet`\n\n$env:VARIABLE_NAME refers to the environment variables in windows.\n\n```\ndocker run --rm -v <path_to_project_root>:<path_to_project_root> -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli publish <path_to_pacts_folder> --consumer-app-version $env:GIT_COMMIT --branch $env:GIT_BRANCH\n\n```\n"))),(0,i.yg)("li",{parentName:"ol"},(0,i.yg)("p",{parentName:"li"},"Check can-i-deploy to see if your provider is compatible with your pact."),(0,i.yg)("pre",{parentName:"li"},(0,i.yg)("code",{parentName:"pre"},"docker run --rm -v <path_to_project_root>:<path_to_project_root> -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli  broker can-i-deploy --pacticipant pactflow-example-bi-directional-consumer-dotnet --version $env:GIT_COMMIT --to-environment production  --retry-while-unknown 0 --retry-interval 10\n"))),(0,i.yg)("li",{parentName:"ol"},(0,i.yg)("p",{parentName:"li"},"Have a look at what other commands are available in the Makefile. All of them can be ran locally from Powershell by changing the windows paths to UNIX and replacing the environment variable references. Any variable referenced as ",(0,i.yg)("inlineCode",{parentName:"p"},"${VARIABLE}")," can be changed to ",(0,i.yg)("inlineCode",{parentName:"p"},"$env:VARIABLE")," to reference environment variables in Powershell.")))),(0,i.yg)("h2",{id:"caveats"},"Caveats"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/oas#considerations"},"OAS considerations"))),(0,i.yg)("h2",{id:"related-topics--posts--discussions"},"Related topics / posts / discussions"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"https://docs.pactflow.io/docs/bi-directional-contract-testing/consumer"},"Consumer Side Bi-Directional Contract Testing Guide")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("a",{parentName:"li",href:"https://docs.pactflow.io/docs/bi-directional-contract-testing/provider"},"Provider Side Bi-Directional Contract Testing Guide"))),(0,i.yg)("h2",{id:"other-examples-of-how-to-do-this-form-of-testing"},"Other examples of how to do this form of testing"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},"TBC")),(0,i.yg)("h2",{id:"found-an-issue"},"Found an issue?"),(0,i.yg)("p",null,"Reach out via a GitHub Issue, or reach us over in the ",(0,i.yg)("a",{parentName:"p",href:"https://slack.pact.io"},"Pact foundation Slack")))}d.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.