Search in sources :

Example 16 with WireMockResponse

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

the class AdminApiTest method defaultsUnspecifiedStubMappingAttributes.

@Test
public void defaultsUnspecifiedStubMappingAttributes() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{}");
    assertThat(response.statusCode(), is(201));
    String body = response.content();
    JsonAssertion.assertThat(body).field("request").field("method").isEqualTo("ANY");
    JsonAssertion.assertThat(body).field("response").field("status").isEqualTo(200);
    assertThat(testClient.get("/").statusCode(), is(200));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 17 with WireMockResponse

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

the class AdminApiTest method deleteStubMappingById.

@Test
public void deleteStubMappingById() throws Exception {
    StubMapping stubMapping = dsl.stubFor(get(urlPathEqualTo("/delete/this")).willReturn(aResponse().withStatus(200)));
    assertThat(testClient.get("/delete/this").statusCode(), is(200));
    WireMockResponse response = testClient.delete("/__admin/mappings/" + stubMapping.getId());
    assertThat(response.content(), is("{}"));
    assertThat(testClient.get("/delete/this").statusCode(), is(404));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) Test(org.junit.jupiter.api.Test)

Example 18 with WireMockResponse

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

the class AdminApiTest method returnsNotFoundWhenAttemptingToSetNonExistentScenarioState.

@Test
void returnsNotFoundWhenAttemptingToSetNonExistentScenarioState() {
    WireMockResponse response = testClient.putWithBody("/__admin/scenarios/i-dont-exist/state", "{\"state\":\"newstate\"}", "application/json");
    assertThat(response.statusCode(), is(404));
    assertThat(response.content(), jsonPartEquals("errors[0].title", "Scenario i-dont-exist does not exist"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 19 with WireMockResponse

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

the class AdminApiTest method returnsBadEntityStatusWhenInvalidRegexUsedInUrl.

@Test
public void returnsBadEntityStatusWhenInvalidRegexUsedInUrl() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{                                      \n" + "    \"request\": {                            \n" + "        \"urlPattern\": \"/@$&%*[[^^£$&%\"    \n" + "    }                                         \n" + "}");
    assertThat(response.statusCode(), is(422));
    Errors errors = Json.read(response.content(), Errors.class);
    assertThat(errors.first().getDetail(), equalsMultiLine("Unclosed character class near index 13\n" + "/@$&%*[[^^£$&%\n" + "             ^"));
    assertThat(errors.first().getSource().getPointer(), is("/request"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 20 with WireMockResponse

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

the class AdminApiTest method returnsSensibleErrorIfStubIdNotValid.

@Test
public void returnsSensibleErrorIfStubIdNotValid() {
    WireMockResponse response = testClient.get("/__admin/requests?matchingStub=not-a-valid-uuid");
    assertThat(response.statusCode(), is(400));
    assertThat(response.content(), jsonPartEquals("errors[0].title", "Query parameter matchingStub value 'not-a-valid-uuid' is not a valid UUID"));
}
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