use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.
the class CaptureControllerTest method shouldStartMinParamsWithRecord.
@Test
public void shouldStartMinParamsWithRecord() throws JSONException {
ResponseEntity<String> response = startVideo(CAPTURE_START_PARAMS_MIN);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'state': 'recording'," + " 'categories': {" + " 'organisation': 'Acme'," + " 'product': 'Moon Rocket'," + " 'module': 'UI'" + " }," + " 'feature': 'Bob Feature'," + " 'scenario': 'Dave Scenario'," + " '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").startsWith("acme/moon-rocket/ui/bob-feature/dave-scenario/");
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 shouldRecord.
// ===========================================
// [ /api/captures/record ] POST
// ===========================================
@Test
public void shouldRecord() throws JSONException {
// must specify record, otherwise no need
startVideo(CAPTURE_START_PARAMS_MIN_NO_RECORD);
ResponseEntity<String> response = recordVideo();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'state': 'recording'," + " 'categories': {" + " 'organisation': 'Acme'," + " 'product': 'Moon Rocket'," + " 'module': 'UI'" + " }," + " 'feature': 'Bob Feature'," + " 'scenario': 'Dave Scenario'," + " '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").startsWith("acme/moon-rocket/ui/bob-feature/dave-scenario/");
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 shouldUpload.
// ===========================================
// [ /api/captures/upload ]
// ===========================================
@Test
public void shouldUpload() throws Exception {
ResponseEntity<String> response = uploadById("2018-02-15_12-14-02_n3jwzb");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
DocumentContext json = JsonPath.parse(response.getBody());
JsonPathAssert.assertThat(json).jsonPathAsInteger("$.length()").isEqualTo(1);
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].id").isEqualTo("2018-02-15_12-14-02_n3jwzb");
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].state").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].url").matches("http:\\/\\/localhost:\\d+\\/mock-upload");
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].scheduled").isNotNull();
verify(mockUploadService, timeout(5000)).upload(any(MultipartFile.class), any(MultipartFile.class));
// Call status until upload finishes
await().atMost(5, SECONDS).untilAsserted(() -> assertThat(uploadStatusState()).isEqualTo("finished"));
response = uploadStatus();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
json = JsonPath.parse(response.getBody());
JsonPathAssert.assertThat(json).jsonPathAsInteger("$.length()").isEqualTo(1);
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].id").isEqualTo("2018-02-15_12-14-02_n3jwzb");
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].state").isEqualTo("finished");
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].url").matches("http:\\/\\/localhost:\\d+\\/mock-upload");
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].scheduled").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].started").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].updated").isNotNull();
JsonPathAssert.assertThat(json).jsonPathAsString("$[0].finished").isNotNull();
}
use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.
the class CaptureControllerTest method shouldFinishWithMinParams.
// FIXME - error states
// ===========================================
// [ /api/captures/finish ] POST
// ===========================================
@Test
public void shouldFinishWithMinParams() throws JSONException {
startVideo(CAPTURE_START_PARAMS_MIN);
ResponseEntity<String> response = finishVideo(CAPTURE_FINISH_PARAMS_MIN);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'state': 'finished'," + " 'categories': {" + " 'organisation': 'Acme'," + " 'product': 'Moon Rocket'," + " 'module': 'UI'" + " }," + " 'feature': 'Bob Feature'," + " 'scenario': 'Dave Scenario'," + " 'format': 'avi'," + " 'meta': {}" + "}";
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").startsWith("acme/moon-rocket/ui/bob-feature/dave-scenario/");
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 cancelAndAssertStatusIsIdle.
/**
* Cancel and assert that the status is idle.
*/
private void cancelAndAssertStatusIsIdle(String initialCheck, ResponseEntity<String> response) throws JSONException {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
DocumentContext json = JsonPath.parse(response.getBody());
JsonPathAssert.assertThat(json).jsonPathAsString(initialCheck).isNotNull();
cancelVideo();
response = statusVideo();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
JSONAssert.assertEquals("{'state' : 'idle'}", response.getBody(), true);
}
Aggregations