Giter Club home page Giter Club logo

microservices-pact's Introduction

Spring Boot Microservices + Pact-JVM

This project contains a very simple demo of using consumer-driven contracts to verify the interactions between microservices. It leverages Spring Boot for both the provider and consumer services.

Testing is achieved using the pact-jvm project, which is a JVM port of the original pact.

Running the Demo

  1. Run the tests using Gradle:

    $ gradle test
  2. This will result in the creation of a pact file called Foo_Consumer-Foo_Provider.json at microservices-pact/microservices-pact-consumer/target/pacts. Here’s a current example:

    {
      "provider" : {
        "name" : "Foo_Provider"
      },
      "consumer" : {
        "name" : "Foo_Consumer"
      },
      "interactions" : [ {
        "description" : "a request for Foos",
        "request" : {
          "method" : "GET",
          "path" : "/foos"
        },
        "response" : {
          "status" : 200,
          "headers" : {
            "Content-Type" : "application/json;charset=UTF-8"
          },
          "body" : [ {
            "value" : 42
          }, {
            "value" : 100
          } ]
        }
      } ],
      "metadata" : {
        "pact-specification" : {
          "version" : "2.0.0"
        },
        "pact-jvm" : {
          "version" : "2.1.7"
        }
      }
    }

    By virtue of the fact that these tests pass, we know that the microservices-pact-consumer app interacts appropriately with the contract as defined in ConsumerPortTest.java.

  3. Next, we want to verify that the microservices-pact-provider app actually provides the expected contract. First, build the apps:

    $ gradle assemble
  4. Next, in one terminal window, start up the provider app:

    $ java -jar microservices-pact-provider/build/libs/microservices-pact-provider-0.0.1-SNAPSHOT.jar
  5. Then, in another terminal window, run the pact verification:

    $ gradle pactVerify

    You should see output along these lines:

    $ gradle pactVerify
    :microservices-pact-provider:pactVerify_fooProvider
    
    Verifying a pact between fooConsumer and fooProvider
      [Using file /Users/pivotal/workspace/microservices-pact/microservices-pact-consumer/target/pacts/Foo_Consumer-Foo_Provider.json]
      a request for Foos
        returns a response which
          has status code 200 (OK)
          includes headers
            "Content-Type" with value "application/json;charset=UTF-8" (OK)
          has a matching body (OK)
    :microservices-pact-provider:pactVerify
    
    BUILD SUCCESSFUL

microservices-pact's People

Contributors

avanderberg avatar

Watchers

James Cloos avatar  avatar

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.