Search in sources :

Example 21 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class AuxParserTest method duplicateBibDatabaseConfiguration.

@Test
public void duplicateBibDatabaseConfiguration() throws URISyntaxException, IOException {
    InputStream originalStream = AuxParserTest.class.getResourceAsStream("config.bib");
    File auxFile = Paths.get(AuxParserTest.class.getResource("paper.aux").toURI()).toFile();
    try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
        ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
        AuxParser auxParser = new AuxParser(auxFile.getAbsolutePath(), result.getDatabase());
        AuxParserResult auxResult = auxParser.parse();
        BibDatabase db = auxResult.getGeneratedBibDatabase();
        assertEquals(Optional.of("\"Maintained by \" # maintainer"), db.getPreamble());
        assertEquals(1, db.getStringCount());
    }
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) File(java.io.File) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 22 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class AuxParserTest method testNestedAux.

@Test
public void testNestedAux() throws URISyntaxException, IOException {
    InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
    File auxFile = Paths.get(AuxParserTest.class.getResource("nested.aux").toURI()).toFile();
    try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
        ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
        AuxParser auxParser = new AuxParser(auxFile.getAbsolutePath(), result.getDatabase());
        AuxParserResult auxResult = auxParser.parse();
        assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
        assertEquals(0, auxResult.getUnresolvedKeysCount());
        BibDatabase newDB = auxResult.getGeneratedBibDatabase();
        assertEquals(2, newDB.getEntries().size());
        assertEquals(2, auxResult.getResolvedKeysCount());
        assertEquals(2, auxResult.getFoundKeysInAux());
        assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(), auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
        assertEquals(0, auxResult.getCrossRefEntriesCount());
    }
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) File(java.io.File) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 23 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class AuxParserTest method testCrossRef.

@Test
public void testCrossRef() throws URISyntaxException, IOException {
    InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
    File auxFile = Paths.get(AuxParserTest.class.getResource("crossref.aux").toURI()).toFile();
    try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
        ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
        AuxParser auxParser = new AuxParser(auxFile.getAbsolutePath(), result.getDatabase());
        AuxParserResult auxResult = auxParser.parse();
        assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
        assertEquals(2, auxResult.getUnresolvedKeysCount());
        BibDatabase newDB = auxResult.getGeneratedBibDatabase();
        assertEquals(4, newDB.getEntries().size());
        assertEquals(3, auxResult.getResolvedKeysCount());
        assertEquals(4, auxResult.getFoundKeysInAux());
        assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(), auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
        assertEquals(1, auxResult.getCrossRefEntriesCount());
    }
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) File(java.io.File) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 24 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class AuxParserTest method testFileNotFound.

@Test
public void testFileNotFound() {
    AuxParser auxParser = new AuxParser("unknownfile.bib", new BibDatabase());
    AuxParserResult auxResult = auxParser.parse();
    assertFalse(auxResult.getGeneratedBibDatabase().hasEntries());
    assertEquals(0, auxResult.getUnresolvedKeysCount());
    BibDatabase newDB = auxResult.getGeneratedBibDatabase();
    assertEquals(0, newDB.getEntries().size());
    assertEquals(0, auxResult.getResolvedKeysCount());
    assertEquals(0, auxResult.getFoundKeysInAux());
    assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(), auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
    assertEquals(0, auxResult.getCrossRefEntriesCount());
}
Also used : BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 25 with BibDatabase

use of org.jabref.model.database.BibDatabase 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)

Aggregations

BibDatabase (org.jabref.model.database.BibDatabase)88 BibEntry (org.jabref.model.entry.BibEntry)60 Test (org.junit.Test)44 ParserResult (org.jabref.logic.importer.ParserResult)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)15 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)15 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)13 MetaData (org.jabref.model.metadata.MetaData)12 IOException (java.io.IOException)10 Defaults (org.jabref.model.Defaults)9 Before (org.junit.Before)9 File (java.io.File)8 InputStreamReader (java.io.InputStreamReader)8 InputStream (java.io.InputStream)7 PropertyVetoException (com.sun.star.beans.PropertyVetoException)6 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)6 WrappedTargetException (com.sun.star.lang.WrappedTargetException)6 LinkedHashMap (java.util.LinkedHashMap)5 BasePanel (org.jabref.gui.BasePanel)5