Package com.github.tomakehurst.wiremock.testsupport

Examples of com.github.tomakehurst.wiremock.testsupport.WireMockResponse


  @Test
  public void servesFileAsJsonWhenNoFileExtension() {
    writeFileToFilesDir("json/12345", "{ \"key\": \"value\" }");
    startRunner();
    WireMockResponse response = testClient.get("/json/12345");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("{ \"key\": \"value\" }"));
    assertThat(response.firstHeader("Content-Type"), is("application/json"));
  }
View Full Code Here


 
  @Test
  public void shouldNotSend302WhenPathIsDirAndTrailingSlashNotPresent() {
      writeFileToFilesDir("json/wire & mock directory/index.json", "{ \"key\": \"index page value\" }");
      startRunner();
        WireMockResponse response = testClient.get("/json/wire%20&%20mock%20directory");
        assertThat(response.statusCode(), is(200));
        assertThat(response.content(), is("{ \"key\": \"index page value\" }"));
  }
View Full Code Here

 
  @Test
  public void servesJsonIndexFileWhenTrailingSlashPresent() {
    writeFileToFilesDir("json/23456/index.json", "{ \"key\": \"new value\" }");
    startRunner();
    WireMockResponse response = testClient.get("/json/23456/");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("{ \"key\": \"new value\" }"));
    assertThat(response.firstHeader("Content-Type"), is("application/json"));
  }
View Full Code Here

 
  @Test
  public void servesXmlIndexFileWhenTrailingSlashPresent() {
    writeFileToFilesDir("json/34567/index.xml", "<blob>BLAB</blob>");
    startRunner();
    WireMockResponse response = testClient.get("/json/34567/");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("<blob>BLAB</blob>"));
    assertThat(response.firstHeader("Content-Type"), is("application/xml"));
  }
View Full Code Here

 
  @Test
  public void doesNotServeFileFromFilesDirWhenNotGET() {
    writeFileToFilesDir("json/should-not-see-this.json", "{}");
    startRunner();
    WireMockResponse response = testClient.put("/json/should-not-see-this.json");
    assertThat(response.statusCode(), is(404)); //Default servlet returns 405 if PUT is forwarded to it
  }
View Full Code Here

  public void proxiesToHostSpecifiedOnCommandLine() {
    WireMock otherServerClient = start8084ServerAndCreateClient();
    otherServerClient.register(get(urlEqualTo("/proxy/ok?working=yes")).willReturn(aResponse().withStatus(HTTP_OK)));
    startRunner("--proxy-all", "http://localhost:8084");
   
    WireMockResponse response = testClient.get("/proxy/ok?working=yes");
    assertThat(response.statusCode(), is(HTTP_OK));
  }
View Full Code Here

    }

    @Test
    public void savesMappingsToMappingsDirectory() {
        // Check the mapping we're about to add isn't already there
        WireMockResponse response = testClient.get("/some/url");
        assertThat(response.statusCode(), is(404));

        // Add a mapping and save it
        stubFor(get(urlEqualTo("/some/url"))
                .willReturn(aResponse().withBody("Response to /some/url")));
        saveAllMappings();

        // Reset, clearing in-memory mappings
        resetToDefault();

        // Check the mapping now exists
        response = testClient.get("/some/url");
        assertThat(response.statusCode(), is(200));
        assertThat(response.content(), is("Response to /some/url"));
    }
View Full Code Here

    }

    @Test
    public void doesNotDuplicateMappingsAlreadyPersistedToFileSystem() {
        // Check the mapping we're about to add isn't already there
        WireMockResponse response = testClient.get("/some/url");
        assertThat(response.statusCode(), is(404));

        // Add a mapping and save it
        stubFor(get(urlEqualTo("/some/url"))
                .willReturn(aResponse().withBody("Response to /some/url")));
        saveAllMappings();
View Full Code Here

    }

    @Test
    public void doesNotDuplicateMappingsAlreadyPersistedAfterReset() {
        // Check the mapping we're about to add isn't already there
        WireMockResponse response = testClient.get("/some/url");
        assertThat(response.statusCode(), is(404));

        // Add a mapping and save it
        stubFor(get(urlEqualTo("/some/url"))
                .willReturn(aResponse().withBody("Response to /some/url")));
        saveAllMappings();
View Full Code Here

                .withRequestBody(equalTo("BlahBlahBlah"))
                .willReturn(aResponse()
                .withStatus(HTTP_OK)
                .withBodyFile("plain-example.txt")));
       
        WireMockResponse response = testClient.putWithBody("/match/this/body/too", "Blah12345", "text/plain");
        assertThat(response.statusCode(), is(HTTP_NOT_FOUND));
       
        response = testClient.putWithBody("/match/this/body/too", "BlahBlahBlah", "text/plain");
        assertThat(response.statusCode(), is(HTTP_OK));
    }
View Full Code Here

TOP

Related Classes of com.github.tomakehurst.wiremock.testsupport.WireMockResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.