Search in sources :

Example 81 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.

the class CaptureControllerTest method shouldStartWithMaximumParams.

@Test
public void shouldStartWithMaximumParams() throws JSONException {
    ResponseEntity<String> response = startVideo(CAPTURE_START_PARAMS_MAX);
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    String expectedJson = "{" + "    'state': 'recording'," + "    'categories': {" + "        'organisation': 'Google'," + "        'product': 'Search'," + "        'module': 'Web App'" + "    }," + "    'feature': 'Advanced Search'," + "    'scenario': 'Search by Country!'," + "    'format': 'avi'," + "    'meta': {" + "        'version': '1.2.3-beta'," + "        'author': 'David'" + "    }," + "    'description': 'Awesome test'" + "}";
    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("google/search/web-app/advanced-search/search-by-country/");
    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 82 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.

the class InfoControllerTest method shouldRetrieveInfo.

// ===========================================
// [ /api ] GET
// ===========================================
@Test
public void shouldRetrieveInfo() throws JSONException {
    ResponseEntity<String> response = restTemplate.exchange(urlWithPort("/api"), HttpMethod.GET, new HttpEntity<>(headers), String.class);
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    String expectedJson = "{" + "  'info': {" + "    'categories': ['organisation', 'product', 'module']," + "    'storage': {}," + "    'upload': {" + "      'enable': true," + "      'url': 'http://localhost:" + port + "/mock-upload'," + "      'headers': {" + "        'Authorization': '########'" + "      }," + "      'threads': 1," + "      'keepFinishedUploadsInSecs': 30" + "    }," + "    'display': {" + "      'x': 0," + "      'y': 0" + "    }," + "    'environment': {}" + "  }," + "  'defaults': {" + "    'categories': {" + "      'organisation': 'Acme'," + "      'product': 'Moon Rocket'," + "      'module': 'UI'" + "    }," + "    'display': {" + "      'alwaysOnTop': 'false'," + "      'capture': {" + "        'x': '0'," + "        'y': '0'," + "        'width': 'displayWidth'," + "        'height': 'displayHeight'" + "      }," + "      'border': {" + "        'display': 'false'," + "        'color': '#ff0000'," + "        'padding': '1'," + "        'width': '1'" + "      }," + "      'background': {" + "        'display': 'false'," + "        'color': '#ffffff'," + "        'x': '0'," + "        'y': '0'," + "        'width': 'displayWidth'," + "        'height': 'displayHeight'" + "      }," + "      'text': {" + "        'display': 'false'," + "        'color': '#000000'," + "        'fontSize': '12'," + "        'x': '0'," + "        'y': '0'" + "      }" + "    }" + "  }," + "  'captureStatus': {" + "    'state': 'idle'" + "  }" + "}";
    JSONAssert.assertEquals(expectedJson, response.getBody(), false);
    DocumentContext json = JsonPath.parse(response.getBody());
    JsonPathAssert.assertThat(json).jsonPathAsString("$.info.started").isNotNull();
    JsonPathAssert.assertThat(json).jsonPathAsString("$.info.uptimeSeconds").isNotNull();
    JsonPathAssert.assertThat(json).jsonPathAsString("$.info.storage.tempFolder").isNotNull();
    JsonPathAssert.assertThat(json).jsonPathAsString("$.info.storage.videoFolder").isNotNull();
    JsonPathAssert.assertThat(json).jsonPathAsString("$.info.display.width").isNotNull();
    JsonPathAssert.assertThat(json).jsonPathAsString("$.info.display.height").isNotNull();
    JsonPathAssert.assertThat(json).jsonPathAsString("$.info.display.height").isNotNull();
    Map<String, String> environmentMap = json.read("$.info.environment");
    assertThat(environmentMap.get("java.awt.graphicsenv")).isNotEmpty();
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 83 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project spring-data-commons by spring-projects.

the class ProjectionIntegrationTests method jacksonSerializationDoesNotExposeDecoratedClass.

// DATACMNS-909
@Test
public void jacksonSerializationDoesNotExposeDecoratedClass() throws Exception {
    ProxyProjectionFactory factory = new ProxyProjectionFactory();
    SampleProjection projection = factory.createProjection(SampleProjection.class);
    ParseContext context = JsonPath.using(new ConfigurationBuilder().options(Option.SUPPRESS_EXCEPTIONS).build());
    DocumentContext json = context.parse(new ObjectMapper().writeValueAsString(projection));
    assertThat(json.read("$.decoratedClass", String.class)).isNull();
}
Also used : ConfigurationBuilder(com.jayway.jsonpath.Configuration.ConfigurationBuilder) ParseContext(com.jayway.jsonpath.ParseContext) DocumentContext(com.jayway.jsonpath.DocumentContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 84 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project connectors-workspace-one by vmware.

the class SalesforceController method getUniqueAccounts.

/**
 * Convert into a Set of unique Accounts, *excluding* those Accounts that
 * already have the email sender as a Contact.
 */
private List<SFAccount> getUniqueAccounts(List<Map<String, Object>> contactRecords, String senderEmail) {
    // We use these Sets to filter out duplicate entries
    Set<SFAccount> uniqueAccounts = new HashSet<>();
    Set<SFAccount> accountsWithExistingContact = new HashSet<>();
    for (Map<String, Object> acctRecord : contactRecords) {
        // Get a reusable context for JsonPath parsing
        DocumentContext ctx = JsonPath.parse(acctRecord);
        // Create an object for the Account to which this Contact belongs
        String acctId = ctx.read("$.Account.Id", String.class);
        String acctName = ctx.read("$.Account.Name", String.class);
        SFAccount acct = new SFAccount(acctId, acctName);
        // Add the Account to the set of all Accounts - this is how we filter out duplicate Accounts
        uniqueAccounts.add(acct);
        // If the Contact has the same email address as the sender, then we don't want to prompt the user to add
        // the sender as a new Contact, so we keep a separate Set of those accounts
        String contactEmail = ctx.read("$.Email", String.class);
        if (senderEmail.equalsIgnoreCase(contactEmail)) {
            accountsWithExistingContact.add(acct);
        }
    }
    // Now subtract out the accounts where the contact already exists...
    uniqueAccounts.removeAll(accountsWithExistingContact);
    // and return the remainder in the form of a List
    return new ArrayList<>(uniqueAccounts);
}
Also used : DocumentContext(com.jayway.jsonpath.DocumentContext)

Example 85 with DocumentContext

use of com.jayway.jsonpath.DocumentContext in project connectors-workspace-one by vmware.

the class JsonReplacementsBuilder method transform.

private String transform(String source) {
    DocumentContext context = JsonPath.using(configuration).parse(source);
    replacements.forEach(replacement -> context.set(replacement.getLeft(), replacement.getRight()));
    return context.jsonString();
}
Also used : 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