Search in sources :

Example 26 with FileVO

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 27 with FileVO

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 28 with FileVO

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();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) HttpGet(org.apache.http.client.methods.HttpGet) FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 29 with FileVO

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();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) MessageVO(org.olat.modules.fo.restapi.MessageVO) File(java.io.File) HttpPut(org.apache.http.client.methods.HttpPut) URL(java.net.URL) Test(org.junit.Test)

Example 30 with FileVO

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);
}
Also used : FileVO(org.olat.restapi.support.vo.FileVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut)

Aggregations

FileVO (org.olat.restapi.support.vo.FileVO)34 URI (java.net.URI)26 HttpResponse (org.apache.http.HttpResponse)26 Test (org.junit.Test)24 InputStream (java.io.InputStream)22 HttpGet (org.apache.http.client.methods.HttpGet)22 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 ByteArrayInputStream (java.io.ByteArrayInputStream)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 HttpPut (org.apache.http.client.methods.HttpPut)8 UriBuilder (javax.ws.rs.core.UriBuilder)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 Identity (org.olat.core.id.Identity)4 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)4 MessageVO (org.olat.modules.fo.restapi.MessageVO)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 SharedFolderHandler (org.olat.repository.handlers.SharedFolderHandler)4 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 URL (java.net.URL)2