Search in sources :

Example 21 with BibtexParser

use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.

the class BibtexDatabaseWriterTest method roundtripWithUnknownMetaData.

@Test
public void roundtripWithUnknownMetaData() throws Exception {
    Path testBibtexFile = Paths.get("src/test/resources/testbib/unknownMetaData.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 22 with BibtexParser

use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.

the class BibDatabaseTestsWithFiles method resolveStrings.

@Test
public void resolveStrings() throws IOException {
    try (FileInputStream stream = new FileInputStream("src/test/resources/org/jabref/util/twente.bib");
        InputStreamReader fr = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
        ParserResult result = new BibtexParser(importFormatPreferences).parse(fr);
        BibDatabase db = result.getDatabase();
        assertEquals("Arvind", db.resolveForStrings("#Arvind#"));
        assertEquals("Patterson, David", db.resolveForStrings("#Patterson#"));
        assertEquals("Arvind and Patterson, David", db.resolveForStrings("#Arvind# and #Patterson#"));
        // Strings that are not found return just the given string.
        assertEquals("#unknown#", db.resolveForStrings("#unknown#"));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) BibDatabase(org.jabref.model.database.BibDatabase) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 23 with BibtexParser

use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.

the class DatabaseFileLookupTest method setUp.

@Before
public void setUp() throws Exception {
    try (FileInputStream stream = new FileInputStream(ImportDataTest.UNLINKED_FILES_TEST_BIB);
        InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
        ParserResult result = new BibtexParser(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)).parse(reader);
        database = result.getDatabase();
        entries = database.getEntries();
        entry1 = database.getEntryByKey("entry1").get();
        entry2 = database.getEntryByKey("entry2").get();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 24 with BibtexParser

use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.

the class LayoutTest method bibtexString2BibtexEntry.

public static BibEntry bibtexString2BibtexEntry(String s) throws IOException {
    ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(s));
    Collection<BibEntry> c = result.getDatabase().getEntries();
    Assert.assertEquals(1, c.size());
    return c.iterator().next();
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) StringReader(java.io.StringReader)

Example 25 with BibtexParser

use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.

the class OOBibStyleTest method testGetCitationMarker.

@Test
public void testGetCitationMarker() throws IOException {
    Path testBibtexFile = Paths.get("src/test/resources/testbib/complex.bib");
    ParserResult result = new BibtexParser(importFormatPreferences).parse(Importer.getReader(testBibtexFile, StandardCharsets.UTF_8));
    OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
    Map<BibEntry, BibDatabase> entryDBMap = new HashMap<>();
    BibDatabase db = result.getDatabase();
    for (BibEntry entry : db.getEntries()) {
        entryDBMap.put(entry, db);
    }
    BibEntry entry = db.getEntryByKey("1137631").get();
    assertEquals("[Boström et al., 2006]", style.getCitationMarker(Arrays.asList(entry), entryDBMap, true, null, null));
    assertEquals("Boström et al. [2006]", style.getCitationMarker(Arrays.asList(entry), entryDBMap, false, null, new int[] { 3 }));
    assertEquals("[Boström, Wäyrynen, Bodén, Beznosov & Kruchten, 2006]", style.getCitationMarker(Arrays.asList(entry), entryDBMap, true, null, new int[] { 5 }));
}
Also used : Path(java.nio.file.Path) ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) HashMap(java.util.HashMap) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Aggregations

BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)43 ParserResult (org.jabref.logic.importer.ParserResult)38 Test (org.junit.Test)28 BibEntry (org.jabref.model.entry.BibEntry)27 StringReader (java.io.StringReader)20 BibDatabase (org.jabref.model.database.BibDatabase)13 InputStreamReader (java.io.InputStreamReader)12 StringWriter (java.io.StringWriter)12 File (java.io.File)8 InputStream (java.io.InputStream)7 Path (java.nio.file.Path)7 Charset (java.nio.charset.Charset)6 Defaults (org.jabref.model.Defaults)6 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)6 Scanner (java.util.Scanner)5 IOException (java.io.IOException)4 FileInputStream (java.io.FileInputStream)3 Collection (java.util.Collection)3 Optional (java.util.Optional)3 FetcherException (org.jabref.logic.importer.FetcherException)3