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));
}
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"));
}
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));
}
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);
}
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());
}
Aggregations