Search in sources :

Example 6 with WireMockResponse

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

the class AdminApiTest method stubMetadataIsAbsentWhenNoneSpecified.

@Test
@SuppressWarnings("unchecked")
public void stubMetadataIsAbsentWhenNoneSpecified() {
    UUID id = UUID.randomUUID();
    wireMockServer.stubFor(get("/without-metadata").withId(id));
    WireMockResponse response = testClient.get("/__admin/mappings/" + id);
    Map<String, ?> data = Json.read(response.content(), Map.class);
    assertThat(data, not(hasKey("metadata")));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 7 with WireMockResponse

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

the class AdminApiTest method updateGlobalSettingsViaPut.

@Test
public void updateGlobalSettingsViaPut() {
    WireMockResponse response = testClient.putWithBody("/__admin/settings", SETTINGS_JSON, "application/json");
    assertThat(response.statusCode(), is(200));
    assertThat(wireMockServer.getGlobalSettings().getSettings().getExtended().getInt("mySetting"), is(123));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 8 with WireMockResponse

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

the class AdminApiTest method getsAllServeEventsMatchingASpecificStub.

@Test
public void getsAllServeEventsMatchingASpecificStub() {
    wm.stubFor(get("/one").willReturn(ok()));
    StubMapping stub2 = wm.stubFor(get("/two").willReturn(ok()));
    testClient.get("/two");
    testClient.get("/one");
    testClient.get("/one");
    testClient.get("/two");
    WireMockResponse response = testClient.get("/__admin/requests?matchingStub=" + stub2.getId());
    assertThat(response.statusCode(), is(200));
    String json = response.content();
    assertThat(json, jsonPartEquals("requests[0].request.url", "/two"));
    assertThat(json, jsonPartEquals("requests[1].request.url", "/two"));
    assertThat(json, jsonPartMatches("requests", hasSize(2)));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Test(org.junit.jupiter.api.Test)

Example 9 with WireMockResponse

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

the class AdminApiTest method returnsSensibleErrorIfStubIdIsNull.

@Test
public void returnsSensibleErrorIfStubIdIsNull() {
    WireMockResponse response = testClient.get("/__admin/requests?matchingStub=");
    assertThat(response.statusCode(), is(400));
    assertThat(response.content(), jsonPartEquals("errors[0].title", "Query parameter matchingStub value '' is not a valid UUID"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 10 with WireMockResponse

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

the class AdminApiTest method returnsBadEntityWhenAttemptingToSetNonExistentScenarioState.

@Test
void returnsBadEntityWhenAttemptingToSetNonExistentScenarioState() {
    dsl.stubFor(get("/one").inScenario("my-scenario").whenScenarioStateIs(STARTED).willSetStateTo("2").willReturn(ok("started")));
    dsl.stubFor(get("/one").inScenario("my-scenario").whenScenarioStateIs("2").willSetStateTo(STARTED).willReturn(ok("2")));
    WireMockResponse response = testClient.putWithBody("/__admin/scenarios/my-scenario/state", "{\"state\":\"non-existent-state\"}", "application/json");
    assertThat(response.statusCode(), is(422));
    assertThat(response.content(), jsonPartEquals("errors[0].title", "Scenario my-scenario does not support state non-existent-state"));
}
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