use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class UserMgmtTest method testUserGroupFolder.
@Test
public void testUserGroupFolder() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("folders").path("group").path(g2.getKey().toString()).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> folders = parseFileArray(body);
assertNotNull(folders);
assertFalse(folders.isEmpty());
// private and public
assertEquals(1, folders.size());
FileVO portrait = folders.get(0);
assertEquals("portrait.jpg", portrait.getTitle());
conn.shutdown();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class UserMgmtTest method testUserBCCourseNodeFolder.
@Test
public void testUserBCCourseNodeFolder() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("folders").path("course").path(demoCourse.getResourceableId().toString()).path(demoBCCourseNode.getIdent()).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> folders = parseFileArray(body);
assertNotNull(folders);
assertFalse(folders.isEmpty());
// private and public
assertEquals(1, folders.size());
FileVO singlePage = folders.get(0);
assertEquals("singlepage.html", singlePage.getTitle());
conn.shutdown();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class ForumTest method testReplyWithTwoAttachments.
@Test
public void testReplyWithTwoAttachments() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
ReplyVO vo = new ReplyVO();
vo.setTitle("Reply with attachment");
vo.setBody("Reply with attachment body");
File64VO[] files = new File64VO[2];
// upload portrait
InputStream portraitStream = CoursesElementsTest.class.getResourceAsStream("portrait.jpg");
assertNotNull(portraitStream);
byte[] portraitBytes = IOUtils.toByteArray(portraitStream);
byte[] portrait64 = Base64.encodeBase64(portraitBytes, true);
files[0] = new File64VO("portrait64.jpg", new String(portrait64));
// upload single page
InputStream indexStream = ForumTest.class.getResourceAsStream("singlepage.html");
assertNotNull(indexStream);
byte[] indexBytes = IOUtils.toByteArray(indexStream);
byte[] index64 = Base64.encodeBase64(indexBytes, true);
files[1] = new File64VO("singlepage64.html", new String(index64));
vo.setAttachments(files);
URI uri = getForumUriBuilder().path("posts").path(m1.getKey().toString()).build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, vo);
method.addHeader("Accept-Language", "en");
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
MessageVO message = conn.parse(response, MessageVO.class);
assertNotNull(message);
assertNotNull(message.getAttachments());
assertEquals(2, message.getAttachments().length);
for (FileVO attachment : message.getAttachments()) {
String title = attachment.getTitle();
assertNotNull(title);
String href = attachment.getHref();
URI attachmentUri = new URI(href);
HttpGet getAttachment = conn.createGet(attachmentUri, "*/*", true);
HttpResponse attachmentCode = conn.execute(getAttachment);
assertEquals(200, attachmentCode.getStatusLine().getStatusCode());
EntityUtils.consume(attachmentCode.getEntity());
}
// 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);
// check if the single page exists
VFSItem uploadedPage = container.resolve("singlepage64.html");
assertNotNull(uploadedPage);
assertTrue(uploadedPage instanceof VFSLeaf);
conn.shutdown();
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class GroupFoldersTest method testCreateFoldersWithSpecialCharacter2.
@Test
public void testCreateFoldersWithSpecialCharacter2() 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/").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("foldername", "New folder 1 2 3").build();
method.setEntity(entity);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
FileVO file = conn.parse(response, FileVO.class);
assertNotNull(file);
assertNotNull(file.getHref());
assertNotNull(file.getTitle());
assertEquals("New folder 1 2 3", file.getTitle());
}
use of org.olat.restapi.support.vo.FileVO in project openolat by klemens.
the class GroupFoldersTest method testGetSubFolder.
@Test
public void testGetSubFolder() throws IOException, URISyntaxException {
// create some sub folders
CollaborationTools collabTools1 = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(g1);
String folderRelPath = collabTools1.getFolderRelPath();
OlatRootFolderImpl folder = new OlatRootFolderImpl(folderRelPath, null);
VFSContainer newFolder1 = folder.createChildContainer("New folder 1");
if (newFolder1 == null) {
newFolder1 = (VFSContainer) folder.resolve("New folder 1");
}
assertNotNull(newFolder1);
VFSContainer newFolder11 = newFolder1.createChildContainer("New folder 1_1");
if (newFolder11 == null) {
newFolder11 = (VFSContainer) newFolder1.resolve("New folder 1_1");
}
assertNotNull(newFolder11);
assertTrue(conn.login("rest-one", "A6B7C8"));
// get root folder
URI request0 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/").build();
HttpGet method0 = conn.createGet(request0, MediaType.APPLICATION_JSON, true);
HttpResponse code0 = conn.execute(method0);
assertEquals(200, code0.getStatusLine().getStatusCode());
InputStream body0 = code0.getEntity().getContent();
assertNotNull(body0);
List<FileVO> fileVos0 = parseFileArray(body0);
assertNotNull(fileVos0);
assertEquals(1, fileVos0.size());
// get sub folder
URI request1 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1").build();
HttpGet method1 = conn.createGet(request1, MediaType.APPLICATION_JSON, true);
HttpResponse code1 = conn.execute(method1);
assertEquals(200, code1.getStatusLine().getStatusCode());
InputStream body1 = code1.getEntity().getContent();
assertNotNull(body1);
List<FileVO> fileVos1 = parseFileArray(body1);
assertNotNull(fileVos1);
assertEquals(1, fileVos1.size());
// get sub folder by link
FileVO fileVO = fileVos1.get(0);
URI fileUri = new URI(fileVO.getHref());
HttpGet brutMethod = conn.createGet(fileUri, "*/*", true);
brutMethod.addHeader("Accept", MediaType.APPLICATION_JSON);
HttpResponse codeBrut = conn.execute(brutMethod);
assertEquals(200, codeBrut.getStatusLine().getStatusCode());
EntityUtils.consume(codeBrut.getEntity());
// get sub sub folder
URI request2 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/New_folder_1_1").build();
HttpGet method2 = conn.createGet(request2, MediaType.APPLICATION_JSON, true);
HttpResponse code2 = conn.execute(method2);
assertEquals(200, code2.getStatusLine().getStatusCode());
InputStream body2 = code2.getEntity().getContent();
assertNotNull(body2);
EntityUtils.consume(code2.getEntity());
// get sub folder with end /
URI request3 = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/folder/New_folder_1/").build();
HttpGet method3 = conn.createGet(request3, MediaType.APPLICATION_JSON, true);
HttpResponse code3 = conn.execute(method3);
assertEquals(200, code3.getStatusLine().getStatusCode());
InputStream body3 = code3.getEntity().getContent();
assertNotNull(body3);
List<FileVO> fileVos3 = parseFileArray(body3);
assertNotNull(fileVos3);
assertEquals(1, fileVos3.size());
}
Aggregations