Search in sources :

Example 1 with Errors

use of com.github.tomakehurst.wiremock.common.Errors in project wiremock by wiremock.

the class AdminApiTest method returnsBadEntityStatusWhenContainsOperandIsNull.

@Test
public void returnsBadEntityStatusWhenContainsOperandIsNull() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"contains\": null\n" + "            }\n" + "        ]\n" + "    }\n" + "}");
    assertThat(response.statusCode(), is(422));
    Errors errors = Json.read(response.content(), Errors.class);
    assertThat(errors.first().getSource().getPointer(), is("/request/bodyPatterns/0"));
    assertThat(errors.first().getTitle(), is("Error parsing JSON"));
    assertThat(errors.first().getDetail(), is("contains operand must be a non-null string"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 2 with Errors

use of com.github.tomakehurst.wiremock.common.Errors in project wiremock by wiremock.

the class AdminApiTest method returnsBadEntityStatusWhenInvalidMatchOperatorManyBodyPatterns.

@Test
public void returnsBadEntityStatusWhenInvalidMatchOperatorManyBodyPatterns() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"equalTo\": \"fine\"\n" + "            },\n" + "            {\n" + "                \"matching\": \"somebad]]][[stuff\"\n" + "            }\n" + "        ]\n" + "    }\n" + "}");
    assertThat(response.statusCode(), is(422));
    Errors errors = Json.read(response.content(), Errors.class);
    assertThat(errors.first().getSource().getPointer(), is("/request/bodyPatterns/1"));
    assertThat(errors.first().getDetail(), is("{\"matching\":\"somebad]]][[stuff\"} is not a valid match operation"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 3 with Errors

use of com.github.tomakehurst.wiremock.common.Errors in project wiremock by wiremock.

the class AdminApiTest method returnsBadEntityStatusWhenEqualToOperandIsWrongType.

@Test
public void returnsBadEntityStatusWhenEqualToOperandIsWrongType() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"equalTo\": 12\n" + "            }\n" + "        ]\n" + "    }\n" + "}");
    assertThat(response.statusCode(), is(422));
    Errors errors = Json.read(response.content(), Errors.class);
    assertThat(errors.first().getSource().getPointer(), is("/request/bodyPatterns/0"));
    assertThat(errors.first().getTitle(), is("Error parsing JSON"));
    assertThat(errors.first().getDetail(), is("equalTo operand must be a non-null string"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 4 with Errors

use of com.github.tomakehurst.wiremock.common.Errors 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 5 with Errors

use of com.github.tomakehurst.wiremock.common.Errors in project wiremock by wiremock.

the class AdminApiTest method returnsBadEntityStatusWhenInvalidRegexUsedInHeader.

@Test
public void returnsBadEntityStatusWhenInvalidRegexUsedInHeader() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"headers\": {\n" + "            \"Accept\": {\n" + "                \"matches\": \"%[[json[[\"\n" + "            }\n" + "        }\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 8\n" + "%[[json[[\n" + "        ^"));
    assertThat(errors.first().getSource().getPointer(), is("/request/headers/Accept"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Aggregations

Errors (com.github.tomakehurst.wiremock.common.Errors)11 WireMockResponse (com.github.tomakehurst.wiremock.testsupport.WireMockResponse)11 Test (org.junit.jupiter.api.Test)11