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();
}
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();
}
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();
}
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);
}
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();
}
Aggregations