Search in sources :

Example 11 with Defaults

use of org.jabref.model.Defaults 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 12 with Defaults

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

the class IntegrityCheckTest method createContext.

private BibDatabaseContext createContext(String field, String value, MetaData metaData) {
    BibEntry entry = new BibEntry();
    entry.setField(field, value);
    BibDatabase bibDatabase = new BibDatabase();
    bibDatabase.insertEntry(entry);
    return new BibDatabaseContext(bibDatabase, metaData, new Defaults());
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Defaults(org.jabref.model.Defaults) BibDatabase(org.jabref.model.database.BibDatabase) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 13 with Defaults

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

the class SynchronizationTestSimulator method setUp.

@Before
public void setUp() throws SQLException, DatabaseNotSupportedException, InvalidDBMSConnectionPropertiesException {
    this.dbmsConnection = TestConnector.getTestDBMSConnection(dbmsType);
    GlobalBibtexKeyPattern pattern = GlobalBibtexKeyPattern.fromPattern("[auth][year]");
    clientContextA = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX), DatabaseLocation.SHARED, ',', pattern);
    clientContextA.getDBMSSynchronizer().openSharedDatabase(dbmsConnection);
    clientContextB = new BibDatabaseContext(new Defaults(BibDatabaseMode.BIBTEX), DatabaseLocation.SHARED, ',', pattern);
    clientContextB.getDBMSSynchronizer().openSharedDatabase(dbmsConnection);
    eventListenerB = new SynchronizationTestEventListener();
    clientContextB.getDBMSSynchronizer().registerListener(eventListenerB);
}
Also used : GlobalBibtexKeyPattern(org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern) Defaults(org.jabref.model.Defaults) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Before(org.junit.Before)

Example 14 with Defaults

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

the class IntegrityCheckTest method createContext.

private BibDatabaseContext createContext(String field, String value, String type) {
    BibEntry entry = new BibEntry();
    entry.setField(field, value);
    entry.setType(type);
    BibDatabase bibDatabase = new BibDatabase();
    bibDatabase.insertEntry(entry);
    return new BibDatabaseContext(bibDatabase, new Defaults());
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Defaults(org.jabref.model.Defaults) BibDatabase(org.jabref.model.database.BibDatabase) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext)

Example 15 with Defaults

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

the class IntegrityCheckTest method testEntryIsUnchangedAfterChecks.

@Test
public void testEntryIsUnchangedAfterChecks() {
    BibEntry entry = new BibEntry();
    // populate with all known fields
    for (String fieldName : InternalBibtexFields.getAllPublicAndInternalFieldNames()) {
        entry.setField(fieldName, UUID.randomUUID().toString());
    }
    // add a random field
    entry.setField(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    // duplicate entry
    BibEntry clonedEntry = (BibEntry) entry.clone();
    BibDatabase bibDatabase = new BibDatabase();
    bibDatabase.insertEntry(entry);
    BibDatabaseContext context = new BibDatabaseContext(bibDatabase, new Defaults());
    new IntegrityCheck(context, mock(FileDirectoryPreferences.class), createBibtexKeyPatternPreferences(), new JournalAbbreviationRepository(new Abbreviation("IEEE Software", "IEEE SW"))).checkBibtexDatabase();
    assertEquals(clonedEntry, entry);
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) BibEntry(org.jabref.model.entry.BibEntry) Defaults(org.jabref.model.Defaults) JournalAbbreviationRepository(org.jabref.logic.journals.JournalAbbreviationRepository) BibDatabase(org.jabref.model.database.BibDatabase) 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