本文整理匯總了Java中play.libs.Json.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java Json.parse方法的具體用法?Java Json.parse怎麽用?Java Json.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類play.libs.Json
的用法示例。
在下文中一共展示了Json.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testread
import play.libs.Json; //導入方法依賴的package包/類
public void testread() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(ENTITY_NAME , entityName);
//innerMap.put(INDEXED , true);
//innerMap.put(JsonKey.USER_ID , "usergt78y4ry8");
innerMap.put(JsonKey.ID , "ggudy8d8ydyy8ddy9");
/*Map<String , Object> payLoad = new HashMap<>();
payLoad.put(JsonKey.USER_ID , "usergt78y4ry8");
payLoad.put(JsonKey.ID , "ggudy8d8ydyy8ddy9");
innerMap.put(PAYLOAD , payLoad);*/
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/object/read").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例2: assignDB
import play.libs.Json; //導入方法依賴的package包/類
private static void assignDB(LineageNodeLite node) {
List<Map<String, Object>> rows = null;
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("urn", node.urn);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getJdbcTemplate().getDataSource());
rows = namedParameterJdbcTemplate.queryForList(GET_DATA_ATTR, parameters);
// node only knows id, level, and urn, assign all other attributes
for (Map<String, Object> row : rows) {
JsonNode prop = Json.parse((String) row.get("properties"));
node.description = (prop.has("description")) ? prop.get("description").asText() : "null";
node.jdbc_url = (prop.has("jdbc_url")) ? prop.get("jdbc_url").asText() : "null";
node.db_code = (prop.has("db_code")) ? prop.get("db_code").asText() : "null";
// check wh_property for a user specified color, use some generic defaults if nothing found
//node.color = getColor(node.urn, node.node_type);
// set things to show up in tooltip
node._sort_list.add("db_code");
//node._sort_list.add("last_modified");
}
}
示例3: testsaveAssessment
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testsaveAssessment() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put("courseId" , "course-123");
innerMap.put("contentId" , "content01");
innerMap.put("attemptId" , "2");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/assessment/update").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例4: testenrollCourse
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testenrollCourse() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put("courseId" , "course-123");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
System.out.println(data);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/user/courses/enroll").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例5: testAnswerMultiChoiceQuestionWrongIP
import play.libs.Json; //導入方法依賴的package包/類
@Test
@RunAsStudent
public void testAnswerMultiChoiceQuestionWrongIP() throws Exception {
Result result = get("/app/student/exam/" + enrolment.getExternalExam().getHash(), true);
JsonNode node = Json.parse(contentAsString(result));
Exam studentExam = deserialize(Exam.class, node);
ExamSectionQuestion question = studentExam.getExamSections().stream()
.flatMap(es -> es.getSectionQuestions().stream())
.filter(esq -> esq.getQuestion().getType() == Question.Type.MultipleChoiceQuestion)
.findFirst()
.get();
Iterator<ExamSectionQuestionOption> it = question.getOptions().iterator();
ExamSectionQuestionOption option = it.next();
// Change IP of reservation machine to simulate that student is on different machine now
machine.setIpAddress("127.0.0.2");
machine.update();
result = request(Helpers.POST, String.format("/app/iop/student/exam/%s/question/%d/option", enrolment.getExternalExam().getHash(),
question.getId()), createMultipleChoiceAnswerData(option), true);
assertThat(result.status()).isEqualTo(403);
}
示例6: testupdateTCStatusOfUser
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testupdateTCStatusOfUser() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.USER_ID , "user123");
innerMap.put(JsonKey.TERM_AND_CONDITION_STATUS , "accepted");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/user/tc/update").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例7: testdeleteGeoLocation
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testdeleteGeoLocation() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.ROOT_ORG_ID , "org123");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/location/delete/123").method("DELETE");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例8: testremoveUsersFromBatch
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testremoveUsersFromBatch() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.BATCH_ID , "batch123");
innerMap.put(JsonKey.USER_IDs ,"LIST OF USER IDs");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/course/batch/users/remove").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例9: testCreateNote
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testCreateNote() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId}uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.USER_ID , "uuiuhcf784508 8y8c79-fhh");
innerMap.put(JsonKey.COURSE_ID , "crs123");
innerMap.put(JsonKey.CONTENT_ID , "content123");
innerMap.put(JsonKey.NOTE , "note");
innerMap.put(JsonKey.TITLE , "learn");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/note/create").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例10: testrejectUserOrganisation
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testrejectUserOrganisation() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.ORGANISATION_ID , "org123");
innerMap.put(JsonKey.STATUS, new BigInteger("1"));
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/org/member/approve").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例11: testUpdateNote
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testUpdateNote() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.ID , "123");
innerMap.put(JsonKey.TAGS , "123");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/note/update/123").method("PATCH");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例12: testenrollCourseWithInvalidData
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testenrollCourseWithInvalidData() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put("courseId" , null);
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
System.out.println(data);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/user/courses/enroll").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(400, result.status());
}
示例13: testcreateTanentPreference
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testcreateTanentPreference() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.ROLE , "admin");
innerMap.put(JsonKey.DATA , "displayPage");
innerMap.put(JsonKey.ROOT_ORG_ID , "rootOrg001");
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/org/tc/create").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例14: testcreateUser
import play.libs.Json; //導入方法依賴的package包/類
@Test
public void testcreateUser() {
PowerMockito.mockStatic(RequestInterceptor.class);
when( RequestInterceptor.verifyRequestData(Mockito.anyObject()) ).thenReturn("{userId} uuiuhcf784508 8y8c79-fhh");
Map<String , Object> requestMap = new HashMap<>();
Map<String , Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.PHONE , "8800088000");
innerMap.put(JsonKey.COUNTRY_CODE,"+91");
innerMap.put(JsonKey.EMAIL , "[email protected]");
innerMap.put(JsonKey.USERNAME , "userName");
innerMap.put(JsonKey.FIRST_NAME , "john");
innerMap.put(JsonKey.LAST_NAME , "rambo");
List<String> roles = new ArrayList<>();
roles.add("user");
List languages = new ArrayList<>();
languages.add("hindi");
innerMap.put(JsonKey.ROLES , roles);
innerMap.put(JsonKey.LANGUAGE , languages);
requestMap.put(JsonKey.REQUEST , innerMap);
String data = mapToJson(requestMap);
JsonNode json = Json.parse(data);
RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/user/create").method("POST");
req.headers(headerMap);
Result result = route(req);
assertEquals(200, result.status());
}
示例15: testGetExam
import play.libs.Json; //導入方法依賴的package包/類
@Test
@RunAsTeacher
public void testGetExam() throws Exception {
// Setup
long id = 1L;
Exam expected = Ebean.find(Exam.class, id);
// Execute
Result result = get("/app/exams/" + id);
// Verify that some paths exist in JSON, this is a significant set of information so really hard to test it's
// all there :p
assertThat(result.status()).isEqualTo(200);
JsonNode node = Json.parse(contentAsString(result));
assertPathsExist(node, getExamFields());
assertPathCounts(node, 3, getExamSectionFieldsOfExam("*"));
assertPathCounts(node, 2, "softwares[*].id", "softwares[*].name");
assertPathCounts(node, 4, "examLanguages[*].code");
// Verify some of the field values are as expected
Exam returned = deserialize(Exam.class, node);
assertThat(expected.getId()).isEqualTo(returned.getId());
assertThat(expected.getName()).isEqualTo(returned.getName());
assertThat(expected.getAnswerLanguage()).isEqualTo(returned.getAnswerLanguage());
assertThat(expected.getCourse().getId()).isEqualTo(returned.getCourse().getId());
assertThat(expected.getCreditType()).isEqualTo(returned.getCreditType());
assertThat(expected.getCustomCredit()).isEqualTo(returned.getCustomCredit());
assertThat(expected.getDuration()).isEqualTo(returned.getDuration());
assertThat(expected.getEnrollInstruction()).isEqualTo(returned.getEnrollInstruction());
assertThat(expected.getExamActiveEndDate()).isEqualTo(returned.getExamActiveEndDate());
assertThat(expected.getExamActiveStartDate()).isEqualTo(returned.getExamActiveStartDate());
}