Search in sources :

Example 6 with Json

use of mjson.Json in project grakn by graknlabs.

the class RequestsTest method extractJsonField_MustExtractTopLevelFieldCorrectly.

@Test
public void extractJsonField_MustExtractTopLevelFieldCorrectly() {
    String topLevelFieldValue = "topLevelFieldValue";
    Json input = Json.object("topLevelField", topLevelFieldValue);
    String extractedTopLevelField = extractJsonField(input, "topLevelField").asString();
    assertThat(extractedTopLevelField, equalTo(topLevelFieldValue));
}
Also used : Json(mjson.Json) Test(org.junit.Test)

Example 7 with Json

use of mjson.Json in project grakn by graknlabs.

the class GraqlShellIT method testJsonOutput.

@Test
public void testJsonOutput() throws Exception {
    String[] result = runShellWithoutErrors("", "-e", "match $x sub " + Schema.MetaSchema.THING.getLabel().getValue() + "; get;", "-o", "json").split("\n");
    assertThat(result, arrayWithSize(NUM_METATYPES));
    Json json = Json.read(result[0]);
    Json x = json.at("x");
    assertTrue(x.has("id"));
    assertFalse(x.has("isa"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Json(mjson.Json) Test(org.junit.Test)

Example 8 with Json

use of mjson.Json 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)

Example 9 with Json

use of mjson.Json in project grakn by graknlabs.

the class GraqlControllerTest method whenRunningInsertQuery_JsonResponseCanBeMappedToJavaObject.

@Test
public void whenRunningInsertQuery_JsonResponseCanBeMappedToJavaObject() {
    Concept expectedConcept = ConceptBuilder.build(sampleKB.tx().getEntityType("movie"));
    Json json = Json.read(sendQuery("insert $x label movie;", APPLICATION_JSON).body().asString()).asJsonList().iterator().next().at("x");
    Concept concept = JsonConceptBuilder.build(json);
    assertEquals(expectedConcept, concept);
}
Also used : Concept(ai.grakn.engine.controller.response.Concept) Json(mjson.Json) Test(org.junit.Test)

Example 10 with Json

use of mjson.Json in project grakn by graknlabs.

the class GraqlControllerTest method whenExecutingExplainQuery_responseIsValid.

// TODO: This test should be improved
@Test
public void whenExecutingExplainQuery_responseIsValid() {
    String keyspace = genealogyKB.tx().keyspace().getValue();
    Response response = sendExplanationQuery("match ($x,$y) isa cousins; offset 0; limit 1; get;", keyspace);
    List<Json> json = Json.read(response.body().asString()).asJsonList();
    assertEquals(3, json.size());
}
Also used : Response(com.jayway.restassured.response.Response) Json(mjson.Json) Test(org.junit.Test)

Aggregations

Json (mjson.Json)10 Test (org.junit.Test)8 Concept (ai.grakn.engine.controller.response.Concept)2 Response (com.jayway.restassured.response.Response)2 SchemaConcept (ai.grakn.concept.SchemaConcept)1 Role (ai.grakn.engine.controller.response.Role)1 Rule (ai.grakn.engine.controller.response.Rule)1 GraknServerException (ai.grakn.exception.GraknServerException)1 Pattern (ai.grakn.graql.Pattern)1 Query (ai.grakn.graql.Query)1 Var (ai.grakn.graql.Var)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)1 ClassRule (org.junit.ClassRule)1