Search in sources :

Example 66 with DocumentContext

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();
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 67 with DocumentContext

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();
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 68 with DocumentContext

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();
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 69 with DocumentContext

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"));
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 70 with DocumentContext

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) {
    }
}
Also used : JsonContext(com.jayway.jsonpath.internal.JsonContext) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException) DocumentContext(com.jayway.jsonpath.DocumentContext)

Aggregations

DocumentContext (com.jayway.jsonpath.DocumentContext)146 Test (org.junit.Test)106 HashMap (java.util.HashMap)14 BaseTest (com.jayway.jsonpath.BaseTest)12 Map (java.util.Map)12 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)8 JsonPath (com.jayway.jsonpath.JsonPath)7 File (java.io.File)7 List (java.util.List)7 JsonPathAssert (com.revinate.assertj.json.JsonPathAssert)6 Query (org.graylog.plugins.views.search.Query)6 MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)6 Time (org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time)6 Values (org.graylog.plugins.views.search.searchtypes.pivot.buckets.Values)6 DateTime (org.joda.time.DateTime)6 Configuration (com.jayway.jsonpath.Configuration)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 InvalidJsonException (com.jayway.jsonpath.InvalidJsonException)4