Ejemplo n.º 1
0
  @Test
  public void returnsStubMappingNearMissesForARequest() {
    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)));

    List<NearMiss> nearMisses =
        WireMock.findNearMissesFor(
            LoggedRequest.createFrom(
                mockRequest().url("/otherpath").header("My-Header", "notmatched")));

    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"));
  }
Ejemplo n.º 2
0
  @Test
  public void returnsRequestNearMissesForARequestPattern() {
    testClient.get("/actual11");
    testClient.get("/actual42");

    List<NearMiss> nearMisses =
        WireMock.findNearMissesFor(
            getRequestedFor(urlEqualTo("/actual4")).withRequestBody(containing("thing")));

    assertThat(nearMisses.size(), is(2));
    assertThat(nearMisses.get(0).getRequest().getUrl(), is("/actual42"));
    assertThat(nearMisses.get(1).getRequest().getUrl(), is("/actual11"));
  }