Coder Social home page Coder Social logo

scala-pact-example's Introduction

scala-pact-example

A sample project to play around Pact and scala-pact

The sample consists in three applications:

   
┏━━━━━━┓                           ┏━━━━━━┓                           ┏━━━━━━┓ 
┃      ┃  ---------------------->  ┃      ┃  ---------------------->  ┃      ┃
┃ App1 ┃   POST /data/forward      ┃ App2 ┃   POST /data/             ┃ App3 ┃
┃      ┃  <----------------------  ┃      ┃  <----------------------  ┃      ┃
┗━━━━━━┛ Location: http://app3/123 ┗━━━━━━┛ Location: http://app3/123 ┗━━━━━━┛ 

App1 performs a POST the App2, that forwards this request to App3 that eventually stores some data in its datastore.
The return value will be the Location header of the machine in which the data got stored.

App1 is a Consumer of App2
App2 is a Provider for App1 and a Consumer of App3
App3 is a Provider for App2

Build

App1

Being just a Consumer, we need to generate the Pact file and publishing it to the Pact broker

sbt pact-publish

N.B.: This command will also run pact-test used to generate the Pact files

App2

Being a Consumer we need to generate and publish the Pact file, but let's not run sbt pact-publish yet

Being also a Producer we need to need to verify the existing contracts with the other consumers. In order do that, we need to run our tests with sbt test but let's not run it yet :)
We cannot run the test just yet because we first need to stub our dependencies, that's why we're going to run this command first:

export APP_PORT=19092;export SERVICE_FORWARD_URI="http://localhost:1234/data";sbt pact-stubber

This command will create a Stubber on port 1234 that will behave according to the Pacts retrieved from the broker.
Unfortunately this command also runs the tests, so we will see some errors, and that's also why we're passing those environment variables. Those variables are not needed by the stubber itself but by the fact that the test will run the application.
Now that the stubber is running, we can finally we can finally run our tests, pointing our application to the stubber URI.

export APP_PORT=9092;export SERVICE_FORWARD_URI="http://localhost:1234/data";sbt pact-publish

This will also run sbt test and verify then our provider.

App3

App3 is just a Provider so the same steps as App2 apply:

export APP_PORT=19092;export SERVICE_FORWARD_URI="http://localhost:1234/data";sbt pact-stubber
export APP_PORT=9092;export SERVICE_FORWARD_URI="http://localhost:1234/data";sbt pact-publish

scala-pact-example's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.