Giter Club home page Giter Club logo

spring-cloud-contract-demo's Introduction

Spring Cloud Contract Demo

Description

This a demo Spring Boot application that demonstrates the implementation of consumer-driven contract tests with the Spring Cloud Contract framework. The project contains two modules, namely an API provider (cloud-contract-provider) and an API consumer (cloud-contract-consumer). There are three contracts, as one contract defines a single request/response pair. The table below lists the different contracts and the endpoints they define:

Endpoint Contract file
POST   /books shouldCreateBook.groovy
GET     /books/{id} shouldFindBookById.groovy
PUT     /books/{id} shouldUpdateBook.groovy

Both the API provider and consumer (including tests) are implemented Java. A list comprising the used frameworks/technologies is given below:

  Java                      11
  Gradle                    6.2.2
  Spring Boot               2.2.5.RELEASE
  Spring Cloud Contract     2.2.2.RELEASE

Building & Running the tests

The complete project can be built with the following command executed at top level:

./gradlew clean build

The server tests will be generated from the contracts located in cloud-contract-producer/src/test/resources/contracts/booksapi. The Gradle task check will generate and run the generated server tests (executed in the cloud-contract-producer directory):

./gradlew check

In order to be able to write the tests for the client side (API consumer) we need a stub implementation of the server contracts. The Gradle task verifierStubsJar generates the client stubs and packages them in a JAR file. The JAR file can be published to local Maven repository with the following task (executed in the cloud-contract-producer directory):

./gradlew publishStubsPublicationToMavenLocal

This will generate and publish the cloud-contract-producer-0.0.1-SNAPSHOT-stubs.jar JAR file to the local Maven repository. On the consumer side we use the AutoConfigureStubRunner annotation to run the server stubs. Here in the id attribute we specify the coordinates of the previously generated artifact and the port on which the server stubs will run. Additionally, we specify the location of the generated stubs, which in our case is LOCAL (the stubs will be fetched from a local Maven repository):

@AutoConfigureStubRunner(ids = "com.bzb.spring.cloud:cloud-contract-producer:0.0.1-SNAPSHOT:stubs:8001", stubsMode = StubRunnerProperties.StubsMode.LOCAL)

Finally, we can execute the client tests with the command executed in the cloud-contract-consumer directory:

./gradlew clean check

spring-cloud-contract-demo's People

Contributors

bzb0 avatar

Watchers

 avatar

spring-cloud-contract-demo's Issues

Execution failed for task ':cloud-contract-consumer:compileJava'. > Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'

i tried ./gradlew clean build then i got this error

Task :cloud-contract-consumer:compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':cloud-contract-consumer:compileJava'.

Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

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.