use of com.jayway.jsonpath.DocumentContext in project graylog2-server by Graylog2.
the class PaginatedResponseTest method serializeWithContext.
@Test
public void serializeWithContext() throws Exception {
final ImmutableList<String> values = ImmutableList.of("hello", "world");
final ImmutableMap<String, Object> context = ImmutableMap.of("context1", "wow");
final PaginatedList<String> paginatedList = new PaginatedList<>(values, values.size(), 1, 10);
final PaginatedResponse<String> response = PaginatedResponse.create("foo", paginatedList, context);
final DocumentContext ctx = JsonPath.parse(objectMapper.writeValueAsString(response));
final JsonPathAssert jsonPathAssert = JsonPathAssert.assertThat(ctx);
jsonPathAssert.jsonPathAsInteger("$.total").isEqualTo(2);
jsonPathAssert.jsonPathAsInteger("$.count").isEqualTo(2);
jsonPathAssert.jsonPathAsInteger("$.page").isEqualTo(1);
jsonPathAssert.jsonPathAsInteger("$.per_page").isEqualTo(10);
jsonPathAssert.jsonPathAsString("$.foo[0]").isEqualTo("hello");
jsonPathAssert.jsonPathAsString("$.foo[1]").isEqualTo("world");
jsonPathAssert.jsonPathAsString("$.context.context1").isEqualTo("wow");
}
use of com.jayway.jsonpath.DocumentContext in project graylog2-server by Graylog2.
the class AssertJsonPath method assertJsonPath.
public static void assertJsonPath(String json, Consumer<JsonPathAssert> consumer) {
final DocumentContext context = JsonPath.parse(json, configuration);
final JsonPathAssert jsonPathAssert = JsonPathAssert.assertThat(context);
consumer.accept(jsonPathAssert);
}
use of com.jayway.jsonpath.DocumentContext in project selenium-tests by Wikia.
the class CreateCategory method execute.
public CategoryPill.Data execute(final CreateCategoryContext context) {
JSONObject jsonObject = new JSONObject(ImmutableMap.builder().put("name", context.getCategoryName()).put("parentId", PARENT_ID).put("siteId", context.getSiteId()).build());
String response;
try {
response = remoteOperation.execute(buildUrl(context), jsonObject);
} catch (RemoteException e) {
Log.logError("error: ", e);
throw new CategoryNotCreated("Could not create a new category.", e);
}
DocumentContext json = JsonPath.parse(response);
CategoryPill.Data data = new CategoryPill.Data(json.read("$.id"), json.read("$.name"));
data.setDisplayOrder(json.read("$.displayOrder"));
return data;
}
use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.
the class CaptureControllerTest method shouldRecordNoParams.
// ===========================================
// [ /captures/record ] POST
// ===========================================
@Test
public void shouldRecordNoParams() throws JSONException {
ResponseEntity<String> response = recordVideo();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'type': 'manual'," + " 'recording': true," + " 'project': 'Moon Rocket'," + " 'format': 'avi'" + "}";
JSONAssert.assertEquals(expectedJson, response.getBody(), false);
DocumentContext json = JsonPath.parse(response.getBody());
JsonPathAssert.assertThat(json).jsonPathAsString("$.started").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.durationSeconds").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.folder").matches("moon-rocket/\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}_[a-z0-9]{6}");
JsonPathAssert.assertThat(json).jsonPathAsString("$.id").isNotNull().hasSize(26);
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.x").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.y").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.width").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.height").isNotNull();
Map<String, String> environmentMap = json.read("$.environment");
assertThat(environmentMap.get("java.awt.graphicsenv")).isNotEmpty();
}
use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.
the class CaptureControllerTest method shouldStopWithMaxParams.
@Test
public void shouldStopWithMaxParams() throws JSONException {
recordVideo(CAPTURE_RECORD_PARAMS_MAX);
ResponseEntity<String> response = stopVideo(CAPTURE_STOP_PARAMS_MAX);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'type': 'automated'," + " 'sid': 5678," + " 'recording': false," + " 'project': 'Google Search'," + " 'feature': 'Advanced Search'," + " 'scenario': 'Search by Country!'," + " 'format': 'avi'," + " 'meta': {" + " 'version': '1.2.3-beta'," + " 'author': 'Bob'," + " 'extra': 'stuff'" + " }," + " 'description': 'even more awesome description'," + " 'testStatus': 'fail'," + " 'testError': 'awesome error'," + " 'testStackTrace': 'io.videofirst.capture.exception.InvalidStateException: Current state is idle'," + " 'testLogs': [{" + " 'ts': '2015-01-02T12:13:14'," + " 'cat': 'browser'," + " 'tier': 'L1'," + " 'log': 'awesome log 1'" + " }, {" + " 'ts': '2016-02-03T16:17:18'," + " 'cat': 'server'," + " 'tier': 'L2'," + " 'log': 'awesome log 2'" + " }]" + "}";
JSONAssert.assertEquals(expectedJson, response.getBody(), false);
DocumentContext json = JsonPath.parse(response.getBody());
JsonPathAssert.assertThat(json).jsonPathAsString("$.started").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.finished").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.durationSeconds").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.folder").matches("^5678/\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}_[\\w\\d]{6}$");
JsonPathAssert.assertThat(json).jsonPathAsString("$.id").isNotNull().hasSize(26);
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.x").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.y").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.width").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$.capture.height").isNotNull();
Map<String, String> environmentMap = json.read("$.environment");
assertThat(environmentMap.get("java.awt.graphicsenv")).isNotEmpty();
}
Aggregations