Search in sources :

Example 1 with GraknServerException

use of ai.grakn.exception.GraknServerException in project grakn by graknlabs.

the class RequestsTest method extractJsonField_MustThrowInformativeError.

@Test
public void extractJsonField_MustThrowInformativeError() {
    // in this test, extractJsonField expects the existence of a field "topLevelField.nestedField"
    // however, the input incorrectly contains "topLevelField.incorrectlyNamedNestedField" instead
    String nestedFieldValue = "nestedFieldValue";
    Json input = Json.object("topLevelField", Json.object("incorrectlyNamedNestedField", nestedFieldValue));
    // test if exception is properly thrown
    boolean errorMessageThrown_ContainingMissingFieldInfo;
    try {
        extractJsonField(input, "topLevelField", "nestedField");
        errorMessageThrown_ContainingMissingFieldInfo = false;
    } catch (GraknServerException e) {
        errorMessageThrown_ContainingMissingFieldInfo = e.getMessage().contains("nestedField");
    }
    assertThat(errorMessageThrown_ContainingMissingFieldInfo, equalTo(true));
}
Also used : GraknServerException(ai.grakn.exception.GraknServerException) Json(mjson.Json) Test(org.junit.Test)

Aggregations

GraknServerException (ai.grakn.exception.GraknServerException)1 Json (mjson.Json)1 Test (org.junit.Test)1