Search in sources :

Example 31 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class ScenarioAcceptanceTest method mappingInScenarioIndependentOfCurrentState.

@Test
public void mappingInScenarioIndependentOfCurrentState() {
    givenThat(get(urlEqualTo("/state/independent/resource")).willReturn(aResponse().withBody("Some content")).inScenario("StateIndependent"));
    givenThat(put(urlEqualTo("/state/modifying/resource")).willReturn(aResponse().withStatus(HTTP_OK)).inScenario("StateIndependent").willSetStateTo("BodyModified"));
    WireMockResponse response = testClient.get("/state/independent/resource");
    assertThat(response.statusCode(), is(HTTP_OK));
    assertThat(response.content(), is("Some content"));
    testClient.put("/state/modifying/resource");
    response = testClient.get("/state/independent/resource");
    assertThat(response.statusCode(), is(HTTP_OK));
    assertThat(response.content(), is("Some content"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 32 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class StandaloneAcceptanceTest method doesNotServeFileFromFilesDirWhenNotGET.

@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(), // Default servlet returns 405 if PUT is forwarded to it
    is(404));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 33 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class StandaloneAcceptanceTest method servesFileFromSpecifiedRecordingsPath.

@Test
public void servesFileFromSpecifiedRecordingsPath() {
    String differentRoot = FILE_SOURCE_ROOT + separator + "differentRoot";
    writeFile(differentRoot + separator + underFiles("test-1.xml"), "<content>Blah</content>");
    startRunner("--root-dir", differentRoot);
    WireMockResponse response = testClient.get("/test-1.xml");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("<content>Blah</content>"));
    assertThat(response.firstHeader("Content-Type"), is("application/xml"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 34 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class StandaloneAcceptanceTest method proxiesToHostSpecifiedOnCommandLine.

@Test
public void proxiesToHostSpecifiedOnCommandLine() throws Exception {
    WireMock otherServerClient = startOtherServerAndClient();
    otherServerClient.register(get(urlEqualTo("/proxy/ok?working=yes")).willReturn(aResponse().withStatus(HTTP_OK)));
    startRunner("--proxy-all", "http://localhost:" + otherServer.port());
    WireMockResponse response = testClient.get("/proxy/ok?working=yes");
    assertThat(response.statusCode(), is(HTTP_OK));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMock(com.github.tomakehurst.wiremock.client.WireMock) Test(org.junit.jupiter.api.Test)

Example 35 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class StandaloneAcceptanceTest method servesFileAsJsonWhenNoFileExtension.

@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"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Aggregations

WireMockResponse (com.github.tomakehurst.wiremock.testsupport.WireMockResponse)172 Test (org.junit.jupiter.api.Test)168 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Errors (com.github.tomakehurst.wiremock.common.Errors)11 WireMockTestClient (com.github.tomakehurst.wiremock.testsupport.WireMockTestClient)9 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)7 UUID (java.util.UUID)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Stopwatch (com.google.common.base.Stopwatch)3 ByteArrayEntity (org.apache.hc.core5.http.io.entity.ByteArrayEntity)3 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)3 ConsoleNotifier (com.github.tomakehurst.wiremock.common.ConsoleNotifier)2 Request (com.github.tomakehurst.wiremock.http.Request)2 JsonVerifiable (com.toomuchcoding.jsonassert.JsonVerifiable)2 IOException (java.io.IOException)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 FileSource (com.github.tomakehurst.wiremock.common.FileSource)1 SingleRootFileSource (com.github.tomakehurst.wiremock.common.SingleRootFileSource)1 Admin (com.github.tomakehurst.wiremock.core.Admin)1