use of com.jayway.jsonpath.DocumentContext in project JsonPath by json-path.
the class IssuesTest method issue_171.
@Test
public void issue_171() {
String json = "{\n" + " \"can delete\": \"this\",\n" + " \"can't delete\": \"this\"\n" + "}";
DocumentContext context = using(JACKSON_JSON_NODE_CONFIGURATION).parse(json);
context.set("$.['can delete']", null);
context.set("$.['can\\'t delete']", null);
ObjectNode objectNode = context.read("$");
assertThat(objectNode.get("can delete").isNull());
assertThat(objectNode.get("can't delete").isNull());
}
use of com.jayway.jsonpath.DocumentContext in project JsonPath by json-path.
the class JsonContextTest method cached_path_with_predicates.
@Test
public void cached_path_with_predicates() {
Filter feq = Filter.filter(Criteria.where("category").eq("reference"));
Filter fne = Filter.filter(Criteria.where("category").ne("reference"));
DocumentContext JsonDoc = JsonPath.parse(JSON_DOCUMENT);
List<String> eq = JsonDoc.read("$.store.book[?].category", feq);
List<String> ne = JsonDoc.read("$.store.book[?].category", fne);
Assertions.assertThat(eq).contains("reference");
Assertions.assertThat(ne).doesNotContain("reference");
}
use of com.jayway.jsonpath.DocumentContext in project credhub by cloudfoundry-incubator.
the class UserGenerationTest method whenGivenAUsernameAndPasswordParameters_usesUsernameAndGeneratesPassword.
@Test
public void whenGivenAUsernameAndPasswordParameters_usesUsernameAndGeneratesPassword() throws Exception {
MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\": \"" + credentialName1 + "\"," + "\"type\": \"user\"," + "\"value\": {" + "\"username\": \"test-username\"" + "}," + "\"parameters\": {" + "\"length\": 40," + "\"exclude_upper\": true," + "\"exclude_lower\": true," + "\"exclude_number\": false," + "\"include_special\": false" + "}" + "}");
final MockHttpServletResponse response = this.mockMvc.perform(post).andExpect(status().isOk()).andReturn().getResponse();
final DocumentContext parsedResponse = JsonPath.parse(response.getContentAsString());
final String password = parsedResponse.read("$.value.password");
assertThat(password.length(), equalTo(40));
assertThat(isDigits(password), equalTo(true));
final String username = parsedResponse.read("$.value.username");
assertThat(username, equalTo("test-username"));
}
use of com.jayway.jsonpath.DocumentContext in project credhub by cloudfoundry-incubator.
the class UserGenerationTest method returnsAConsistentPasswordHash.
@Test
public void returnsAConsistentPasswordHash() throws Exception {
MockHttpServletRequestBuilder postRequest = post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\": \"" + credentialName1 + "\"," + "\"type\": \"user\"," + "\"value\": {" + "\"username\": \"test-username\"" + "}" + "}");
final MockHttpServletResponse postResponse = this.mockMvc.perform(postRequest).andExpect(status().isOk()).andReturn().getResponse();
final MockHttpServletRequestBuilder getRequest = get("/api/v1/data?name=" + credentialName1).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON);
final MockHttpServletResponse getResponse = this.mockMvc.perform(getRequest).andExpect(status().isOk()).andReturn().getResponse();
final DocumentContext parsedPostResponse = JsonPath.parse(postResponse.getContentAsString());
final DocumentContext parsedGetResponse = JsonPath.parse(getResponse.getContentAsString());
final String postHash = parsedPostResponse.read("$.value.password_hash");
final String getHash = parsedGetResponse.read("$.data[0].value.password_hash");
assertThat(postHash, equalTo(getHash));
assertThat(postHash.matches("^\\$6\\$[a-zA-Z0-9/.]+\\$[a-zA-Z0-9/.]+$"), equalTo(true));
}
use of com.jayway.jsonpath.DocumentContext in project pom-manipulation-ext by release-engineering.
the class JSONIOTest method modifyFile.
@Test
public void modifyFile() throws ManipulationException, IOException {
String deletePath = "$..resolved";
DocumentContext doc = jsonIO.parseJSON(npmFile);
doc.delete(deletePath);
File target = tf.newFile();
jsonIO.writeJSON(target, doc.jsonString());
assertFalse(FileUtils.contentEquals(npmFile, target));
}
Aggregations