Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.36 KB

client-jersey-wiremock-testing.md

File metadata and controls

56 lines (40 loc) · 1.36 KB

SDA Commons Client Jersey WireMock Testing

javadoc

Testing dependencies for WireMock test framework.

Extensions

This module provides a Junit 5 extension to set up Wiremock for your tests.

WireMockExtension

Useful for setting up Wiremock for each one of your tests.

Example:

class WireMockExtensionTest {

  @RegisterExtension
  WireMockExtension wire = new WireMockExtension();

  @BeforeEach
  void before() {
    wire.stubFor(
        get("/api/cars") // NOSONAR
            .withHeader("Accept", notMatching("gzip"))
            .willReturn(ok().withHeader("Content-type", "application/json").withBody("[]")));
  }

  // Tests
}

WireMockClassExtension

Useful for setting up Wiremock once for your test class.

Example:

class WireMockClassExtensionTest {

  @RegisterExtension
  public static WireMockClassExtension wire =
      new WireMockClassExtension();

  @BeforeAll
  public static void beforeAll() {
    wire.stubFor(
        get("/api/cars") // NOSONAR
            .withHeader("Accept", notMatching("gzip"))
            .willReturn(ok().withHeader("Content-type", "application/json").withBody("[]")));
  }
  
  // Tests
}