Giter Site home page Giter Site logo

bwgjoseph / spring-boot-consumer-driven-contract-demo Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 2.1 MB

Spring Boot with Pact

HTML 44.40% CSS 4.15% JavaScript 5.77% Java 42.62% Groovy 3.05%
consumer-driven-contracts java junit5 pact pact-broker spring-boot spring-cloud-contract hacktoberfest

spring-boot-consumer-driven-contract-demo's Introduction

Spring Boot Consumer Driven Contract Demo

This project is written to attempt to understand more about Consumer Driven Contract with the use of Spring Boot + Pact / Spring Cloud Contract

Goal

  • Basic understanding and setup of Pact consumer / provider
  • Basic understanding and setup of Pact server
  • Basic understanding and setup of SCC provider / consumer
  • HTTP contract test for Pact
  • Messaging contract test for Pact
  • HTTP contract test for SCC
  • Messaging contract test for SCC
  • Using SCC with Pact Broker

Project

This repository includes four distinct sub-project;

Run

Navigate to the individual directory and run

./gradlew bootRun

Build

Navigate to the individual directory and run

./gradlew [clean] build

Pact CDC

Broker

As mentioned earlier, without using Broker, we need to transfer the generated contract from the Consumer to Provider manually. However, with Broker, we can simply ask the Consumer to publish the contracts to Broker, and the Provider will read and verify the contracts from the Broker. This allows for even more seamless integration test and the Broker also has UI to view the result

To startup the broker, navigate to root directory and run

docker-compose up -d

Access via http://localhost:9292

Known Issue

  • Since au.com.dius.pact.consumer:junit5:4.3.0 onwards, when running the test, it will throw error java.lang.UnsupportedOperationException: Method getSingleProfile does not conform required method signature 'public au.com.dius.pact.core.model.V4Pact xxx(PactBuilder builder)'
    • See test-report, most likely related to this issue and this note
    • To overcome this, we can change to PactSpecVersion.V3 like such @PactTestFor(providerName = "ProfileProvider", pactVersion = PactSpecVersion.V3)
    • Seem like PactSpecVersion.V4 is the default, and is incompatible with V3
  • When running the test via VSCode (manual click), pact generated contract will be output to target/pact even though using gradle. However, if running via command ./gradlew build, there won't be such issue
  • Unable to publish verification result to broker after running ./gradlew pactVerify command. Have reported the issue.
    • Managed to get the result published after some help but still facing issue when using with gradle plugin

Spring Cloud Contract CDC

Known Issue

  • start.spring.io wrongly generated contracts as task instead of extension for gradle

Consideration

  • Consumer Driven Contract [Pact] vs Provider Driven Contract [SCC]
  • Ease of use
  • Learning curve / Overhead

Developer Experience

Documentation

  • Both libraries don't provide the best out-of-the-box experience to start as the documentation seem to jump all around, and are quite confusing (sometimes)

Tooling Support

  • So far, I am using gradle to test in my demo, and online is lacking on the support for gradle. Most of the example are written using maven, and my attempt to use gradle has faced multiple issues.
    • Especially when an error occurs, it wasn't quite clear of what exactly is happening. I have to enable --info or --debug to see what exactly is the issue
    • One example was when using SCC, in my contract, I did not enclose the response.body.email with quotes, but the error was pointing at Line 5 of the getAllProfiles.groovy file which was the start of the contract and was able to know when I turn on --debug mode
  • To be fair, if I had chose to use maven, the experience should have been better

Features

  • In Pact, consumer writes what fields are required in the contract before submitting, and provider run against it
  • In SCC, provider provides the stub and consumer run against the stub, then verify if the fields they need are there
  • In SCC, it seem less straightforward to write contract against Date

Further exploration

Possibly look into using Spring Cloud Contract with pact-broker Look into scc-multiapi-converter

Sample

Reference

spring-boot-consumer-driven-contract-demo's People

Contributors

bwgjoseph avatar

Watchers

 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.