Search in sources :

Example 1 with FeedFile

use of de.danoeh.antennapod.model.feed.FeedFile in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method setupFeedFile.

private FeedFileImpl setupFeedFile(String downloadUrl, String title, boolean deleteExisting) {
    FeedFileImpl feedfile = new FeedFileImpl(downloadUrl);
    String fileUrl = new File(destDir, title).getAbsolutePath();
    File file = new File(fileUrl);
    if (deleteExisting) {
        Log.d(TAG, "Deleting file: " + file.delete());
    }
    feedfile.setFile_url(fileUrl);
    return feedfile;
}
Also used : File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile)

Example 2 with FeedFile

use of de.danoeh.antennapod.model.feed.FeedFile in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method download.

private Downloader download(String url, String title, boolean expectedResult, boolean deleteExisting, String username, String password, boolean deleteOnFail) {
    FeedFile feedFile = setupFeedFile(url, title, deleteExisting);
    DownloadRequest request = new DownloadRequest(feedFile.getFile_url(), url, title, 0, feedFile.getTypeAsInt(), username, password, deleteOnFail, null, false);
    Downloader downloader = new HttpDownloader(request);
    downloader.call();
    DownloadStatus status = downloader.getResult();
    assertNotNull(status);
    assertEquals(expectedResult, status.isSuccessful());
    assertTrue(status.isDone());
    // the file should not exist if the download has failed and deleteExisting was true
    assertTrue(!deleteExisting || new File(feedFile.getFile_url()).exists() == expectedResult);
    return downloader;
}
Also used : HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile)

Example 3 with FeedFile

use of de.danoeh.antennapod.model.feed.FeedFile in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method testCancel.

@Test
public void testCancel() {
    final String url = httpServer.getBaseUrl() + "/delay/3";
    FeedFileImpl feedFile = setupFeedFile(url, "delay", true);
    final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt(), null, null, true, null, false));
    Thread t = new Thread() {

        @Override
        public void run() {
            downloader.call();
        }
    };
    t.start();
    downloader.cancel();
    try {
        t.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    DownloadStatus result = downloader.getResult();
    assertTrue(result.isDone());
    assertFalse(result.isSuccessful());
    assertTrue(result.isCancelled());
    assertFalse(new File(feedFile.getFile_url()).exists());
}
Also used : HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

FeedFile (de.danoeh.antennapod.model.feed.FeedFile)3 File (java.io.File)3 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)2 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)2 Downloader (de.danoeh.antennapod.core.service.download.Downloader)2 HttpDownloader (de.danoeh.antennapod.core.service.download.HttpDownloader)2 LargeTest (androidx.test.filters.LargeTest)1 Test (org.junit.Test)1