private void mockEmitMessages() {
   WireMock.stubFor(
       WireMock.post(WireMock.urlMatching(MOCKED_COLLECTION))
           .willReturn(
               WireMock.aResponse()
                   .withStatus(200)
                   .withHeader("Content-Type", "text/html")
                   .withBody("")));
 }
  @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"));
  }
  @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"));
  }
  @Bean
  @Primary
  public WireMockServer wireMockServer() {
    WireMockServer wireMockServer =
        new WireMockServer(
            wireMockConfig()
                .port(MOCK_SERVER_PORT)); // No-args constructor will start on port 8080, no HTTPS
    wireMockServer.start();
    WireMock.configureFor(MOCK_SERVER_PORT);

    return wireMockServer;
  }
  @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"));
  }
  @Test
  public void returnsAllUnmatchedRequests() {
    stubFor(
        get(urlEqualTo("/mypath"))
            .withHeader("My-Header", equalTo("matched"))
            .willReturn(aResponse().withStatus(200)));

    testClient.get("/unmatched/path");

    List<LoggedRequest> unmatched = WireMock.findUnmatchedRequests();

    assertThat(unmatched.size(), is(1));
    assertThat(unmatched.get(0).getUrl(), is("/unmatched/path"));
  }
 @Test
 public void testDeleteTokeninfoServerTimeout() throws Exception {
   try {
     WireMock.addRequestProcessingDelay(2100);
     getRestTemplate()
         .exchange(
             delete(URI.create(getRawSyncBaseUri() + "/clients/animals/1"))
                 .header(AUTHORIZATION, SERVER_ERROR_ACCESS_TOKEN)
                 .build(),
             Void.class);
     failBecauseExceptionWasNotThrown(HttpServerErrorException.class);
   } catch (HttpServerErrorException e) {
     assertThat(e.getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR);
   }
 }