Search in sources :

Example 6 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class TestDownloads method test002GetDownloadInfo.

/**
 * Tests retrieving info about a download node
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/private/alfresco/versions/1/downloads/<download_id>}
 */
@Test
public void test002GetDownloadInfo() throws Exception {
    Download download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableFolderId1, zippableFolderId2_InFolder1, zippableDocId4_InFolder2);
    // test retrieving information about an ongoing download
    assertInProgressDownload(download, 4, 52);
    // test retrieving information about a finished download
    assertDoneDownload(download, 4, 52);
    // test retrieving the status of a cancelled download
    cancelWithRetry(() -> {
        Download downloadToBeCancelled = createDownload(HttpServletResponse.SC_ACCEPTED, zippableFolderId1, zippableDocId3_InFolder1);
        cancel(downloadToBeCancelled.getId());
        assertCancelledDownload(downloadToBeCancelled, 3, 39);
    });
}
Also used : Download(org.alfresco.rest.api.model.Download) Test(org.junit.Test)

Example 7 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class TestDownloads method test004GetDownloadContent.

/**
 * Tests downloading the content of a download node(a zip) using the /nodes API:
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/content}
 */
@Test
public void test004GetDownloadContent() throws Exception {
    // test downloading the content of a 1 file zip
    Download download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1);
    assertDoneDownload(download, 1, 13);
    HttpResponse response = downloadContent(download);
    ZipInputStream zipStream = getZipStreamFromResponse(response);
    ZipEntry zipEntry = zipStream.getNextEntry();
    assertEquals("Zip entry name is not correct", ZIPPABLE_DOC1_NAME, zipEntry.getName());
    assertTrue("Zip entry size is not correct", zipEntry.getCompressedSize() <= 13);
    assertTrue("No more entries should be in this zip", zipStream.getNextEntry() == null);
    zipStream.close();
    Map<String, String> responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    assertEquals(format("attachment; filename=\"%s\"; filename*=UTF-8''%s", ZIPPABLE_DOC1_NAME + DEFAULT_ARCHIVE_EXTENSION, ZIPPABLE_DOC1_NAME + DEFAULT_ARCHIVE_EXTENSION), responseHeaders.get("Content-Disposition"));
    // test downloading the content of a multiple file zip
    download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableFolderId1, zippableDocId3_InFolder1);
    assertDoneDownload(download, 3, 39);
    response = downloadContent(download);
    zipStream = getZipStreamFromResponse(response);
    assertEquals("Zip entry name is not correct", FOLDER1_NAME + "/", zipStream.getNextEntry().getName());
    assertEquals("Zip entry name is not correct", FOLDER1_NAME + "/" + DOC3_NAME, zipStream.getNextEntry().getName());
    assertEquals("Zip entry name is not correct", FOLDER1_NAME + "/" + SUB_FOLDER1_NAME + "/", zipStream.getNextEntry().getName());
    assertEquals("Zip entry name is not correct", FOLDER1_NAME + "/" + SUB_FOLDER1_NAME + "/" + DOC4_NAME, zipStream.getNextEntry().getName());
    assertEquals("Zip entry name is not correct", DOC3_NAME, zipStream.getNextEntry().getName());
    assertTrue("No more entries should be in this zip", zipStream.getNextEntry() == null);
    zipStream.close();
    responseHeaders = response.getHeaders();
    assertNotNull(responseHeaders);
    assertEquals(format("attachment; filename=\"%s\"; filename*=UTF-8''%s", DEFAULT_ARCHIVE_NAME, DEFAULT_ARCHIVE_NAME), responseHeaders.get("Content-Disposition"));
    // test download the content of a zip which has a secondary child
    download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1, zippableFolderId3);
    assertDoneDownload(download, 2, 26);
    response = downloadContent(download);
    zipStream = getZipStreamFromResponse(response);
    assertEquals("Zip entry name is not correct", ZIPPABLE_DOC1_NAME, zipStream.getNextEntry().getName());
    assertEquals("Zip entry name is not correct", FOLDER3_NAME + "/", zipStream.getNextEntry().getName());
    assertEquals("Zip entry name is not correct", FOLDER3_NAME + "/" + ZIPPABLE_DOC1_NAME, zipStream.getNextEntry().getName());
    assertTrue("No more entries should be in this zip", zipStream.getNextEntry() == null);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Download(org.alfresco.rest.api.model.Download) Test(org.junit.Test)

Example 8 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class TestDownloads method createDownload.

private Download createDownload(int expectedStatus, String... nodeIds) throws Exception {
    Download downloadRequest = new Download();
    downloadRequest.setNodeIds(Arrays.asList(nodeIds));
    setRequestContext(user1);
    Download download = create(downloadRequest, expectedStatus);
    return download;
}
Also used : Download(org.alfresco.rest.api.model.Download)

Example 9 with Download

use of org.alfresco.rest.api.model.Download in project alfresco-remote-api by Alfresco.

the class TestDownloads method test005DeleteDownloadNode.

/**
 * Tests deleting a download node using the /nodes API:
 *
 * <p>DELETE:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>}
 */
@Test
public void test005DeleteDownloadNode() throws Exception {
    // test deleting a download node
    Download download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1);
    assertDoneDownload(download, 1, 13);
    deleteNode(download.getId(), true, HttpServletResponse.SC_NO_CONTENT);
    getDownload(download.getId(), HttpServletResponse.SC_NOT_FOUND);
    // test user2 deleting a download node created by user1
    download = createDownload(HttpServletResponse.SC_ACCEPTED, zippableDocId1);
    assertDoneDownload(download, 1, 13);
    setRequestContext(user2);
    deleteNode(download.getId(), true, HttpServletResponse.SC_FORBIDDEN);
    assertDoneDownload(download, 1, 13);
}
Also used : Download(org.alfresco.rest.api.model.Download) Test(org.junit.Test)

Aggregations

Download (org.alfresco.rest.api.model.Download)9 Test (org.junit.Test)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)1 DownloadStatus (org.alfresco.service.cmr.download.DownloadStatus)1