Search in sources :

Example 46 with WireMockResponse

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

the class RequestFilterAcceptanceTest method filterCanBeAppliedToAdmin.

@Test
public void filterCanBeAppliedToAdmin() {
    initialise(new AdminAuthenticatingFilter());
    wm.stubFor(get(url).willReturn(ok()));
    String adminUrl = "/__admin/mappings";
    WireMockResponse good = client.get(adminUrl, withHeader("Authorization", "Token 123"));
    assertThat(good.statusCode(), is(200));
    WireMockResponse bad = client.get(adminUrl);
    assertThat(bad.statusCode(), is(401));
    // Stubs are unaffected
    WireMockResponse stub = client.get(url);
    assertThat(stub.statusCode(), is(200));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 47 with WireMockResponse

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

the class ResponseDefinitionTransformerAcceptanceTest method supportsSpecifiyingExtensionsByInstance.

@Test
public void supportsSpecifiyingExtensionsByInstance() {
    wm = new WireMockServer(wireMockConfig().dynamicPort().extensions(new ExampleTransformer(), new MultiTransformer2()));
    wm.start();
    client = new WireMockTestClient(wm.port());
    createStub("/to-instance-transform");
    WireMockResponse response = client.get("/to-instance-transform");
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("Expect this"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Test(org.junit.jupiter.api.Test)

Example 48 with WireMockResponse

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

the class ResponseDefinitionTransformerAcceptanceTest method supportsAccessingTheFilesFileSource.

@Test
public void supportsAccessingTheFilesFileSource() {
    startWithExtensions("com.github.tomakehurst.wiremock.ResponseDefinitionTransformerAcceptanceTest$FileAccessTransformer");
    createStub("/files-access-transform");
    WireMockResponse response = client.get("/files-access-transform");
    assertThat(response.content(), is("Some example test from a file"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 49 with WireMockResponse

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

the class ResponseDefinitionTransformerAcceptanceTest method supportsSpecifiyingExtensionsByClass.

@Test
public void supportsSpecifiyingExtensionsByClass() {
    wm = new WireMockServer(wireMockConfig().dynamicPort().extensions(ExampleTransformer.class, MultiTransformer1.class));
    wm.start();
    client = new WireMockTestClient(wm.port());
    createStub("/to-class-transform");
    WireMockResponse response = client.get("/to-class-transform");
    assertThat(response.statusCode(), is(201));
    assertThat(response.content(), is("Transformed body"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Test(org.junit.jupiter.api.Test)

Example 50 with WireMockResponse

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

the class ResponseDelayAcceptanceTest method responseWithByteDribbleAndFixedDelay.

@Test
public void responseWithByteDribbleAndFixedDelay() {
    byte[] body = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    int numberOfChunks = body.length / 2;
    int fixedDelay = 1000;
    int chunkedDuration = 1000;
    int totalDuration = fixedDelay + chunkedDuration;
    stubFor(get(urlEqualTo("/dribbleWithFixedDelay")).willReturn(aResponse().withStatus(200).withBody(body).withChunkedDribbleDelay(numberOfChunks, chunkedDuration).withFixedDelay(fixedDelay)));
    long start = System.currentTimeMillis();
    WireMockResponse response = testClient.get("/dribbleWithFixedDelay");
    long timeTaken = System.currentTimeMillis() - start;
    assertThat(response.statusCode(), is(200));
    assertThat(timeTaken, greaterThanOrEqualTo((long) totalDuration));
    assertThat(body, is(response.binaryContent()));
}
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