Skip to content

Commit

Permalink
test RISImporter
Browse files Browse the repository at this point in the history
  • Loading branch information
obraliar committed Mar 17, 2016
1 parent 7929957 commit fbe4d24
Show file tree
Hide file tree
Showing 21 changed files with 366 additions and 104 deletions.
20 changes: 9 additions & 11 deletions src/main/java/net/sf/jabref/importer/fileformat/RisImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class RisImporter extends ImportFormat {

private static final Pattern RECOGNIZED_FORMAT_PATTERN = Pattern.compile("TY - .*");


/**
* Return the name of this import format.
*/
Expand Down Expand Up @@ -94,10 +93,6 @@ public List<BibEntry> importEntries(InputStream stream, OutputPrinter status) th

for (String entry1 : entries) {

if (entry1.trim().isEmpty()) {
continue;
}

String type = "";
String author = "";
String editor = "";
Expand Down Expand Up @@ -159,11 +154,11 @@ public List<BibEntry> importEntries(InputStream stream, OutputPrinter status) th
hm.put("title", oldVal + ": " + val);
}
}
}
// =
// val;
else if ("T2".equals(lab) || "T3".equals(lab) || "BT".equals(lab)) {
hm.put("title", hm.get("title").replaceAll("\\s+", " ")); // Normalize whitespaces
} else if ("T2".equals(lab) || "BT".equals(lab)) {
hm.put("booktitle", val);
} else if ("T3".equals(lab)) {
hm.put("series", val);
} else if ("AU".equals(lab) || "A1".equals(lab)) {
if ("".equals(author)) {
author = val;
Expand Down Expand Up @@ -194,6 +189,9 @@ else if ("T2".equals(lab) || "T3".equals(lab) || "BT".equals(lab)) {
hm.put("address", val);
} else if ("EP".equals(lab)) {
endPage = val;
if (!endPage.isEmpty()) {
endPage = "--" + endPage;
}
} else if ("SN".equals(lab)) {
hm.put("issn", val);
} else if ("VL".equals(lab)) {
Expand Down Expand Up @@ -233,7 +231,7 @@ else if ("T2".equals(lab) || "T3".equals(lab) || "BT".equals(lab)) {
}
} else if ("U1".equals(lab) || "U2".equals(lab) || "N1".equals(lab)) {
if (!comment.isEmpty()) {
comment = comment + "\n";
comment = comment + " ";
}
comment = comment + val;
}
Expand Down Expand Up @@ -261,7 +259,7 @@ else if ("ID".equals(lab)) {
hm.put("comment", comment);
}

hm.put("pages", startPage + "--" + endPage);
hm.put("pages", startPage + endPage);
}
BibEntry b = new BibEntry(DEFAULT_BIBTEXENTRY_ID, type); // id assumes an existing database so don't

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,39 @@

import net.sf.jabref.*;

import net.sf.jabref.importer.OutputPrinterToNull;
import net.sf.jabref.model.entry.BibEntry;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;

/**
* Test cases for the RISImporter
*
* @author $Author: coezbek $
*/
public class RISImporterTest {

private RisImporter risImporter;

@Before
public void setUp() throws Exception {
if (Globals.prefs == null) {
Globals.prefs = JabRefPreferences.getInstance();
}
Globals.prefs = JabRefPreferences.getInstance();
risImporter = new RisImporter();
}

@Test
public void testIsRecognizedFormat() throws IOException {

RisImporter importer = new RisImporter();
try (InputStream stream = RISImporterTest.class
.getResourceAsStream("RisImporterTest1.ris")) {
Assert.assertTrue(importer.isRecognizedFormat(stream));
}
public void testGetFormatName() {
Assert.assertEquals(risImporter.getFormatName(), "RIS");
}

@Test
public void testProcessSubSup() {

HashMap<String, String> hm = new HashMap<>();
hm.put("title", "/sub 3/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$_3$", hm.get("title"));

hm.put("title", "/sub 3 /");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$_3$", hm.get("title"));

hm.put("title", "/sub 31/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$_{31}$", hm.get("title"));

hm.put("abstract", "/sub 3/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$_3$", hm.get("abstract"));

hm.put("review", "/sub 31/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$_{31}$", hm.get("review"));

hm.put("title", "/sup 3/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$^3$", hm.get("title"));

hm.put("title", "/sup 31/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$^{31}$", hm.get("title"));

hm.put("abstract", "/sup 3/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$^3$", hm.get("abstract"));

hm.put("review", "/sup 31/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$^{31}$", hm.get("review"));

hm.put("title", "/sub $Hello/");
IsiImporter.processSubSup(hm);
Assert.assertEquals("$_{\\$Hello}$", hm.get("title"));
public void testGetCLIId() {
Assert.assertEquals(risImporter.getCLIId(), "ris");
}

@Test
public void testImportEntries() throws IOException {
RisImporter importer = new RisImporter();

try (InputStream stream = RISImporterTest.class
.getResourceAsStream("RisImporterTest1.ris")) {
List<BibEntry> entries = importer.importEntries(stream, new OutputPrinterToNull());
Assert.assertEquals(1, entries.size());
BibEntry entry = entries.get(0);
Assert.assertEquals("Editorial: Open Source and Empirical Software Engineering", entry
.getField("title"));
Assert.assertEquals(
"Harrison, Warren",
entry.getField("author"));

Assert.assertEquals("article", entry.getType());
Assert.assertEquals("Empirical Software Engineering", entry.getField("journal"));
Assert.assertEquals("2001", entry.getField("year"));
Assert.assertEquals("6", entry.getField("volume"));
Assert.assertEquals("3", entry.getField("number"));
Assert.assertEquals("193--194", entry.getField("pages"));
Assert.assertEquals("#sep#", entry.getField("month"));
public void testIfNotRecognizedFormat() throws IOException {
try (InputStream stream = RISImporterTest.class.getResourceAsStream("RisImporterCorrupted.ris")) {
Assert.assertFalse(risImporter.isRecognizedFormat(stream));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package net.sf.jabref.importer.fileformat;

import net.sf.jabref.*;
import net.sf.jabref.bibtex.BibtexEntryAssert;
import net.sf.jabref.importer.OutputPrinterToNull;
import net.sf.jabref.model.entry.BibEntry;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@RunWith(Parameterized.class)
public class RISImporterTestFiles {

private RisImporter risImporter;

@Parameter
public String fileName;


@Before
public void setUp() throws Exception {
Globals.prefs = JabRefPreferences.getInstance();
risImporter = new RisImporter();
}

@Parameters(name = "{0}")
public static Collection<String> fileNames() {
return Arrays.asList(new String[] {"RisImporterTest1", "RisImporterTest3",
"RisImporterTest4a", "RisImporterTest4b", "RisImporterTest4c",
"RisImporterTest5a", "RisImporterTest5b", "RisImporterTest6"});
}

@Test
public void testIsRecognizedFormat() throws IOException {
try (InputStream stream = RISImporterTest.class.getResourceAsStream(fileName + ".ris")) {
Assert.assertTrue(risImporter.isRecognizedFormat(stream));
}
}

@Test
public void testImportEntries() throws IOException {
try (InputStream risStream = RISImporterTest.class.getResourceAsStream(fileName + ".ris")) {

List<BibEntry> risEntries = risImporter.importEntries(risStream, new OutputPrinterToNull());
BibtexEntryAssert.assertEquals(RISImporterTest.class, fileName + ".bib", risEntries);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ @TechReport{
Year = {2005},
Month = {11},
day = {7},

Abstract = {Lorem ipsum abstract},
author = {Uwe Cantner and Andreas Nicklisch and Torsten Weiland},
institution = {University of Jena, Faculty of Economics and Max-Planck-Institute for Research into Collective Goods and Max-Planck-Institute for Economics, Strategic Interactions Group},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

JF - Empirical Software Engineering
T1 - Editorial: Open Source and Empirical Software Engineering
VL - 6
IS - 3
SP - 193
EP - 194
PY - 2001/09/01/
AU - Harrison, Warren
UR - http://dx.doi.org/10.1023/A:1017379030770
ER -

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@phdthesis{,
abstract = {abstract0
abstract1},
address = {32 peralta avenue los gatos ca},
author = {Cocke and Harrison, Warren Levenshtein Morris},
booktitle = {kmptnz},
comment = {comment0
comment1
comment2},
doi = {whatever},
editor = {Rives and Kasami},
issn = {kmptns},
journal = {kmptnd},
keywords = {keyword0, keyword1},
month = {#sep#},
pages = {193--194},
publisher = {kmptnv},
refid = {123456 sxdbgsd},
school = {kmptvf},
series = {Arrow},
title = {Editorial: Open Source and Empirical Software Engineering: Editorial. Editorial? Editorial: Editorials},
url = {http://dx.doi.org/10.1023/A:1017379030770},
volume = {6},
year = {2001}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@

TY - JOUR

TY - BOOK
TY - JOUR
TY - MGZN
TY - THES
TY - UNPB
TY - RPRT
TY - CHAP
TY - OTHER
TY - CONF
JF - Empirical Software Engineering
T1 - Editorial: Open Source and Empirical Software Engineering
VL - 6
IS - 3
T1 - Editorial: Open Source and Empirical Software Engineering:
TI - Editorial.
T1 - Editorial?
T1 - Editorial
T1 - Editorials
VL - 6
IS -
SP - 193
EP - 194
PY - 99
PY - YEAR/MONTH/DAY/
PY - 2001/09/01/
AU - Harrison, Warren
PY - 2001/00/00/
PY - ///
PY - 2001///
Y1 - 2001/09/01/
AU - Cocke
A1 - Harrison, Warren
Levenshtein
Morris
A2 - Rives
A2 - Kasami
T2 - Automaton
T3 - Arrow
BT - State
JA - kmptne
JF - kmptnz
TY - OTHER
JO - kmptnd

PB - kmptnv
TY - THES
PB - kmptvf
ID - 123456
sxdbgsd
AD - 32 peralta avenue los gatos ca
CY - 32 peralta avenue los gatos ca
SN - kmptns

N2 - abstract0
AB - abstract1
UR - http://dx.doi.org/10.1023/A:1017379030770
ER -


KW - keyword0
KW - keyword1

U1 - comment0
U2 - comment1
N1 - comment2

M3 - doi: whatever
M3 - no

IS -
ER - kmpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@incollection{,
author = {Barata, Catarina and Celebi, MEmre and Marques, JorgeS},
booktitle = {Dermoscopy Image Analysis},
comment = {doi:10.1201/b19107-2},
doi = {10.1201/b19107-2},
issn = {978-1-4822-5326-9},
month = {#sep#},
pages = {1-22},
publisher = {CRC Press},
series = {Digital Imaging and Computer Vision},
title = {Toward a Robust Analysis of Dermoscopy Images Acquired under Different Conditions},
url = {http://dx.doi.org/10.1201/b19107-2},
year = {2015}
}
Loading

0 comments on commit fbe4d24

Please sign in to comment.