Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workshop - Mocks as Code. Modeling services in ...

Workshop - Mocks as Code. Modeling services in Config Management integration tests

When managing service configurations at scale, we often need to automate testing of these configurations. In software integration testing, we can use Testcontainers - a popular framework for Docker and other container engines. For public cloud environments, there is LocalStack. And for API service providers, we have WireMock. Can we use the same toolchain for configuration management? If you use modern Infrastructure-as-Code tools like Pulumi, yes!

In this edition, we will use Java or Kotlin for EVERYTHING, from the application itself and all the way up to Infrastructure as Code definitions and tests.

In this workshop, we will go through the following topics:
1. Containerizing Spring app development
2. Integration testing with Testcontainers and LocalStack
3. Mocking APIs with WireMock
4. Infrastructure as Code (IaC) with Pulumi and Pulumi for Java
5. Testing IaC locally, with all tools above combined

See https://github.com/oleg-nenashev/mocks-as-code-demo for the demo repository we will be using in this workshop. It also contains all the links to the used tools and additional learning materials.

Copyright Notice: Gradle, Inc. Gradle®, Develocity®, Build Scan®, and the Gradlephant logo are registered trademarks of Gradle, Inc. "Gradle" means "Gradle Build Tool" and does not reference Gradle, Inc. and/or its subsidiaries

Avatar for Oleg Nenashev

Oleg Nenashev PRO

May 14, 2024
Tweet

Resources

Demo Repo

https://github.com/oleg-nenashev/mocks-as-code-demo

Repository with all the demos

More Decks by Oleg Nenashev

Other Decks in Programming

Transcript

  1. NOTE: • This presentation was modified on 08 Oct 2025,

    to exclude trademarks and IP of Gradle Inc, as per request from the company • The content is mostly retained, except for the observability section • Gradle®, Develocity®, Build Scan®, and the Gradlephant logo are registered trademarks of Gradle, Inc. "Gradle" means "Gradle Build Tool" and does not reference Gradle, Inc. and/or its subsidiaries.
  2. > whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Community

    builder Developer Tools Hacker #RussiansAgainstPutin #StandWithUkraine
  3. 5 Staging & QA Tests Build Integration tests Build Tests

    Gaining confidence in you software “Shift Left” with modern tools
  4. 7 Java All the Way Down Up Application Unit Tests

    Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way
  5. Today 8 1. Containerizing Spring App Development 2. Integration testing

    with Testcontainers and LocalStack 3. Mocking APIs with WireMock 4. Infrastructure as Code (IaC) with Pulumi 5. Testing IaC locally 6. Advanced Troubleshooting Localstack
  6. Workshop Prerequisites • Internet :( • Java 17 & your

    favorite IDE • Testcontainers-compatible Docker environment ◦ Tested on: Docker Desktop ◦ You can use: Podman, Colima, Rancher Desktop (list) ◦ OR: Testcontainers Cloud • Pulumi CLI + registration ◦ Guide: www.pulumi.com/docs/install/ 10
  7. Credits 13 • Siva Prasad Reddy and Oleg Shelajev, Docker

    • The demos are based on: ◦ github.com/testcontainers/tc-guide-testing-aws-service-integrations-using-loca lstack ◦ github.com/testcontainers-community/testcontainers-wiremock-demo
  8. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides
  9. LocalStack • Local AWS Services emulation OR mocking • “awslocal”

    CLI utility • SDKs for languages and test frameworks 26 docs.localstack.cloud/
  10. Some of Them 28 • Emulated: S3, SQS, … •

    Mocked: EC2 (in the FOSS lib) • Thoughts & Prayers: AWS GreenShift ;) • …
  11. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides
  12. wiremock.org/docs/stubbing IF (request_url) THEN (response) * * it gets MUCH

    more complex WireMock Config JSON: Client library response request Client App Mock API Server HTTP/2 API Mocking 101
  13. API Mocking Tools Main implementation in Java Native lib, Docker

    images and Testcontainers modules Support for GraalVM Rich Ecosystem Sandbox CNCF Project Golang / Microservice arch Docker image, Testcontainers module, All-in K8s Charts Less Rich Ecosystem
  14. WireMock Ecosystem / Java • Java • Kotlin • Scala

    • Groovy • Clojure • (?)Android 37 • JUnit 4/5 • Testcontainers • Sprint Boot • Spring Cloud Contract • Quarkus • Maven / Gradle Build Tool • Spock • Pact
  15. 42

  16. Enter -as-Code Tools! • Infrastructure as Real Code • SDKs

    for programming languages • Standard IDEs • Standard Developer Tools • Extensibility via libraries 45
  17. 51 Java All the Way Down Up Application Unit Tests

    Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way
  18. Beware Pulumi for AWS Native • AWS Native configuration is

    not applied for endpoints • APIs are slightly different in the package 63
  19. 64

  20. 65

  21. 67

  22. 68 Java All the Way Down Up Application Unit Tests

    Build Definition and Pipelines Integration Tests Infrastructure-as-Code Deployment Pipelines Deployment Tests Production Health Checks Java the stack up all the way
  23. What I’m looking forward to? • Feedback from Java developers

    • Is Infra-as-Code with Java interesting to you? • Do you want Pulumi-LocalStack for Java productization? • Any other feedback on dev tools :)