Search in sources :

Example 11 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class FieldFormatterCleanupsTest method checkTwoSaveActionsForOneField.

@Test
public void checkTwoSaveActionsForOneField() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("title[lower_case,identity]"));
    FieldFormatterCleanup lowerCaseTitle = new FieldFormatterCleanup("title", new LowerCaseFormatter());
    FieldFormatterCleanup identityInTitle = new FieldFormatterCleanup("title", new IdentityFormatter());
    assertEquals(Arrays.asList(lowerCaseTitle, identityInTitle), actions.getConfiguredActions());
    actions.applySaveActions(entry);
    assertEquals(Optional.of("educational session 1"), entry.getField("title"));
}
Also used : IdentityFormatter(org.jabref.logic.formatter.IdentityFormatter) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 12 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class FieldFormatterCleanupTest method testInternalAllField.

@Test
public void testInternalAllField() throws Exception {
    FieldFormatterCleanup cleanup = new FieldFormatterCleanup(FieldName.INTERNAL_ALL_FIELD, new UpperCaseFormatter());
    cleanup.cleanup(entry);
    Assert.assertEquals(fieldMap.get("title").toUpperCase(), entry.getField("title").get());
    Assert.assertEquals(fieldMap.get("booktitle").toUpperCase(), entry.getField("booktitle").get());
    Assert.assertEquals(fieldMap.get("year").toUpperCase(), entry.getField("year").get());
    Assert.assertEquals(fieldMap.get("month").toUpperCase(), entry.getField("month").get());
    Assert.assertEquals(fieldMap.get("abstract").toUpperCase(), entry.getField("abstract").get());
    Assert.assertEquals(fieldMap.get("doi").toUpperCase(), entry.getField("doi").get());
    Assert.assertEquals(fieldMap.get("issn").toUpperCase(), entry.getField("issn").get());
}
Also used : FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) UpperCaseFormatter(org.jabref.logic.formatter.casechanger.UpperCaseFormatter) Test(org.junit.Test)

Example 13 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class MetaDataSerializerTest method serializeSingleSaveAction.

@Test
public void serializeSingleSaveAction() {
    FieldFormatterCleanups saveActions = new FieldFormatterCleanups(true, Collections.singletonList(new FieldFormatterCleanup("title", new LowerCaseFormatter())));
    metaData.setSaveActions(saveActions);
    Map<String, String> expectedSerialization = new TreeMap<>();
    expectedSerialization.put("saveActions", "enabled;" + OS.NEWLINE + "title[lower_case]" + OS.NEWLINE + ";");
    assertEquals(expectedSerialization, MetaDataSerializer.getSerializedStringMap(metaData, pattern));
}
Also used : FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) TreeMap(java.util.TreeMap) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 14 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class BibtexParserTest method parseRecognizesSaveActionsAfterEntry.

@Test
public void parseRecognizesSaveActionsAfterEntry() throws IOException {
    BibtexParser parser = this.parser;
    ParserResult parserResult = parser.parse(new StringReader("@InProceedings{6055279,\n" + "  Title                    = {Educational session 1},\n" + "  Booktitle                = {Custom Integrated Circuits Conference (CICC), 2011 IEEE},\n" + "  Year                     = {2011},\n" + "  Month                    = {Sept},\n" + "  Pages                    = {1-7},\n" + "  Abstract                 = {Start of the above-titled section of the conference proceedings record.},\n" + "  DOI                      = {10.1109/CICC.2011.6055279},\n" + "  ISSN                     = {0886-5930}\n" + "}\n" + "\n" + "@comment{jabref-meta: saveActions:enabled;title[lower_case]}"));
    FieldFormatterCleanups saveActions = parserResult.getMetaData().getSaveActions().get();
    assertTrue(saveActions.isEnabled());
    assertEquals(Collections.singletonList(new FieldFormatterCleanup("title", new LowerCaseFormatter())), saveActions.getConfiguredActions());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 15 with FieldFormatterCleanup

use of org.jabref.model.cleanup.FieldFormatterCleanup in project jabref by JabRef.

the class BibtexParserTest method integrationTestSaveActions.

@Test
public void integrationTestSaveActions() throws IOException {
    BibtexParser parser = this.parser;
    ParserResult parserResult = parser.parse(new StringReader("@comment{jabref-meta: saveActions:enabled;title[lower_case]}"));
    FieldFormatterCleanups saveActions = parserResult.getMetaData().getSaveActions().get();
    assertTrue(saveActions.isEnabled());
    assertEquals(Collections.singletonList(new FieldFormatterCleanup("title", new LowerCaseFormatter())), saveActions.getConfiguredActions());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Aggregations

FieldFormatterCleanup (org.jabref.model.cleanup.FieldFormatterCleanup)33 Test (org.junit.Test)22 FieldFormatterCleanups (org.jabref.model.cleanup.FieldFormatterCleanups)20 LowerCaseFormatter (org.jabref.logic.formatter.casechanger.LowerCaseFormatter)10 BibEntry (org.jabref.model.entry.BibEntry)9 ClearFormatter (org.jabref.logic.formatter.bibtexfields.ClearFormatter)7 NormalizePagesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)5 MoveFieldCleanup (org.jabref.logic.cleanup.MoveFieldCleanup)3 IdentityFormatter (org.jabref.logic.formatter.IdentityFormatter)3 NormalizeDateFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter)3 NormalizeMonthFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter)3 StringReader (java.io.StringReader)2 NormalizeNamesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter)2 RemoveBracesFormatter (org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter)2 UpperCaseFormatter (org.jabref.logic.formatter.casechanger.UpperCaseFormatter)2 ParserResult (org.jabref.logic.importer.ParserResult)2 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 Component (java.awt.Component)1 ArrayList (java.util.ArrayList)1