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;
}
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;
}
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());
}
Aggregations