@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"));
  }
Exemplo n.º 2
0
  @Test
  public void headerMatchingIsCaseInsensitive() {

    LoggedRequest loggedRequest =
        createFrom(
            aRequest(context)
                .withUrl("/for/logging")
                .withMethod(POST)
                .withBody("Actual Content")
                .withHeader("Content-Type", "text/plain")
                .withHeader("ACCEPT", "application/json")
                .build());

    assertTrue(loggedRequest.containsHeader("content-type"));
    assertNotNull(loggedRequest.getHeader("content-type"));
    assertTrue(loggedRequest.containsHeader("CONTENT-TYPE"));
    assertNotNull(loggedRequest.getHeader("CONTENT-TYPE"));
    assertTrue(loggedRequest.containsHeader("Accept"));
    assertNotNull(loggedRequest.getHeader("Accept"));
  }