Search in sources :

Example 21 with WireMockTestClient

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

the class DelayAndCustomMatcherAcceptanceTest method delayIsAddedWhenCustomResponseTransformerPresent.

@Test
public void delayIsAddedWhenCustomResponseTransformerPresent() {
    stubFor(get(urlEqualTo("/delay-this")).willReturn(aResponse().withStatus(200).withTransformers("response-body-changer").withUniformRandomDelay(500, 1000)));
    WireMockTestClient client = new WireMockTestClient(wireMockRule.getPort());
    Stopwatch stopwatch = Stopwatch.createStarted();
    WireMockResponse response = client.get("/delay-this");
    stopwatch.stop();
    assertThat(stopwatch.elapsed(MILLISECONDS), greaterThanOrEqualTo(500L));
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("Transformed body"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Stopwatch(com.google.common.base.Stopwatch) Test(org.junit.jupiter.api.Test)

Example 22 with WireMockTestClient

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

the class ClientAuthenticationAcceptanceTest method supportsCustomAuthenticator.

@Test
public void supportsCustomAuthenticator() {
    initialise(new Authenticator() {

        @Override
        public boolean authenticate(Request request) {
            return request.containsHeader("X-Magic-Header");
        }
    }, new ClientAuthenticator() {

        @Override
        public List<HttpHeader> generateAuthHeaders() {
            return singletonList(httpHeader("X-Magic-Header", "blah"));
        }
    });
    WireMockTestClient noAuthClient = new WireMockTestClient(server.port());
    assertThat(noAuthClient.get("/__admin/mappings").statusCode(), is(401));
    assertThat(noAuthClient.get("/__admin/mappings", withHeader("X-Magic-Header", "anything")).statusCode(), is(200));
    // Throws an exception on a non 2xx response
    goodClient.getServeEvents();
}
Also used : WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Request(com.github.tomakehurst.wiremock.http.Request) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 23 with WireMockTestClient

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

the class ClientAuthenticationAcceptanceTest method canRequireHttpsOnAdminApi.

@Test
public void canRequireHttpsOnAdminApi() {
    server = new WireMockServer(wireMockConfig().dynamicPort().dynamicHttpsPort().basicAdminAuthenticator("user", "password").requireHttpsForAdminApi());
    server.start();
    WireMockTestClient client = new WireMockTestClient(server.port());
    String authHeader = new BasicCredentials("user", "password").asAuthorizationHeaderValue();
    WireMockResponse response = client.get("/__admin/requests", withHeader(AUTHORIZATION, authHeader));
    assertThat(response.statusCode(), is(403));
    assertThat(response.content(), containsString("HTTPS is required for accessing the admin API"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) Matchers.containsString(org.hamcrest.Matchers.containsString) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Test(org.junit.jupiter.api.Test)

Example 24 with WireMockTestClient

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

the class WireMockJUnitRuleTest method assertCanRegisterStubAndFetchOnCorrectPort.

public static void assertCanRegisterStubAndFetchOnCorrectPort(int port) {
    givenThat(get(urlEqualTo("/rule/test")).willReturn(aResponse().withBody("Rule test body")));
    WireMockTestClient testClient = new WireMockTestClient(port);
    assertThat(testClient.get("/rule/test").content(), is("Rule test body"));
}
Also used : WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient)

Example 25 with WireMockTestClient

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

the class WireMockServerTests method supportsRecordingProgrammaticallyWithoutHeaderMatching.

// https://github.com/tomakehurst/wiremock/issues/193
@Test
public void supportsRecordingProgrammaticallyWithoutHeaderMatching() {
    WireMockServer wireMockServer = new WireMockServer(DYNAMIC_PORT, new SingleRootFileSource(tempDir), false, new ProxySettings("proxy.company.com", DYNAMIC_PORT));
    wireMockServer.start();
    wireMockServer.enableRecordMappings(new SingleRootFileSource(tempDir + "/mappings"), new SingleRootFileSource(tempDir + "/__files"));
    wireMockServer.stubFor(get(urlEqualTo("/something")).willReturn(aResponse().withStatus(200)));
    WireMockTestClient client = new WireMockTestClient(wireMockServer.port());
    assertThat(client.get("http://localhost:" + wireMockServer.port() + "/something").statusCode(), is(200));
}
Also used : WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) ProxySettings(com.github.tomakehurst.wiremock.common.ProxySettings) SingleRootFileSource(com.github.tomakehurst.wiremock.common.SingleRootFileSource) Test(org.junit.jupiter.api.Test)

Aggregations

WireMockTestClient (com.github.tomakehurst.wiremock.testsupport.WireMockTestClient)43 Test (org.junit.jupiter.api.Test)16 BeforeEach (org.junit.jupiter.api.BeforeEach)10 WireMockResponse (com.github.tomakehurst.wiremock.testsupport.WireMockResponse)9 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 SingleRootFileSource (com.github.tomakehurst.wiremock.common.SingleRootFileSource)2 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 FileSource (com.github.tomakehurst.wiremock.common.FileSource)1 ProxySettings (com.github.tomakehurst.wiremock.common.ProxySettings)1 Request (com.github.tomakehurst.wiremock.http.Request)1 X509KeyStore (com.github.tomakehurst.wiremock.http.ssl.X509KeyStore)1 WireMockServerRunner (com.github.tomakehurst.wiremock.standalone.WireMockServerRunner)1 Stopwatch (com.google.common.base.Stopwatch)1 Certificate (java.security.cert.Certificate)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1