Skip to content

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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
}