Ejemplo n.º 1
0
  @Test
  public void nearMisses() {
    stubFor(
        get(urlEqualTo("/mypath"))
            .withHeader("My-Header", equalTo("matched"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        get(urlEqualTo("/otherpath"))
            .withHeader("My-Header", equalTo("otherheaderval"))
            .willReturn(aResponse().withStatus(200)));
    stubFor(
        get(urlEqualTo("/yet/another/path"))
            .withHeader("X-Alt-Header", equalTo("matchonthis"))
            .willReturn(aResponse().withStatus(200)));

    testClient.get("/otherpath", withHeader("My-Header", "notmatched"));

    List<NearMiss> nearMisses = WireMock.findNearMissesForAllUnmatched();

    assertThat(nearMisses.get(0).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(0).getStubMapping().getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(1).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(1).getStubMapping().getRequest().getUrl(), is("/mypath"));
    assertThat(nearMisses.get(2).getRequest().getUrl(), is("/otherpath"));
    assertThat(nearMisses.get(2).getStubMapping().getRequest().getUrl(), is("/yet/another/path"));
  }