Search in sources :

Example 6 with DocumentContext

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

Example 7 with DocumentContext

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

Example 8 with DocumentContext

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

Example 9 with DocumentContext

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

Example 10 with DocumentContext

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

Aggregations

DocumentContext (com.jayway.jsonpath.DocumentContext)150 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)9 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 IOException (java.io.IOException)4