Search in sources :

Example 6 with Errors

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

the class AdminApiTest method returnsBadEntityStatusWhenInvalidRegexUsedInBodyPattern.

@Test
public void returnsBadEntityStatusWhenInvalidRegexUsedInBodyPattern() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"equalTo\": \"fine\"\n" + "            },\n" + "            {\n" + "                \"matches\": \"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().getTitle(), is("Error parsing JSON"));
    assertThat(errors.first().getDetail(), equalsMultiLine("Unclosed character class near index 16\n" + "somebad]]][[stuff\n" + "                ^"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 7 with Errors

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

the class AdminApiTest method returnsBadEntityStatusWhenInvalidMatchOperator.

@Test
public void returnsBadEntityStatusWhenInvalidMatchOperator() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\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/0"));
    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 8 with Errors

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

the class AdminApiTest method returnsBadEntityStatusOnEqualToJsonOperand.

@Test
public void returnsBadEntityStatusOnEqualToJsonOperand() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"equalToJson\": \"(wrong)\"\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().getDetail(), allOf(containsString("Unexpected character ('(' (code 40)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')"), containsString("line: 1, column: 2")));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Errors(com.github.tomakehurst.wiremock.common.Errors) Test(org.junit.jupiter.api.Test)

Example 9 with Errors

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

the class AdminApiTest method returnsBadEntityStatusWhenContainsOperandIsWrongType.

@Test
public void returnsBadEntityStatusWhenContainsOperandIsWrongType() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"contains\": 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("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 10 with Errors

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

the class AdminApiTest method returnsBadEntityStatusWhenInvalidEqualToXmlSpecified.

@Test
public void returnsBadEntityStatusWhenInvalidEqualToXmlSpecified() {
    WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + "    \"request\": {\n" + "        \"bodyPatterns\": [\n" + "            {\n" + "                \"equalToXml\": \"(wrong)\"\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("Content is not allowed in prolog.; line 1; column 1"));
}
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