use of com.jayway.jsonpath.DocumentContext in project spring-boot-admin by codecentric.
the class ApplicationTest method test_json_format.
@Test
public void test_json_format() throws JsonProcessingException, IOException {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
Application app = Application.create("test").withHealthUrl("http://health").withServiceUrl("http://service").withManagementUrl("http://management").build();
DocumentContext json = JsonPath.parse(objectMapper.writeValueAsString(app));
assertThat((String) json.read("$.name")).isEqualTo("test");
assertThat((String) json.read("$.serviceUrl")).isEqualTo("http://service");
assertThat((String) json.read("$.managementUrl")).isEqualTo("http://management");
assertThat((String) json.read("$.healthUrl")).isEqualTo("http://health");
}
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) {
PageObjectLogging.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;
}
use of com.jayway.jsonpath.DocumentContext in project nifi by apache.
the class SplitJson method onTrigger.
@Override
public void onTrigger(final ProcessContext processContext, final ProcessSession processSession) {
FlowFile original = processSession.get();
if (original == null) {
return;
}
final ComponentLog logger = getLogger();
DocumentContext documentContext;
try {
documentContext = validateAndEstablishJsonContext(processSession, original);
} catch (InvalidJsonException e) {
logger.error("FlowFile {} did not have valid JSON content.", new Object[] { original });
processSession.transfer(original, REL_FAILURE);
return;
}
final JsonPath jsonPath = JSON_PATH_REF.get();
Object jsonPathResult;
try {
jsonPathResult = documentContext.read(jsonPath);
} catch (PathNotFoundException e) {
logger.warn("JsonPath {} could not be found for FlowFile {}", new Object[] { jsonPath.getPath(), original });
processSession.transfer(original, REL_FAILURE);
return;
}
if (!(jsonPathResult instanceof List)) {
logger.error("The evaluated value {} of {} was not a JSON Array compatible type and cannot be split.", new Object[] { jsonPathResult, jsonPath.getPath() });
processSession.transfer(original, REL_FAILURE);
return;
}
List resultList = (List) jsonPathResult;
Map<String, String> attributes = new HashMap<>();
final String fragmentId = UUID.randomUUID().toString();
attributes.put(FRAGMENT_ID.key(), fragmentId);
attributes.put(FRAGMENT_COUNT.key(), Integer.toString(resultList.size()));
for (int i = 0; i < resultList.size(); i++) {
Object resultSegment = resultList.get(i);
FlowFile split = processSession.create(original);
split = processSession.write(split, (out) -> {
String resultSegmentContent = getResultRepresentation(resultSegment, nullDefaultValue);
out.write(resultSegmentContent.getBytes(StandardCharsets.UTF_8));
});
attributes.put(SEGMENT_ORIGINAL_FILENAME.key(), split.getAttribute(CoreAttributes.FILENAME.key()));
attributes.put(FRAGMENT_INDEX.key(), Integer.toString(i));
processSession.transfer(processSession.putAllAttributes(split, attributes), REL_SPLIT);
}
original = copyAttributesToOriginal(processSession, original, fragmentId, resultList.size());
processSession.transfer(original, REL_ORIGINAL);
logger.info("Split {} into {} FlowFiles", new Object[] { original, resultList.size() });
}
use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.
the class CaptureControllerTest method shouldStop.
// FIXME - error states
// ===========================================
// [ /api/captures/stop ] POST
// ===========================================
@Test
public void shouldStop() throws JSONException {
startVideo(CAPTURE_START_PARAMS_MIN);
ResponseEntity<String> response = stopVideo();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'state': 'stopped'," + " '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("$.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();
}
use of com.jayway.jsonpath.DocumentContext in project vft-capture by videofirst.
the class CaptureControllerTest method shouldFinishWithMaxParams.
@Test
public void shouldFinishWithMaxParams() throws JSONException {
startVideo(CAPTURE_START_PARAMS_MAX);
ResponseEntity<String> response = finishVideo(CAPTURE_FINISH_PARAMS_MAX);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String expectedJson = "{" + " 'state': 'finished'," + " 'categories': {" + " 'organisation': 'Google'," + " 'product': 'Search'," + " 'module': 'Web App'" + " }," + " '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': 'co.videofirst.vft.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").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();
}
Aggregations