DsmDownloadTest.java 2.53 KB
Newer Older
敖文武 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
import clients.DsmFileStationClient;
import exeptions.DsmDownloadException;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import requests.DsmAuth;
import requests.filestation.DsmRequestParameters;
import responses.Response;
import responses.filestation.transfert.DsmDownloadResponse;

import java.io.File;
import java.io.IOException;

public class DsmDownloadTest extends DsmTest{

    private final String ROOT_FOLDER = "/homes/testResource";
    private DsmFileStationClient client;
    private File fileToDownload;

    @Rule
    public TemporaryFolder folder= new TemporaryFolder();


    @Before
    public void initTest() throws IOException {
        super.initTest();
        String fileSuccess = "dummy-upload-file"+System.currentTimeMillis()+".txt";
        String content = "success content";

        fileToDownload = Utils.makeFile(folder, content, fileSuccess);
        client = DsmFileStationClient.login(DsmAuth.fromResource("env.properties"));

        client.upload(ROOT_FOLDER, fileToDownload.getAbsolutePath())
                .createParentFolders(true)
                .overwrite(DsmRequestParameters.OverwriteBehaviour.OVERWRITE)
                .call();
    }

    @After
    public void postTest() {
        client.simpleDelete(ROOT_FOLDER).setRecursive(true).call();
    }

    @Test
    public void downloadOneFileAndSuccess() {

       Response<DsmDownloadResponse> response = client.download(ROOT_FOLDER+"/"+fileToDownload.getName(), folder.getRoot().getAbsolutePath()).call();

        Assert.assertNotNull(response);
        Assert.assertTrue(response.isSuccess());
        Assert.assertNotNull(response.getData());
        Assert.assertNotNull(response.getData().getFile());
        Assert.assertTrue(response.getData().getFile().exists());
    }


    @Test(expected = DsmDownloadException.class)
    public void downloadWithoutDestinationPathAndFail() {
        client.download(ROOT_FOLDER+"/"+fileToDownload.getName(), null).call();
    }

    @Test(expected = DsmDownloadException.class)
    public void downloadWithoutSourcePathAndFail() {
        client.download(null, folder.getRoot().getAbsolutePath()).call();
    }

    @Test(expected = DsmDownloadException.class)
    public void downloadFileDoesNotExistShouldFail() {

        client.download(ROOT_FOLDER+"/file55252.txt", folder.getRoot().getAbsolutePath()).call();
    }

    @Test(expected = DsmDownloadException.class)
    public void downloadFileDestinationFolderDoesNotExistShouldFail() {
        client.download(ROOT_FOLDER+"/"+fileToDownload.getName(), "Z:\\").call();
    }
}