Spring Cloud Contract

repository·main·Indexed 20 days ago

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

Provides support for consumer-driven contracts and service schemas in Spring applications to test and assert HTTP and message-based interactions. Includes documentation on the Spring Cloud Contract Verifier, Stub Runner configuration, Groovy DSL customization, and pluggable architecture for custom contract converters, test generators, and stub generators. Note: This project is no longer actively maintained and has transitioned to Stubborn.sh.

Tokens
72.4K
Snippets
199
Records
298
Agent score
72%

What's inside Spring Cloud Contract

  1. Overview of Spring Cloud Contract Specification

    main

    The spring-cloud-contract-spec module defines the contract formats used by Spring Cloud Contract. It provides support for writing contracts in two different languages:

    • Groovy: Using a Groovy-based Domain Specific Language (DSL).
    • Java: Using a Java-based DSL.

    These specifications allow developers to define the expected behavior of a service (the producer) in a language-agnostic way, which can then be used to generate tests for both the producer and its consumers.

  2. Overview of Spring Cloud Contract Maven Plugin

    main

    The Spring Cloud Contract Maven Plugin is part of the Spring Cloud Contract Verifier toolset, designed to enable Consumer Driven Contract (CDC) development for JVM-based applications. It facilitates moving Test-Driven Development (TDD) to the architectural level by managing two primary testing flows:

    1. Client Tests (Consumer side): Uses stub mappings generated from contracts to allow WireMock to simulate the server during integration testing.
    2. Server Tests (Producer side): Uses acceptance tests generated from contracts to verify that the server-side API implementation remains compliant with the defined contracts.

    Key capabilities include:

    • Generating tests automatically from provided contracts.
    • Running stubs directly from the generated stubs.
  3. Overview of Spring Cloud Contract

    main

    Spring Cloud Contract provides support for consumer-driven contracts and service schemas in Spring applications. It is designed to provide confidence when deploying new features in distributed systems by ensuring producers and consumers adhere to agreed-upon interactions.

    Key capabilities include:

    • Writing tests for both HTTP and message-based interactions.
    • Publishing contracts as assets.
    • Asserting that contracts are maintained by both producers and consumers.
  4. What is Spring Cloud Contract?

    main

    Spring Cloud Contract is a framework designed to move Test-Driven Development (TDD) to the level of software architecture by enabling consumer-driven and producer-driven contract testing. It provides a way to ensure that the stubs used by clients (consumers) accurately reflect the actual behavior of the server-side implementation (producers).

    Key Purposes

    • Stub Accuracy: Ensures HTTP and messaging stubs match the actual server-side implementation.
    • ATDD Promotion: Promotes Acceptance Test-Driven Development and microservices architectural styles.
    • Contract Visibility: Provides a mechanism to publish contract changes that are immediately visible to both consumer and producer.
    • Boilerplate Generation: Automatically generates boilerplate test code for the server side.

    Core Concepts

    • Contracts: An agreement defining how API or message communication should look (e.g., specific URLs, HTTP methods, request bodies, and expected responses).
    • Stubs: Mocked representations of services. Spring Cloud Contract integrates with Wiremock by default to serve as the HTTP server stub.
    • Trust Model: Contracts should always come from a trusted source. The framework ensures that the stubs you use were created by the service you are calling and have been tested against the producer's side.
  5. Key features of Spring Cloud Contract

    main

    Spring Cloud Contract is a Consumer Driven Contract (CDC) tooling suite designed for polyglot environments. Its core value propositions include:

    • Messaging Support: Capability to perform CDC with messaging systems.
    • Statically Typed DSL: Provides a clear and easy-to-use DSL for defining contracts.
    • JSON-to-Contract Workflow: You can copy-paste existing JSON files directly into a contract and edit only the necessary elements.
    • Automated Test Generation: Automatically generates tests based on the defined contracts.
    • Stub Runner: Automatically downloads stubs at runtime from artifact repositories like Nexus or Artifactory.
    • Spring Cloud Integration: Seamless integration that eliminates the need for a discovery service during integration tests.
    • Polyglot Extensibility: Support for any language or framework can be added via Docker.
  6. Use Stub Runner Boot Application

    main

    Spring Cloud Contract Stub Runner Boot is a Spring Boot application that provides REST endpoints to trigger messaging labels and access WireMock servers.

    Note on Availability: As of version 4.1.6, executable JARs are not released via the standard artifact repository. The preferred method of use is via the Docker Stub Runner Boot image. You can also build the application from the source code available in the project repository.

    Security Warning: The application is not secured by design and is intended strictly as a testing utility. It should never be used in production environments. Ensure only trusted clients have access to the server.

  7. What is Spring Cloud Contract Stub Runner

    main
    Spring Cloud Contract Stub Runner is a tool designed to solve the problem of manually transferring generated WireMock JSON stubs (for HTTP) or messaging stubs from the server side to the client side. Instead of manually copying JSON files and configuring client-side messaging environments, Stub Runner automatically downloads and runs the necessary stubs for you, facilitating easier integration testing for clients.