Skip to content

Commit

Permalink
fix(downloader.http): correction on temporary file name
Browse files Browse the repository at this point in the history
  • Loading branch information
davinkevin committed Feb 12, 2016
1 parent e23b95f commit 10b0a10
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ public File getTagetFile (Item item) {
}

logger.info("Doublon sur le fichier en lien avec {} - {}, {}", item.getPodcast().getTitle(), item.getId(), item.getTitle() );
return Files.createTempFile(finalFile.getParent(), FilenameUtils.getBaseName(getItemUrl()) + "-", "." + FilenameUtils.getExtension(getItemUrl()) + temporaryExtension).toFile();
String fileName = finalFile.getFileName().toString();
return Files.createTempFile(finalFile.getParent(), FilenameUtils.getBaseName(fileName) + "-", "." + FilenameUtils.getExtension(fileName) + temporaryExtension).toFile();
} catch (IOException e) {
logger.error("Erreur lors du renommage d'un doublon", e);
logger.error("Error during creation of target file", e);
stopDownload();
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ public void should_handle_exception_during_move() throws MalformedURLException {
public void should_get_the_same_target_file_each_call() throws MalformedURLException {
/* Given */
httpDownloader.setItem(item);
when(itemDownloadManager.getRootfolder()).thenReturn(ROOT_FOLDER);

/* When */
httpDownloader.target = httpDownloader.getTagetFile(item);
Expand All @@ -355,4 +356,36 @@ public void should_handle_duplicate_on_file_name() throws IOException {
/* Then */
assertThat(targetFile).isNotEqualTo(Paths.get(ROOT_FOLDER, podcast.getTitle(), "file.mp4" + TEMPORARY_EXTENSION).toFile());
}

@Test
public void should_handle_error_during_creation_of_temp_file() throws IOException {
/* Given */
podcast.setTitle("bin");
httpDownloader.setItem(item.setUrl("http://foo.bar.com/bash"));

when(itemDownloadManager.getRootfolder()).thenReturn("/");
when(podcastRepository.findOne(eq(podcast.getId()))).thenReturn(podcast);
when(itemRepository.save(any(Item.class))).then(i -> i.getArguments()[0]);

/* When */
File targetFile = httpDownloader.getTagetFile(item);

/* Then */
assertThat(item.getStatus()).isEqualTo(Status.STOPPED);
}

@Test
public void should_save_sync_with_podcast() {
/* Given */
httpDownloader.setItem(item);

doThrow(RuntimeException.class).when(podcastRepository).findOne(anyInt());

/* When */
httpDownloader.saveSyncWithPodcast();

/* Then */
assertThat(httpDownloader.getItem()).isSameAs(item);
verify(itemRepository, never()).save(any(Item.class));
}
}

0 comments on commit 10b0a10

Please sign in to comment.