1"use strict";(self.webpackChunkpartners=self.webpackChunkpartners||[]).push([[36173],{15680:(e,t,a)=>{a.d(t,{xA:()=>c,yg:()=>g});var r=a(96540);function o(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function p(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function n(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?p(Object(a),!0).forEach((function(t){o(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):p(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function i(e,t){if(null==e)return{};var a,r,o=function(e,t){if(null==e)return{};var a,r,o={},p=Object.keys(e);for(r=0;r<p.length;r++)a=p[r],t.indexOf(a)>=0||(o[a]=e[a]);return o}(e,t);if(Object.getOwnPropertySymbols){var p=Object.getOwnPropertySymbols(e);for(r=0;r<p.length;r++)a=p[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(o[a]=e[a])}return o}var l=r.createContext({}),s=function(e){var t=r.useContext(l),a=t;return e&&(a="function"==typeof e?e(t):n(n({},t),e)),a},c=function(e){var t=s(e.components);return r.createElement(l.Provider,{value:t},e.children)},u="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},d=r.forwardRef((function(e,t){var a=e.components,o=e.mdxType,p=e.originalType,l=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),u=s(a),d=o,g=u["".concat(l,".").concat(d)]||u[d]||m[d]||p;return a?r.createElement(g,n(n({ref:t},c),{},{components:a})):r.createElement(g,n({ref:t},c))}));function g(e,t){var a=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var p=a.length,n=new Array(p);n[0]=d;var i={};for(var l in t)hasOwnProperty.call(t,l)&&(i[l]=t[l]);i.originalType=e,i[u]="string"==typeof e?e:o,n[1]=i;for(var s=2;s<p;s++)n[s]=a[s];return r.createElement.apply(null,n)}return r.createElement.apply(null,a)}d.displayName="MDXCreateElement"},27255:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>n,default:()=>m,frontMatter:()=>p,metadata:()=>i,toc:()=>s});var r=a(58168),o=(a(96540),a(15680));const p={custom_edit_url:"https://github.com/pactflow/example-provider-springboot/edit/master/README.md",title:"Example Java Spring Boot Provider",sidebar_label:"Example Java Spring Boot Provider"},n=void 0,i={unversionedId:"docs/examples/java/provider-springboot/readme",id:"docs/examples/java/provider-springboot/readme",title:"Example Java Spring Boot Provider",description:"Source Code",source:"@site/docs/docs/examples/java/provider-springboot/readme.md",sourceDirName:"docs/examples/java/provider-springboot",slug:"/docs/examples/java/provider-springboot/",permalink:"/docs/examples/java/provider-springboot/",draft:!1,editUrl:"https://github.com/pactflow/example-provider-springboot/edit/master/README.md",tags:[],version:"current",lastUpdatedBy:"Github Action",lastUpdatedAt:1728562302,formattedLastUpdatedAt:"Oct 10, 2024",frontMatter:{custom_edit_url:"https://github.com/pactflow/example-provider-springboot/edit/master/README.md",title:"Example Java Spring Boot Provider",sidebar_label:"Example Java Spring Boot Provider"},sidebar:"examples",previous:{title:"Example Java GraphQL Provider",permalink:"/docs/examples/java/provider/graphql/"},next:{title:"Example Consumer",permalink:"/docs/examples/js/consumer/"}},l={},s=[{value:"Source Code",id:"source-code",level:2},{value:"Project Phases",id:"project-phases",level:2},{value:"Dependencies",id:"dependencies",level:2},{value:"Usage",id:"usage",level:2},{value:"Simulating CI",id:"simulating-ci",level:3}],c={toc:s},u="wrapper";
1function m(e){let{components:t,...a}=e;return(0,o.yg)(u,(0,r.A)({},c,a,{components:t,mdxType:"MDXLayout"}),(0,o.yg)("h2",{id:"source-code"},"Source Code"),(0,o.yg)("p",null,(0,o.yg)("a",{parentName:"p",href:"https://github.com/pactflow/example-provider-springboot"},"https://github.com/pactflow/example-provider-springboot")),(0,o.yg)("p",null,(0,o.yg)("img",{parentName:"p",src:"https://github.com/pactflow/example-provider-springboot/workflows/Build/badge.svg",alt:"Build"})),(0,o.yg)("p",null,(0,o.yg)("a",{parentName:"p",href:"https://test.pactflow.io/overview/provider/pactflow-example-provider-springboot/consumer/pactflow-example-consumer-java-junit"},(0,o.yg)("img",{parentName:"a",src:"https://test.pactflow.io/pacticipants/pactflow-example-provider-springboot/branches/master/latest-version/can-i-deploy/to-environment/production/badge.svg",alt:"Can I deploy Status"}))),(0,o.yg)("p",null,(0,o.yg)("a",{parentName:"p",href:"https://test.pactflow.io/pacts/provider/pactflow-example-provider-springboot/consumer/pactflow-example-consumer-java-junit/latest"},(0,o.yg)("img",{parentName:"a",src:"https://test.pactflow.io/pacts/provider/pactflow-example-provider-springboot/consumer/pactflow-example-consumer-java-junit/latest/badge.svg",alt:"Pact Status"}))," (latest pact)"),(0,o.yg)("p",null,(0,o.yg)("a",{parentName:"p",href:"https://test.pactflow.io/pacts/provider/pactflow-example-provider-springboot/consumer/pactflow-example-consumer-java-junit/latest/prod"},(0,o.yg)("img",{parentName:"a",src:"https://test.pactflow.io/pacts/provider/pactflow-example-provider-springboot/consumer/pactflow-example-consumer-java-junit/latest/prod/badge.svg",alt:"Pact Status"}))," (prod/prod pact)"),(0,o.yg)("p",null,"This is an example of a Java Spring Boot provider that uses Pact, ",(0,o.yg)("a",{parentName:"p",href:"https://pactflow.io"},"PactFlow")," and GitHub Actions to ensure that it is compatible with the expectations its consumers have of it."),(0,o.yg)("p",null,"The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy."),(0,o.yg)("p",null,"It is using a public tenant on PactFlow, which you can access ",(0,o.yg)("a",{parentName:"p",href:"https://test.pactflow.io"},"here")," using the credentials ",(0,o.yg)("inlineCode",{parentName:"p"},"dXfltyFMgNOFZAxr8io9wJ37iUpY42M"),"/",(0,o.yg)("inlineCode",{parentName:"p"},"O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"),"."),(0,o.yg)("h2",{id:"project-phases"},"Project Phases"),(0,o.yg)("p",null,"The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy."),(0,o.yg)("ul",null,(0,o.yg)("li",{parentName:"ul"},"Test",(0,o.yg)("ul",{parentName:"li"},(0,o.yg)("li",{parentName:"ul"},"Run tests (including the pact tests that generate the contract)"),(0,o.yg)("li",{parentName:"ul"},"Publish pacts, tagging the consumer version with the name of the current branch"),(0,o.yg)("li",{parentName:"ul"},"Check if we are safe to deploy to prod (ie. has the pact content been successfully verified)"))),(0,o.yg)("li",{parentName:"ul"},"Deploy (only from master)",(0,o.yg)("ul",{parentName:"li"},(0,o.yg)("li",{parentName:"ul"}
1,"Deploy app (just pretend for the purposes of this example!)"),(0,o.yg)("li",{parentName:"ul"},"Tag the deployed consumer version as 'prod'")))),(0,o.yg)("h2",{id:"dependencies"},"Dependencies"),(0,o.yg)("ul",null,(0,o.yg)("li",{parentName:"ul"},"Docker"),(0,o.yg)("li",{parentName:"ul"},"A ",(0,o.yg)("a",{parentName:"li",href:"https://pactflow.io"},"PactFlow")," account"),(0,o.yg)("li",{parentName:"ul"},"A ",(0,o.yg)("a",{parentName:"li",href:"https://docs.pactflow.io/#configuring-your-api-token"},"read/write API Token")," from your PactFlow account"),(0,o.yg)("li",{parentName:"ul"},"Java 8+ installed")),(0,o.yg)("h2",{id:"usage"},"Usage"),(0,o.yg)("p",null,"See the ",(0,o.yg)("a",{parentName:"p",href:"https://github.com/pactflow/ci-cd-workshop"},"PactFlow CI/CD Workshop"),"."),(0,o.yg)("blockquote",null,(0,o.yg)("p",{parentName:"blockquote"},(0,o.yg)("em",{parentName:"p"},"Note:")," This repository is designed, out the box to work with the ",(0,o.yg)("a",{parentName:"p",href:"https://github.com/pactflow/example-consumer-java-junit"},(0,o.yg)("inlineCode",{parentName:"a"},"example-consumer-java-junit"))," project, which specifies the provider it depends on, as the one named in this repository (",(0,o.yg)("inlineCode",{parentName:"p"},"pactflow-example-provider-springboot"),"). If you are using another consumer example such as the ",(0,o.yg)("a",{parentName:"p",href:"https://github.com/pactflow/example-consumer"},(0,o.yg)("inlineCode",{parentName:"a"},"pactflow-example-consumer"))," repo, you should do one of the following in your consumer project, either override the environment variable ",(0,o.yg)("inlineCode",{parentName:"p"},"PACT_PROVIDER=pactflow-example-provider-springboot")," or update ",(0,o.yg)("a",{parentName:"p",href:"https://github.com/pactflow/example-consumer/blob/master/src/api.pact.spec.js#L9"},"the test")," to specify the correct provider name.")),(0,o.yg)("p",null,"The below commands are designed for a Linux/OSX environment, please translate for use on Windows/PowerShell as necessary:"),(0,o.yg)("p",null,"Please ensure the following environment variables have been exported in the process that you run the tests (generally a terminal):"),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre"},"export PACT_BROKER_TOKEN=<your pactflow read/write token here>\nexport PACT_BROKER_BASE_URL=https://<your pactflow subdomain>.pactflow.io\nexport PACT_BROKER_HOST=<your pactflow subdomain>.pactflow.io\n")),(0,o.yg)("p",null,"You can run the tests locally with:"),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre"},"make test\n")),(0,o.yg)("h3",{id:"simulating-ci"},"Simulating CI"),(0,o.yg)("p",null,"Usually, you would integrate this into a real CI system (such as Buildkite/Jenkins/CircleCI etc., or GitHub Actions as this repository is built against)."),(0,o.yg)("p",null,"You can simulate a CI process with the following command:"),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre"},"make fake_ci\n")))}m.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.