16 Mayıs 2023 Salı

WireMock @WireMockTest Anotasyonu

Giriş
Açıklaması şöyle
httpPort: To indicate on which port we will be able to make HTTP calls.
httpsEnabled and httpsPort:. To indicate that we want to make HTTPS calls and in which port.
proxyMode. To emulate a domain name other than localhost. In this case and using HTTPClient we must use the useSystemProperties method when creating the client.
Örnek
Şöyle yaparız
@Log4j2
@WireMockTest(httpsEnabled = true, httpsPort = 9090, proxyMode = true)
public class WiremockBasicTest {
  String BEARER_TOKEN = "Bearer 77d9b8f0-fafe-3778-addf-2755bdc53c88";
  String JSON_CONTENT = "{\"hellow\":\"world\"}";

  @Test
  public void doGetAndGetResponse_proxyMode() throws Exception{
    stubFor(get("/sample").withHeader(HttpHeaders.AUTHORIZATION, WireMock.equalTo(BEARER_TOKEN))
      .withHost(WireMock.equalTo("mydomain.com"))
      .willReturn(aResponse().withBody(JSON_CONTENT).withStatus(200)));
    ...
  }
}

Hiç yorum yok:

Yorum Gönder