Search in sources :

Example 96 with WireMockResponse

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

the class RequestFilterAcceptanceTest method filterCanStopWithResponse.

@Test
public void filterCanStopWithResponse() {
    initialise(new StubAuthenticatingFilter());
    wm.stubFor(get(url).willReturn(ok()));
    WireMockResponse good = client.get(url, withHeader("Authorization", "Token 123"));
    assertThat(good.statusCode(), is(200));
    WireMockResponse bad = client.get(url);
    assertThat(bad.statusCode(), is(401));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 97 with WireMockResponse

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

the class RequestFilterAcceptanceTest method filterCanContinueWithModifiedRequest.

@Test
public void filterCanContinueWithModifiedRequest() {
    initialise(new RequestHeaderModifyingFilter());
    wm.stubFor(get(url).withHeader("X-Modify-Me", equalTo("modified")).willReturn(ok()));
    WireMockResponse response = client.get(url, withHeader("X-Modify-Me", "original"));
    assertThat(response.statusCode(), is(200));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 98 with WireMockResponse

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

the class RequestFilterAcceptanceTest method filterCanBeAppliedToStubsAndAdmin.

@Test
public void filterCanBeAppliedToStubsAndAdmin() {
    initialise(new BothAuthenticatingFilter());
    wm.stubFor(get(url).willReturn(ok()));
    String adminUrl = "/__admin/mappings";
    WireMockResponse stub = client.get(url);
    assertThat(stub.statusCode(), is(401));
    WireMockResponse admin = client.get(adminUrl);
    assertThat(admin.statusCode(), is(401));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 99 with WireMockResponse

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

the class RequestFilterAcceptanceTest method filtersAreChained.

@Test
public void filtersAreChained() {
    initialise(new RequestHeaderAppendingFilter("A"), new RequestHeaderAppendingFilter("B"), new RequestHeaderAppendingFilter("C"));
    wm.stubFor(get(url).withHeader("X-Modify-Me", matching("_[ABC]{3}")).willReturn(ok()));
    WireMockResponse response = client.get(url, withHeader("X-Modify-Me", "_"));
    assertThat(response.statusCode(), is(200));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 100 with WireMockResponse

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

the class ResponseDefinitionTransformerAcceptanceTest method doesNotApplyNonGlobalExtensionsWhenNotExplicitlySpecfiedByStub.

@Test
public void doesNotApplyNonGlobalExtensionsWhenNotExplicitlySpecfiedByStub() {
    wm = new WireMockServer(wireMockConfig().dynamicPort().extensions(new ExampleTransformer(), new NonGlobalTransformer()));
    wm.start();
    client = new WireMockTestClient(wm.port());
    createStub("/non-global-transform");
    WireMockResponse response = client.get("/non-global-transform");
    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)

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