use of org.olat.modules.fo.restapi.MessageVO in project openolat by klemens.
the class ForumTest method testUpload64Attachment.
@Test
public void testUpload64Attachment() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).queryParam("authorKey", id1.getKey()).queryParam("title", "New message with attachment ").queryParam("body", "A very interesting response in Thread-1 with an attachment").build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
MessageVO message = conn.parse(response, MessageVO.class);
assertNotNull(message);
// attachment
InputStream portraitStream = CoursesElementsTest.class.getResourceAsStream("portrait.jpg");
assertNotNull(portraitStream);
// upload portrait
URI attachUri = getForumUriBuilder().path("posts").path(message.getKey().toString()).path("attachments").build();
byte[] portraitBytes = IOUtils.toByteArray(portraitStream);
byte[] portrait64 = Base64.encodeBase64(portraitBytes, true);
HttpPost attachMethod = conn.createPost(attachUri, MediaType.APPLICATION_JSON);
attachMethod.addHeader("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
conn.addEntity(attachMethod, new BasicNameValuePair("file", new String(portrait64)), new BasicNameValuePair("filename", "portrait64.jpg"));
HttpResponse attachCode = conn.execute(attachMethod);
assertEquals(200, attachCode.getStatusLine().getStatusCode());
// check if the file exists
ForumManager fm = ForumManager.getInstance();
VFSContainer container = fm.getMessageContainer(message.getForumKey(), message.getKey());
VFSItem uploadedFile = container.resolve("portrait64.jpg");
assertNotNull(uploadedFile);
assertTrue(uploadedFile instanceof VFSLeaf);
// check if the image is still an image
VFSLeaf uploadedImage = (VFSLeaf) uploadedFile;
InputStream uploadedStream = uploadedImage.getInputStream();
BufferedImage image = ImageIO.read(uploadedStream);
FileUtils.closeSafely(uploadedStream);
assertNotNull(image);
conn.shutdown();
}
use of org.olat.modules.fo.restapi.MessageVO in project openolat by klemens.
the class GroupMgmtTest method testGetThreads.
@Test
public void testGetThreads() throws IOException, URISyntaxException {
assertTrue(conn.login("rest-one", "A6B7C8"));
URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/forum/threads").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<MessageVO> messages = parseMessageArray(body);
assertNotNull(messages);
assertEquals(2, messages.size());
}
Aggregations