Search in sources :

Example 61 with DocumentContext

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");
}
Also used : JsonPathAssert(com.revinate.assertj.json.JsonPathAssert) PaginatedList(org.graylog2.database.PaginatedList) DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 62 with DocumentContext

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

Example 63 with DocumentContext

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;
}
Also used : JSONObject(org.json.JSONObject) CategoryPill(com.wikia.webdriver.elements.communities.mobile.components.discussions.common.category.CategoryPill) RemoteException(com.wikia.webdriver.common.remote.RemoteException) DocumentContext(com.jayway.jsonpath.DocumentContext)

Example 64 with DocumentContext

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

Example 65 with DocumentContext

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

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