use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.
the class CaptureControllerTest method shouldRecordMinParams.
@Test
public void shouldRecordMinParams() throws JSONException {
ResponseEntity<String> response = recordVideo(CAPTURE_RECORD_PARAMS_MIN);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'type': 'manual'," + " 'recording': true," + " 'project': 'Moon Rocket'," + " 'feature': 'Bob Feature'," + " 'scenario': 'Dave Scenario'" + "}";
JSONAssert.assertEquals(expectedJson, response.getBody(), false);
DocumentContext json = JsonPath.parse(response.getBody());
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 shouldStopWithMinParams.
@Test
public void shouldStopWithMinParams() throws JSONException {
recordVideo(CAPTURE_RECORD_PARAMS_MIN);
ResponseEntity<String> response = stopVideo(CAPTURE_STOP_PARAMS_MIN);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'type': 'manual'," + " 'recording': false," + " 'project': 'Moon Rocket'," + " '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("moon-rocket/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.
// ===========================================
// [ /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 mica2 by obiba.
the class EntityConfigServiceTest method can_merge_two_definition.
@Test
public void can_merge_two_definition() throws Exception {
// Given
String customDefinition = "[" + " {" + " \"type\": \"fieldset\"," + " \"items\": [ \"customItem1\", \"customItem2\"]" + " }" + "]";
String mandatoryDefinition = "[" + " {" + " \"type\": \"fieldset\"," + " \"items\": [\"mandatoryItem1\"]" + " }" + "]";
// Execute
String mergeSchema = new IndividualStudyConfigService().mergeDefinition(customDefinition, mandatoryDefinition);
// Verify
DocumentContext parse = JsonPath.parse(mergeSchema);
assertThat(parse.read("$[0].items[0]"), is("mandatoryItem1"));
assertThat(parse.read("$[1].items[0]"), is("customItem1"));
}
use of com.jayway.jsonpath.DocumentContext in project mica2 by obiba.
the class SchemaFormContentFileService method deleteFiles.
public void deleteFiles(SchemaFormContentAware entity) {
Object json = defaultConfiguration().jsonProvider().parse(entity.getContent());
DocumentContext context = JsonPath.using(defaultConfiguration().addOptions(Option.AS_PATH_LIST)).parse(json);
DocumentContext reader = new JsonContext(defaultConfiguration().addOptions(Option.REQUIRE_PROPERTIES)).parse(json);
try {
((JSONArray) context.read("$..obibaFiles")).stream().map(p -> (JSONArray) reader.read(p.toString())).flatMap(Collection::stream).forEach(file -> fileStoreService.delete(((LinkedHashMap) file).get("id").toString()));
} catch (PathNotFoundException e) {
}
}
Aggregations