kurbaniec / swe-dependencies

Pact Examples.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kacper Urbaniec | SWE | 11.11.2022

Assignment 3: Dependencies

๐Ÿ—๏ธ Architecture

  • provider.customer | CustomerService

    Spring Boot service available @ http://localhost:8080
    Provides a list of customers via a REST API. The customer has the typical information like name, address, date of birth, email address, status, and more. Besides the basic information, the customer has a list of financial products. Every product has a name, balance, product code, and interest rate, among others.

  • consumer.info | InfoService

    Spring Boot service available @ http://localhost:8090
    Provides a modified list of customer via REST API. Returns a list of all customers with name, email, and status.

  • consumer.aggregator | AggregatorService

    Node service available @ http://localhost:9000
    Provides a modified list of customer via REST API. Returns a list of all customers with names and an aggregated balance (sum of all product balances).

๐Ÿค Test & Verify Pacts

  1. Run tests & generate pact for InfoService consumer

    # On Unix: chmod +x ./consumer.info/gradlew
    ./consumer.info/gradlew -p "consumer.info" test 
  2. Run tests & generate pact for AggregatorService consumer

    npm --prefix ./consumer.aggregator/ install
    npm --prefix ./consumer.aggregator/ run test 
  3. Verfiy pacts for CustomerService provider

    # On Unix: chmod +x ./provider.customer/gradlew
    ./provider.customer/gradlew -p "provider.customer" test 

For example, if one were to remove the balance field from the API CustomerService, the contract check would fail and output the following error messages.

image-20221111204320248

image-20221111204446501

Pact & other consumer-driven testing frameworks help detect breaking service modifications to prevent such client defects.

๐Ÿš€ Run

  1. CustomerService

    ./provider.customer/gradlew -p "provider.customer" bootRun 

    API

    • /customers - Query all customers

      curl http://localhost:8080/customers
    • /customer/{customer-email} - Query specific customer

      curl http://localhost:8080/customer/customer.c@gmail.com
  2. InfoService

    Requires running CustomerService.

    ./consumer.info/gradlew -p "consumer.info" bootRun 

    API

    • /customers - Query all customer info

      curl http://localhost:8090/customers
  3. AggregatorService

    Requires running CustomerService.

    npm --prefix ./consumer.aggregator/ run build 
    npm --prefix ./consumer.aggregator/ run start 

    API

    • /customers - Query all customers with aggregated balances

      curl http://localhost:9000/customers

Additionally, a postman collection can be found in the test.postman folder to manually interact with the services.

Acknowledgments

About

Pact Examples.


Languages

Language:Kotlin 76.6%Language:TypeScript 22.9%Language:Shell 0.5%