Search in sources :

Example 26 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class MoveFilesCleanupTest method movesFileFromSubfolder.

@Test
public void movesFileFromSubfolder() throws IOException {
    File subfolder = bibFolder.newFolder();
    File fileBefore = new File(subfolder, "test.pdf");
    assertTrue(fileBefore.createNewFile());
    assertTrue(new File(subfolder, "test.pdf").exists());
    LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
    entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
    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(new LinkedFile("", fileAfter.getName(), ""))), entry.getField("file"));
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) File(java.io.File) LinkedFile(org.jabref.model.entry.LinkedFile) Test(org.junit.Test)

Example 27 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class RenamePdfCleanupTest method cleanupSingleField.

@Test
public void cleanupSingleField() 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, fileField);
    cleanup.cleanup(entry);
    LinkedFile newFileField = new LinkedFile("", "Toot - test title.pdf", "PDF");
    assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) Test(org.junit.Test)

Example 28 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class RenamePdfCleanupTest method cleanupGetTargetFilename.

@Test
public void cleanupGetTargetFilename() throws IOException {
    String fileNamePattern = "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}";
    testFolder.newFile("Toot.pdf");
    LinkedFile fileField = new LinkedFile("", "Toot.pdf", "PDF");
    RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, layoutFormatterPreferences, fileDirPrefs);
    entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
    entry.setField("title", "test title");
    assertEquals("Toot - test title.pdf", cleanup.getTargetFileName(fileField, entry));
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) Test(org.junit.Test)

Aggregations

LinkedFile (org.jabref.model.entry.LinkedFile)28 Test (org.junit.Test)13 File (java.io.File)11 Path (java.nio.file.Path)8 FieldChange (org.jabref.model.FieldChange)6 ArrayList (java.util.ArrayList)5 BibEntry (org.jabref.model.entry.BibEntry)5 HashMap (java.util.HashMap)3 List (java.util.List)3 ExternalFileType (org.jabref.gui.externalfiletype.ExternalFileType)3 UnknownExternalFileType (org.jabref.gui.externalfiletype.UnknownExternalFileType)3 FileListEntry (org.jabref.gui.filelist.FileListEntry)3 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)3 IOException (java.io.IOException)2 Paths (java.nio.file.Paths)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 FileFieldParser (org.jabref.model.entry.FileFieldParser)2