List of usage examples for org.apache.commons.httpclient HttpMethod getResponseBodyAsString
public abstract String getResponseBodyAsString() throws IOException;
From source file:org.olat.restapi.CoursesTest.java
@Test public void testGetCourses() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final HttpMethod method = createGet("/repo/courses", MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200);/* ww w . ja v a2 s. c om*/ final String body = method.getResponseBodyAsString(); final List<CourseVO> courses = parseCourseArray(body); assertNotNull(courses); assertTrue(courses.size() >= 2); CourseVO vo1 = null; CourseVO vo2 = null; for (final CourseVO course : courses) { if (course.getTitle().equals("courses1")) { vo1 = course; } else if (course.getTitle().equals("courses2")) { vo2 = course; } } assertNotNull(vo1); assertEquals(vo1.getKey(), course1.getResourceableId()); assertNotNull(vo2); assertEquals(vo2.getKey(), course2.getResourceableId()); }
From source file:org.olat.restapi.GroupMgmtTest.java
@Test public void testGetParticipantsAdmin() throws HttpException, IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final String request = "/groups/" + g1.getKey() + "/participants"; final HttpMethod method = createGet(request, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200);// w w w . j a va2 s .c om final String body = method.getResponseBodyAsString(); final List<UserVO> participants = parseUserArray(body); assertNotNull(participants); assertEquals(participants.size(), 2); Long idKey1 = null; Long idKey2 = null; for (final UserVO participant : participants) { if (participant.getKey().equals(part1.getKey())) { idKey1 = part1.getKey(); } else if (participant.getKey().equals(part2.getKey())) { idKey2 = part2.getKey(); } } assertNotNull(idKey1); assertNotNull(idKey2); }
From source file:org.olat.restapi.GroupMgmtTest.java
@Test public void testGetOwnersAdmin() throws HttpException, IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final String request = "/groups/" + g1.getKey() + "/owners"; final HttpMethod method = createGet(request, MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200);/*from w ww. ja va 2 s.c om*/ final String body = method.getResponseBodyAsString(); final List<UserVO> owners = parseUserArray(body); assertNotNull(owners); assertEquals(owners.size(), 2); Long idKey1 = null; Long idKey2 = null; for (final UserVO participant : owners) { if (participant.getKey().equals(owner1.getKey())) { idKey1 = owner1.getKey(); } else if (participant.getKey().equals(owner2.getKey())) { idKey2 = owner2.getKey(); } } assertNotNull(idKey1); assertNotNull(idKey2); }
From source file:org.olat.restapi.UserMgmtTest.java
@Test public void testGetUsers() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final HttpMethod method = createGet("/users", MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200);/*from ww w .j ava 2 s. c o m*/ final String body = method.getResponseBodyAsString(); method.releaseConnection(); final List<UserVO> vos = parseUserArray(body); final List<Identity> identities = BaseSecurityManager.getInstance().getIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_VISIBLE_LIMIT); assertNotNull(vos); assertFalse(vos.isEmpty()); assertEquals(vos.size(), identities.size()); }
From source file:org.olat.restapi.UserMgmtTest.java
@Test public void testGetUser() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final HttpMethod method = createGet("/users/" + id1.getKey(), MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200);/*www. java 2 s .c o m*/ final String body = method.getResponseBodyAsString(); method.releaseConnection(); final UserVO vo = parse(body, UserVO.class); assertNotNull(vo); assertEquals(vo.getKey(), id1.getKey()); assertEquals(vo.getLogin(), id1.getName()); // are the properties there? assertFalse(vo.getProperties().isEmpty()); }
From source file:org.olat.restapi.UserMgmtTest.java
@Test public void testGetUserNotAdmin() throws IOException { final HttpClient c = loginWithCookie("rest-one", "A6B7C8"); final HttpMethod method = createGet("/users/" + id2.getKey(), MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200);//w w w . ja v a2 s . com final String body = method.getResponseBodyAsString(); method.releaseConnection(); final UserVO vo = parse(body, UserVO.class); assertNotNull(vo); assertEquals(vo.getKey(), id2.getKey()); assertEquals(vo.getLogin(), id2.getName()); // no properties for security reason assertTrue(vo.getProperties().isEmpty()); }
From source file:org.olat.restapi.UserMgmtTest.java
/** * Only print out the raw body of the response * /*from w w w . jav a 2 s. c om*/ * @throws IOException */ @Test public void testGetRawJsonUsers() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final HttpMethod method = createGet("/users", MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200); final String bodyJsons = method.getResponseBodyAsString(); System.out.println("Users JSON"); System.out.println(bodyJsons); System.out.println("Users JSON"); }
From source file:org.olat.restapi.UserMgmtTest.java
/** * Only print out the raw body of the response * /*from w w w. jav a 2s . c o m*/ * @throws IOException */ @Test public void testGetRawXmlUsers() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final HttpMethod method = createGet("/users", MediaType.APPLICATION_XML, true); final int code = c.executeMethod(method); assertEquals(code, 200); final String bodyXmls = method.getResponseBodyAsString(); System.out.println("Users XML"); System.out.println(bodyXmls); System.out.println("Users XML"); }
From source file:org.olat.restapi.UserMgmtTest.java
/** * Only print out the raw body of the response * /*from w w w . j a v a2 s . c o m*/ * @throws IOException */ @Test public void testGetRawJsonUser() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final HttpMethod method = createGet("/users/" + id1.getKey(), MediaType.APPLICATION_JSON, true); final int code = c.executeMethod(method); assertEquals(code, 200); final String bodyJson = method.getResponseBodyAsString(); System.out.println("User"); System.out.println(bodyJson); System.out.println("User"); }
From source file:org.olat.restapi.UserMgmtTest.java
/** * Only print out the raw body of the response * // www. ja va2 s . co m * @throws IOException */ @Test public void testGetRawXmlUser() throws IOException { final HttpClient c = loginWithCookie("administrator", "olat"); final HttpMethod method = createGet("/users/" + id1.getKey(), MediaType.APPLICATION_XML, true); final int code = c.executeMethod(method); assertEquals(code, 200); final String bodyXml = method.getResponseBodyAsString(); System.out.println("User"); System.out.println(bodyXml); System.out.println("User"); }