use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class UserMgmtTest method testOtherUserPersonalFolder.
@Test
public void testOtherUserPersonalFolder() throws Exception {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("folders").path("personal").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<FileVO> files = parseFileArray(body);
assertNotNull(files);
assertTrue(files.isEmpty());
// private and public
assertEquals(0, files.size());
conn.shutdown();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class UserMgmtTest method testOtherUserPersonalFolderOfId3.
@Test
public void testOtherUserPersonalFolderOfId3() throws Exception {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id3.getKey().toString()).path("folders").path("personal").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<FileVO> files = parseFileArray(body);
assertNotNull(files);
assertFalse(files.isEmpty());
// private and public
assertEquals(1, files.size());
FileVO portrait = files.get(0);
assertEquals("portrait.jpg", portrait.getTitle());
conn.shutdown();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class ForumTest method testGetAttachment.
@Test
public void testGetAttachment() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
// set a attachment
VFSContainer container = forumManager.getMessageContainer(m1.getForum().getKey(), m1.getKey());
InputStream portraitIn = CoursesElementsTest.class.getResourceAsStream("portrait.jpg");
assertNotNull(portraitIn);
VFSLeaf attachment = container.createChildLeaf(UUID.randomUUID().toString().replace("-", "") + ".jpg");
FileUtils.bcopy(portraitIn, attachment.getOutputStream(false), "");
assertTrue(conn.login("administrator", "openolat"));
URI uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).path("attachments").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<FileVO> files = parseFileArray(response.getEntity().getContent());
assertNotNull(files);
FileVO attachmentVO = null;
for (FileVO file : files) {
if (attachment.getName().equals(file.getTitle())) {
attachmentVO = file;
}
}
assertNotNull(attachmentVO);
URI downloadURI = new URI(attachmentVO.getHref());
HttpGet download = conn.createGet(downloadURI, MediaType.APPLICATION_JSON, true);
HttpResponse downloadResponse = conn.execute(download);
assertEquals(200, downloadResponse.getStatusLine().getStatusCode());
// String contentType = downloadResponse.getEntity().getContentType().getValue();
// doesn't work with grizzly assertEquals("image/jpeg", contentType);
conn.shutdown();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class ForumTest method testUploadAttachmentAndRename.
@Test
public void testUploadAttachmentAndRename() 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
URL portraitUrl = CoursesElementsTest.class.getResource("portrait.jpg");
assertNotNull(portraitUrl);
File portrait = new File(portraitUrl.toURI());
// upload portrait
URI attachUri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).path("attachments").build();
HttpPost attachMethod = conn.createPost(attachUri, MediaType.APPLICATION_JSON);
conn.addMultipart(attachMethod, "portrait.jpg", portrait);
HttpResponse attachCode = conn.execute(attachMethod);
assertEquals(200, attachCode.getStatusLine().getStatusCode());
EntityUtils.consume(attachCode.getEntity());
// upload portrait a second time
URI attach2Uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).path("attachments").build();
HttpPost attach2Method = conn.createPost(attach2Uri, MediaType.APPLICATION_JSON);
conn.addMultipart(attach2Method, "portrait.jpg", portrait);
HttpResponse attach2Code = conn.execute(attach2Method);
assertEquals(200, attach2Code.getStatusLine().getStatusCode());
EntityUtils.consume(attach2Code.getEntity());
// load the attachments
URI loadUri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).path("attachments").build();
HttpGet loadMethod = conn.createGet(loadUri, MediaType.APPLICATION_JSON, true);
HttpResponse loadResponse = conn.execute(loadMethod);
assertEquals(200, loadResponse.getStatusLine().getStatusCode());
InputStream loadBody = loadResponse.getEntity().getContent();
List<FileVO> files = parseFileArray(loadBody);
assertNotNull(files);
assertEquals(2, files.size());
conn.shutdown();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class GroupFoldersTest method testCreateFoldersWithSpecialCharacter.
// @Test not working -> Jersey ignore the request and return 200 (why?)
public void testCreateFoldersWithSpecialCharacter() throws IOException, URISyntaxException {
assertTrue(conn.login("rest-one", "A6B7C8"));
URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/New_folder_1_1/New_folder_1 1 2").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
FileVO file = conn.parse(response, FileVO.class);
assertNotNull(file);
}
Aggregations