use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class CleanupWorkerTest method cleanupRenamePdfRenamesRelativeFile.
@Test
public void cleanupRenamePdfRenamesRelativeFile() throws IOException {
CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.RENAME_PDF);
File tempFile = bibFolder.newFile();
BibEntry entry = new BibEntry();
entry.setCiteKey("Toot");
LinkedFile fileField = new LinkedFile("", tempFile.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
worker.cleanup(preset, entry);
LinkedFile newFileField = new LinkedFile("", "Toot.tmp", "");
Assert.assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class CleanupWorkerTest method cleanupMoveFilesMovesFileFromSubfolder.
@Test
public void cleanupMoveFilesMovesFileFromSubfolder() throws IOException {
CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.MOVE_PDF);
File subfolder = bibFolder.newFolder();
File tempFile = new File(subfolder, "test.pdf");
tempFile.createNewFile();
BibEntry entry = new BibEntry();
LinkedFile fileField = new LinkedFile("", tempFile.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
worker.cleanup(preset, entry);
LinkedFile newFileField = new LinkedFile("", tempFile.getName(), "");
Assert.assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class RenamePdfCleanupTest method cleanupRenamePdfRenamesWithMultipleFiles.
@Test
public void cleanupRenamePdfRenamesWithMultipleFiles() throws IOException {
String fileNamePattern = "\\bibtexkey - \\title";
File tempFile = testFolder.newFile("Toot.tmp");
entry.setField("title", "test title");
entry.setField("file", FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), new LinkedFile("", tempFile.getAbsolutePath(), ""), new LinkedFile("", "", ""))));
RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, mock(LayoutFormatterPreferences.class), fileDirPrefs);
cleanup.cleanup(entry);
assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), new LinkedFile("", "Toot - test title.tmp", ""), new LinkedFile("", "", "")))), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class RenamePdfCleanupTest method cleanupRenamePdfRenamesFileInSameFolder.
@Test
public void cleanupRenamePdfRenamesFileInSameFolder() throws IOException {
String fileNamePattern = "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}";
testFolder.newFile("Toot.pdf");
LinkedFile fileField = new LinkedFile("", "Toot.pdf", "PDF");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
entry.setField("title", "test title");
RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, layoutFormatterPreferences, fileDirPrefs);
cleanup.cleanup(entry);
LinkedFile newFileField = new LinkedFile("", "Toot - test title.pdf", "PDF");
assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class MoveFilesCleanupTest method movesFileFromSubfolderMultiple.
@Test
public void movesFileFromSubfolderMultiple() throws IOException {
File subfolder = bibFolder.newFolder();
File fileBefore = new File(subfolder, "test.pdf");
assertTrue(fileBefore.createNewFile());
assertTrue(fileBefore.exists());
LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), fileField, new LinkedFile("", "", ""))));
cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs, mock(LayoutFormatterPreferences.class));
cleanup.cleanup(entry);
assertFalse(fileBefore.exists());
File fileAfter = new File(pdfFolder, "test.pdf");
assertTrue(fileAfter.exists());
assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), new LinkedFile("", fileAfter.getName(), ""), new LinkedFile("", "", "")))), entry.getField("file"));
}
Aggregations