Search in sources :

Example 6 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class CleanupWorkerTest method setUp.

@Before
public void setUp() throws IOException {
    pdfFolder = bibFolder.newFolder();
    MetaData metaData = new MetaData();
    metaData.setDefaultFileDirectory(pdfFolder.getAbsolutePath());
    BibDatabaseContext context = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
    context.setDatabaseFile(bibFolder.newFile("test.bib"));
    FileDirectoryPreferences fileDirPrefs = mock(FileDirectoryPreferences.class);
    //Biblocation as Primary overwrites all other dirs
    when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true);
    worker = new CleanupWorker(context, new CleanupPreferences("\\bibtexkey", //empty fileDirPattern for backwards compatibility
    "", mock(LayoutFormatterPreferences.class), fileDirPrefs));
}
Also used : FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Example 7 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class RenamePdfCleanupTest method setUp.

@Before
public void setUp() throws Exception {
    MetaData metaData = new MetaData();
    context = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
    context.setDatabaseFile(testFolder.newFile("test.bib"));
    fileDirPrefs = mock(FileDirectoryPreferences.class);
    //Set Biblocation as Primary Directory, otherwise the tmp folders won't be cleaned up correctly
    when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(true);
    entry = new BibEntry();
    entry.setCiteKey("Toot");
    layoutFormatterPreferences = mock(LayoutFormatterPreferences.class, Answers.RETURNS_DEEP_STUBS);
}
Also used : FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) BibEntry(org.jabref.model.entry.BibEntry) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Example 8 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class MoveFilesCleanupTest method setUp.

@Before
public void setUp() throws IOException {
    MetaData metaData = new MetaData();
    pdfFolder = bibFolder.newFolder();
    metaData.setDefaultFileDirectory(pdfFolder.getAbsolutePath());
    databaseContext = new BibDatabaseContext(new BibDatabase(), metaData, new Defaults());
    databaseContext.setDatabaseFile(bibFolder.newFile("test.bib"));
    entry = new BibEntry();
    entry.setCiteKey("Toot");
    entry.setField("title", "test title");
    fileDirPrefs = mock(FileDirectoryPreferences.class);
    //Biblocation as Primary overwrites all other dirs, therefore we set it to false here
    when(fileDirPrefs.isBibLocationAsPrimary()).thenReturn(false);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Example 9 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class BibtexDatabaseWriterTest method roundtripWithUserComment.

@Test
public void roundtripWithUserComment() throws Exception {
    Path testBibtexFile = Paths.get("src/test/resources/testbib/bibWithUserComments.bib");
    Charset encoding = StandardCharsets.UTF_8;
    ParserResult result = new BibtexParser(importFormatPreferences).parse(Importer.getReader(testBibtexFile, encoding));
    SavePreferences preferences = new SavePreferences().withEncoding(encoding).withSaveInOriginalOrder(true);
    BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData(), new Defaults(BibDatabaseMode.BIBTEX));
    StringSaveSession session = databaseWriter.savePartOfDatabase(context, result.getDatabase().getEntries(), preferences);
    try (Scanner scanner = new Scanner(testBibtexFile, encoding.name())) {
        assertEquals(scanner.useDelimiter("\\A").next(), session.getStringValue());
    }
}
Also used : Path(java.nio.file.Path) ParserResult(org.jabref.logic.importer.ParserResult) Scanner(java.util.Scanner) Defaults(org.jabref.model.Defaults) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) Charset(java.nio.charset.Charset) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Test(org.junit.Test)

Example 10 with Defaults

use of org.jabref.model.Defaults in project jabref by JabRef.

the class BibtexDatabaseWriterTest method roundtrip.

@Test
public void roundtrip() throws Exception {
    Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib");
    Charset encoding = StandardCharsets.UTF_8;
    ParserResult result = new BibtexParser(importFormatPreferences).parse(Importer.getReader(testBibtexFile, encoding));
    SavePreferences preferences = new SavePreferences().withEncoding(encoding).withSaveInOriginalOrder(true);
    BibDatabaseContext context = new BibDatabaseContext(result.getDatabase(), result.getMetaData(), new Defaults(BibDatabaseMode.BIBTEX));
    StringSaveSession session = databaseWriter.savePartOfDatabase(context, result.getDatabase().getEntries(), preferences);
    try (Scanner scanner = new Scanner(testBibtexFile, encoding.name())) {
        assertEquals(scanner.useDelimiter("\\A").next(), session.getStringValue());
    }
}
Also used : Path(java.nio.file.Path) ParserResult(org.jabref.logic.importer.ParserResult) Scanner(java.util.Scanner) Defaults(org.jabref.model.Defaults) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) Charset(java.nio.charset.Charset) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Test(org.junit.Test)

Aggregations

Defaults (org.jabref.model.Defaults)24 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)24 BibDatabase (org.jabref.model.database.BibDatabase)9 ParserResult (org.jabref.logic.importer.ParserResult)8 BibEntry (org.jabref.model.entry.BibEntry)7 Test (org.junit.Test)7 Charset (java.nio.charset.Charset)6 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)6 MetaData (org.jabref.model.metadata.MetaData)6 Path (java.nio.file.Path)5 Scanner (java.util.Scanner)5 BibtexDatabaseWriter (org.jabref.logic.exporter.BibtexDatabaseWriter)5 SavePreferences (org.jabref.logic.exporter.SavePreferences)5 Before (org.junit.Before)5 FileSaveSession (org.jabref.logic.exporter.FileSaveSession)3 SaveException (org.jabref.logic.exporter.SaveException)3 SaveSession (org.jabref.logic.exporter.SaveSession)3 FileDirectoryPreferences (org.jabref.model.metadata.FileDirectoryPreferences)3 IOException (java.io.IOException)2 JabRefFrame (org.jabref.gui.JabRefFrame)2