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

Developing subatomic apps with Quarkus and Wire...

Developing subatomic apps with Quarkus and WireMock

Quarkus has a lot of capabilities for local development, including the recently released Dev Services that usually runs with Testcontainers under the hood. We can leverage Dev Services for providing great real-time API provider development experiences for Quarkus based service and client apps.

In this talk and live coding session I will show how to develop a REST API and gRPC 3-tier client-service-database app with help of WireMock, Quarkus and Testcontainers. We will go through live development and prototyping APIs, mocking data and API providers, and then also using WireMock as a proxy to inject some failures and chaos into the service.

Oleg Nenashev

December 10, 2023
Tweet

More Decks by Oleg Nenashev

Other Decks in Technology

Transcript

  1. > whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Developer

    tools hacker Community builder & DevRel consultant #RussiansAgainstPutin #StandWithUkraine
  2. WireMock Cloud by WireMock Inc. 4 • WireMock creator is

    a co-founder of the Inc. • WireMock Cloud - SaaS for end-to-end API mocking • Private beta: K8s Edition for managed / on-premises wiremock.io
  3. Outline • Intro to API integration testing and WireMock •

    Using WireMock and Quarkus • And examples! 5
  4. > whoami --quarkus • Jenkins on Quarkus experiments • Jenkinsfile

    Runner native exec with Quarkus • FaaScinator pet project (Stale) • Wishlist: WireMock + Quarkus image 6
  5. Docker image for OpenFaaS openfaas/of-watchdog AdoptOpenJDK JDK/JRE Service Wrapper GET

    / run function GET /help GET /usage GET /schema Config and schema (env vars, sys prop) User CLI app Quarkus github.com/oleg-nenashev/faascinator ¡Stale project!
  6. APIs are essential for Integration Testing 9 GROWTH IN WEB

    APIS SINCE 2005 Over 90% of developers use APIs. Skyrocket growth of APIs JANUARY 2006 JANUARY 2008 JANUARY 2010 JANUARY 2012 JANUARY 2014 JANUARY 2016 JANUARY 2018 MONTH The growth over time of the Programmable Web API API directory to more than 22,000 entries 22000 20000 18000 16000 14000 12000 10000 8000 6000 4000 2000 0 TOTAL API COUNT Programmable Web * Gartner Hype Cycle for APIs, 2022
  7. Quarkus is great for building REST APIs 11 • Built-in

    support • Many extensions • Developer experience https://code.quarkus.io/
  8. 13

  9. 15

  10. 16

  11. 19

  12. Integration testing? 24 • Multiple technology stacks and toolchains •

    Many teams involved • Sacred knowledge • [Almost] always too late
  13. 25 Build Unit tests Publish Reports Integration tests Publish Reports

    NOW “Shift Left” Fast integrations tests are critical
  14. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock) 4. Mocking at the code level 26 Slow Fast Accu- rate Nope
  15. 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) 4. Mocking at the code level 27 Slow Fast Nope Accu- rate
  16. 28 Staging & QA Tests Build Integration tests Build Tests

    Gaining confidence in you software “Shift Left”
  17. 29

  18. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock) 4. Mocking at the code level 30 Slow Fast Accu- rate Nope
  19. 31 WireMock 101 WireMock is a tool for building mock

    APIs Created in 2011 as a Java test library and CLI Available beyond Java/JVM, inc Python or Golang You can can: • Create stable development environments • Isolate yourself from flakey 3rd parties • Simulate APIs that don't exist yet wiremock.org
  20. 32 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
  21. WireMock & JVM Ecosystem - projects for… • Java •

    Kotlin • Scala • Groovy • Clojure • Android (in 2.x) 37 • JUnit 4/5 • Testcontainers • Sprint Boot • Spring Cloud Contract • Quarkus • (*)Micronaut • Maven/Gradle • Spock • Pact
  22. WireMock and Quarkus wishlist • WireMock official images on Quarkus

    • WireMock native packaging with Quarkus • Ext: Full configuration-as-code in WireMock, build-time configuration in Quarkus • Ext: Support for WireMock in the proxy mode • Ext: Testcontainers-based Dev Service: extensions and portability 49
  23. Wishlist - WireMock as a Proxy in Quarkus 50 Tests

    / Dev Real API Provider OR • Fault injection • Recording • Protocol Verification
  24. Takeaways 52 • Shift left your integration testing… as far

    as unit tests and developer environments • Reduce external dependencies, mock APIs • There are tools for that, including WireMock • WireMock and Quarkus co-exist well
  25. References My demo: TODO • Similar one in Spring Boot:

    https://github.com/shelajev/testcontainers-wiremock-demo WireMock extension for Quarkus: • https://docs.quarkiverse.io/quarkus-wiremock • https://github.com/gscaramuzzino/quarkus-wiremock-testing • https://quarkus.io/guides/getting-started-testing#quarkus-test-resource 54