spring-cloud-contract | Support for Consumer Driven Contracts in Spring | Microservice library

 by   spring-cloud Java Version: v2.2.3.RELEASE License: Apache-2.0

kandi X-RAY | spring-cloud-contract Summary

kandi X-RAY | spring-cloud-contract Summary

spring-cloud-contract is a Java library typically used in Architecture, Microservice, Spring Boot, Spring applications. spring-cloud-contract has build file available, it has a Permissive License and it has high support. However spring-cloud-contract has 14 bugs and it has 1 vulnerabilities. You can download it from GitHub, Maven.

You always need confidence when pushing new features into a new application or service in a distributed system. To that end, this project provides support for consumer-driven contracts and service schemas in Spring applications, covering a range of options for writing tests, publishing them as assets, and asserting that a contract is kept by producers and consumers — for both HTTP and message-based interactions.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              spring-cloud-contract has a highly active ecosystem.
              It has 681 star(s) with 415 fork(s). There are 42 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 71 open issues and 1181 have been closed. On average issues are closed in 231 days. There are no pull requests.
              It has a positive sentiment in the developer community.
              The latest version of spring-cloud-contract is v2.2.3.RELEASE

            kandi-Quality Quality

              OutlinedDot
              spring-cloud-contract has 14 bugs (1 blocker, 2 critical, 5 major, 6 minor) and 1871 code smells.

            kandi-Security Security

              spring-cloud-contract has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              OutlinedDot
              spring-cloud-contract code analysis shows 1 unresolved vulnerabilities (1 blocker, 0 critical, 0 major, 0 minor).
              There are 12 security hotspots that need review.

            kandi-License License

              spring-cloud-contract is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              spring-cloud-contract releases are available to install and integrate.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              spring-cloud-contract saves you 47613 person hours of effort in developing the same functionality from scratch.
              It has 55670 lines of code, 5220 functions and 930 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed spring-cloud-contract and discovered the below as its top functions. This is intended to give you an instant insight into spring-cloud-contract implemented functionality, and help decide if they suit your requirements.
            • Implementation of PactBrokerLoader
            • Finds all contracts .
            • Process contracts .
            • Deletes a directory recursively .
            • Append the body of the request .
            • Creates and configures the contracts .
            • Traverses the value using the given function .
            • Builds the environment variables .
            • Returns the matching rules for the given body matchers .
            • Add body to the request body
            Get all kandi verified functions for this library.

            spring-cloud-contract Key Features

            No Key Features are available at this moment for spring-cloud-contract.

            spring-cloud-contract Examples and Code Snippets

            No Code Snippets are available at this moment for spring-cloud-contract.

            Community Discussions

            QUESTION

            What $() syntax means for Groovy language?
            Asked 2021-May-08 at 14:56

            I found this in Groovy Syntax documentation at 4.6.1. Special cases:

            As slashy strings were mostly designed to make regexp easier so a few things that are errors in GStrings like $() or $5 will work with slashy strings.

            What $() syntax means? give some usage examples please

            I also found it at Define the Contract Locally in the Repository of the Fraud Detection Service:

            ...

            ANSWER

            Answered 2021-May-08 at 14:56

            It means nothing (or what you make of it). There are two places, you are addressing, but they have nothing to do with each other.

            The docs just mention this as "you can use slashy strings to write things, that would give you an error with a GString" - the same is true for just using '-Strings.

            E.g.

            Source https://stackoverflow.com/questions/67448673

            QUESTION

            Groovy and Spring Cloud Contract - Variable in the bodyAsValue
            Asked 2021-Apr-24 at 09:48

            I would like to know how am I supposed to create in Groovy the Json payload with a random value. For example

            ...

            ANSWER

            Answered 2021-Apr-24 at 09:48

            You have to call it for the whole body, it won't work for part of it

            Source https://stackoverflow.com/questions/67233141

            QUESTION

            What programming languages does the Spring Cloud Contract Stub Runner support?
            Asked 2021-Mar-31 at 15:37

            I'm learning about Spring Cloud Contract and have a question regarding the supported languages. While writing SCC Stub runner based contract tests the documentation seems to imply that we're supporting tests written in either JUnit or Spock.

            https://cloud.spring.io/spring-cloud-contract/1.2.x/multi/multi__spring_cloud_contract_stub_runner.html

            Can we use the Spring Cloud Contract Stub Runner only for Java / Groovy languages or does it support other languages as well?

            ...

            ANSWER

            Answered 2021-Mar-31 at 15:37

            Please read the blog post https://spring.io/blog/2018/02/13/spring-cloud-contract-in-a-polyglot-world and the documentation here https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/using.html#flows-provider-non-jvm where we explain the workflows for non jvm apps. Here https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/project-features.html#contract-dsl you can find the list of supported contract formats. Please always read the documentation before filing a question.

            Source https://stackoverflow.com/questions/66889898

            QUESTION

            Spring Cloud Contract - empty path parameter randomly generated from the regexp
            Asked 2021-Mar-30 at 09:53

            I am trying to introduce path param in urlPath as regexp in the following way:

            ...

            ANSWER

            Answered 2021-Mar-30 at 09:53

            The problem was with the regex. Instead of /trackedItems/([a-zA-Z0-9]*)/locationOccupancies there should be /trackedItems/([a-zA-Z0-9]+)/locationOccupancies

            Source https://stackoverflow.com/questions/66742644

            QUESTION

            Spring Cloud Contract - Node.js as producer
            Asked 2021-Mar-15 at 12:06

            My team is creating 2 microservices. One in Spring - consumer and another in Node.js - producer. They will communicate through http rest api.

            We would like to test them using contract. I've seen https://spring.io/blog/2018/02/13/spring-cloud-contract-in-a-polyglot-world but it's a different case (producer is on Java side and consumer is on Js).

            Is there a way to define contract and generate tests for both microservices in such case?

            ...

            ANSWER

            Answered 2021-Mar-15 at 12:06

            You can generate a standard contract test with the spring cloud contract plugin. You will also generate stubs and push them out. On the consumer side you can use the docker spring cloud stub runner image to run the stubs.

            Source https://stackoverflow.com/questions/66637370

            QUESTION

            Is it possible with spring-cloud-contract to work on a contract branch for the producer?
            Asked 2021-Mar-12 at 13:04

            Currently we have a github repo where we store all the contracts, another repo which contains the producer code, and last but not least another one which contains the consumer code.

            On the consumer side working with branches when pointing to the contract repo is well supported by using properties like stubrunner.properties.git.branch (more info can be found here https://cloud.spring.io/spring-cloud-contract/reference/html/appendix.html#additional-application-properties)

            But on the producer I can not see any way of using the contracts of a concrete branch, we just can point to the github repo where contracts are stored by using contractsRepositoryUrl of the spring-cloud-contract-maven-plugin

            This will be very useful to create a flow of contract testing :

            • a PR to contract testing repo with the proposal
            • which will trigger the producer job (passing the pr branch name)
            • if the repo with the contracts contains the bindings, populated by the producer(previous step), then we could trigger the consumer job and validate if everything is fine with these proposed changes
            • once the 2 builds are green (producer and consumer) we can merge the changes on the contracts repo

            UPDATE : the following spring-cloud-contract-maven-plugin config worked for me, also you can set this property through command line like this -Dstubrunner.properties.git.branch=other_branch_than_master

            ...

            ANSWER

            Answered 2021-Mar-12 at 11:41

            You can reuse the same properties presented here (https://docs.spring.io/spring-cloud-contract/docs/2.2.6.RELEASE/reference/html/appendix.html#additional-application-properties) under the e.g. Spring Cloud Contract Maven's section. That way you can pick which branch should be downloaded

            Source https://stackoverflow.com/questions/66597175

            QUESTION

            Discussion: Should CDC based producer tests mock business logic or integrate with business logic
            Asked 2020-Nov-18 at 07:56

            My question addresses a conceptual issue with consumer driven contracts (CDCs), not with Spring-Cloud-Contract in particular (though tagged otherwise).

            A CDC usually guarantees a particular behavior of a service (producer/supplier) to its client (consumer). Many architectures (e.g. Hexagonal/Clean/Onion Architecture) have an adapter/layer to provide the technical interface(s) of the service (REST/SOAP/Messaging/...). They separate the adapter from the business logic. When tests are written based on a CDC it is possible to just test the adapter (classical unit test) and mock away the business logic.

            However, the contract formally does not only specify a particular mapping of the result (from the business logic) to the data transfer object as returned by the adapter. Moreover it contains semantics wrt. to the request/response behavior: If the consumer sends a specific request with meaningful data, the producer should respond with a particular correct answer (with respect to the request).

            My point for discussion/question is: Should the test on the producer side then be an integration test (integrating business logic) to check if the business logic will return the correct answer? In this case the next layer (behind business logic) might be mocked away as long as the business logic is an integral part of the test case.

            In Spring CDCs (but I think in other CDC implementations as well) it is possible to distinguish between consumer and producer side and the generated test cases. For example it would be possible to reduce the producer part to check for formal correctness of the response (e.g., if a particular data item is contained and validates against a pattern) while it specifies a concrete response for the consumer part at the same time. This might lead to the (mis-) understanding on the consumer side (and backed by the consumer tests) that the concrete specified data would be returned by the producer if the consumer had sent the specified request from the CDC.

            What do users of CDCs think? How do you specify behavior and to what extent do you test it on the producer side?

            ...

            ANSWER

            Answered 2020-Nov-18 at 07:56

            We describe it in the documentation - https://docs.spring.io/spring-cloud-contract/docs/2.2.5.RELEASE/reference/htmlsingle/#getting-started-introducing-spring-cloud-contract-purposes . Let me write it here for your convenience

            Spring Cloud Contract’s purpose is NOT to start writing business features in the contracts. Assume that we have a business use case of fraud check. If a user can be a fraud for 100 different reasons, we would assume that you would create two contracts, one for the positive case and one for the negative case. Contract tests are used to test contracts between applications and not to simulate full behavior.

            If you check Pact's documentation (https://docs.pact.io/faq#do-i-still-need-end-to-end-tests) you'll find

            Contract tests replace a certain class of system integration test (the ones you do to make sure that you're using the API correctly and that the API responds the way you expect). They don't replace the tests that ensure that the core business logic of your services is working.

            In case of Spring Cloud Contract - if you have a controller that delegates work to a service, then you should mock out the service and test only whether your controller can take a request and send back a proper response

            Source https://stackoverflow.com/questions/64888562

            QUESTION

            Is it possible to have one OpenApi3 definition for contract and for contract test specification which will be parsable by spring-cloud-contract?
            Asked 2020-Sep-24 at 12:07

            The idea is to have one file for both - contract definition and contract test specification.

            I found the plugin 'guru.springframework:spring-cloud-contract-oa3:2.1.2.0' which should make what I want but it fails for me. I based my config on the examples from this repo https://github.com/springframeworkguru/sccoa3-fraud-example

            Here is the error message after executing

            gradle build clean

            ...

            ANSWER

            Answered 2020-Sep-24 at 12:07

            You need to add the guru.springframework:spring-cloud-contract-oa3:2.1.2.0 dependency to the plugin's classpath not to the project's classpath.

            Not like this:

            Source https://stackoverflow.com/questions/64044441

            QUESTION

            Spring Cloud Contract: Prefered way to import repeating parts in Contract DSL
            Asked 2020-Sep-07 at 06:30

            When writing a contract for an API i found myself repeating the same things over and over. For example regex validations for complex json object need to be copy pasted. Thats tedious and not very DRY.

            I'm using Kotlin DSL and Maven

            I tried to extract the common parts in another file to reuse it. (Kotlin extension functions ftw.)

            After trying multiple things to reuse that file I gave up.

            The common parts should be as close to the actual contracts as possible. I don't want to export them in another project, and build them seperat, as they are an vital part of the contracts.

            I tried it the following ways:

            1. just put the file in the same directory and importing the functions, hoping it would be resolved as it would in java - did not work at all (my expectations were low, was worth a shot)
            2. putting it in another maven module, and add that as dependency to the spring-cloud-contract-maven-plugin. that worked, as long as the dependant module was built and installed in the local maven repo. if no built version was available maven could not resolve it.
            3. experimenting with kotlin script @file:Import() and @file:DependOn to tackle my issue, no luck.

            Is there another way, that I missed? Is there a prefered way doing this? This must be a common issue, right?

            ...

            ANSWER

            Answered 2020-Sep-07 at 06:30

            QUESTION

            RESTful service contracts for protobuf definitions
            Asked 2020-Aug-29 at 18:18

            Design Overview

            • Request and response objects are modelled in protobuf.
            • Classes are generated in Python and Java using protoc.
            • Users create request objects in Python and send it to RESTful Java Spring Boot microservices.
            • A JavaScript React web application and Node server also invoke the RESTful endpoints.
            • Requests and responses are serialized to Json.
            • 1+ Java microservices may use the same request/response objects. eg. an aggregator/API gateway microservice will pass on the request to the actual microservice, providing the relevant service.

            Question

            Protobuf enforces some level of type checking, and a kind of contract, for request/response objects. However, how do I develop, maintain and enforce RESTful contracts (HTTP verb + path + request + response)?

            Is this the way to go?

            Develop contracts in Spring Cloud Contract and auto-generate integration contract tests.

            ...

            ANSWER

            Answered 2020-Jun-26 at 08:42

            You can check out a sample that uses protobuffers with spring cloud contract on the producer side here https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/master/producer_proto and on the consumer side here https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/master/consumer_proto

            The very idea is to treat the content as binary. Let's say that I stored the request and response in a binary format in a .bin file. Then I can create the following contract

            Source https://stackoverflow.com/questions/62590619

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install spring-cloud-contract

            In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. The following files can be found in the Spring Cloud Build project. Go to File → Settings → Editor → Code style. There click on the icon next to the Scheme section. There, click on the Import Scheme value and pick the Intellij IDEA code style XML option. Import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml file. Go to File → Settings → Editor → Inspections. There click on the icon next to the Profile section. There, click on the Import Profile and import the spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml file. To have Intellij work with Checkstyle, you have to install the Checkstyle plugin. It’s advisable to also install the Assertions2Assertj to automatically convert the JUnit assertions.
            Default Checkstyle rules
            File header setup
            Default suppression rules
            Project defaults for Intellij that apply most of Checkstyle rules
            Project style conventions for Intellij that apply most of Checkstyle rules
            checkstyle.header.file - please point it to the Spring Cloud Build’s, spring-cloud-build-tools/src/main/resources/checkstyle-header.txt file either in your cloned repo or via the https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt URL.
            checkstyle.suppressions.file - default suppressions. Please point it to the Spring Cloud Build’s, spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml file either in your cloned repo or via the https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml URL.
            checkstyle.additional.suppressions.file - this variable corresponds to suppressions in your local project. E.g. you’re working on spring-cloud-contract. Then point to the project-root/src/checkstyle/checkstyle-suppressions.xml folder. Example for spring-cloud-contract would be: /home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml.

            Support

            Spring Cloud is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want to contribute even something trivial please do not hesitate, but follow the guidelines below.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/spring-cloud/spring-cloud-contract.git

          • CLI

            gh repo clone spring-cloud/spring-cloud-contract

          • sshUrl

            git@github.com:spring-cloud/spring-cloud-contract.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link