-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endnote importer test #321
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
src/test/java/net/sf/jabref/importer/fileformat/EndnoteImporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package net.sf.jabref.importer.fileformat; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.importer.OutputPrinterToNull; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
|
||
public class EndnoteImporterTest { | ||
|
||
EndnoteImporter importer; | ||
|
||
@Before | ||
public void setUp() { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
importer = new EndnoteImporter(); | ||
} | ||
|
||
@Test | ||
public void testGetFormatName() { | ||
assertEquals("Refer/Endnote", importer.getFormatName()); | ||
} | ||
|
||
@Test | ||
public void testGetCLIId() { | ||
assertEquals("refer", importer.getCLIId()); | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormat() throws IOException { | ||
List<String> list = Arrays.asList("Endnote.pattern.A.enw", "Endnote.pattern.E.enw", "Endnote.book.example.enw"); | ||
|
||
for (String str : list) { | ||
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream(str)) { | ||
assertTrue(importer.isRecognizedFormat(is)); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormatReject() throws IOException { | ||
List<String> list = Arrays.asList("IEEEImport1.txt", "IsiImporterTest1.isi", "IsiImporterTestInspec.isi", | ||
"IsiImporterTestWOS.isi", "IsiImporterTestMedline.isi", "RisImporterTest1.ris", | ||
"Endnote.pattern.no_enw", "empty.pdf", "annotated.pdf"); | ||
|
||
for (String str : list) { | ||
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream(str)) { | ||
assertFalse(importer.isRecognizedFormat(is)); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testImportEntries0() throws IOException { | ||
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream("Endnote.entries.enw")) { | ||
List<BibEntry> bibEntries = importer.importEntries(is, new OutputPrinterToNull()); | ||
|
||
assertEquals(5, bibEntries.size()); | ||
|
||
BibEntry be0 = bibEntries.get(0); | ||
assertEquals("Misc", be0.getType().getName()); | ||
assertEquals("testA0 and testA1", be0.getField("author")); | ||
assertEquals("testE0 and testE1", be0.getField("editor")); | ||
assertEquals("testT", be0.getField("title")); | ||
|
||
BibEntry be1 = bibEntries.get(1); | ||
assertEquals("Misc", be1.getType().getName()); | ||
assertEquals("testC", be1.getField("address")); | ||
assertEquals("testB2", be1.getField("booktitle")); | ||
assertEquals("test8", be1.getField("date")); | ||
assertEquals("test7", be1.getField("edition")); | ||
assertEquals("testJ", be1.getField("journal")); | ||
assertEquals("testD", be1.getField("year")); | ||
|
||
BibEntry be2 = bibEntries.get(2); | ||
assertEquals("Article", be2.getType().getName()); | ||
assertEquals("testB0", be2.getField("journal")); | ||
|
||
BibEntry be3 = bibEntries.get(3); | ||
assertEquals("Book", be3.getType().getName()); | ||
assertEquals("testI0", be3.getField("publisher")); | ||
assertEquals("testB1", be3.getField("series")); | ||
|
||
BibEntry be4 = bibEntries.get(4); | ||
assertEquals("MastersThesis", be4.getType().getName()); | ||
assertEquals("testX", be4.getField("abstract")); | ||
assertEquals("testF", be4.getField("bibtexkey")); | ||
assertEquals("testR", be4.getField("doi")); | ||
assertEquals("testK", be4.getField("keywords")); | ||
assertEquals("testO1", be4.getField("note")); | ||
assertEquals("testN", be4.getField("number")); | ||
assertEquals("testP", be4.getField("pages")); | ||
assertEquals("testI1", be4.getField("school")); | ||
assertEquals("testU", be4.getField("url")); | ||
assertEquals("testV", be4.getField("volume")); | ||
} | ||
} | ||
|
||
@Test | ||
public void testImportEntries1() throws IOException { | ||
String s = "%O Artn\\\\s testO\n%A testA,\n%E testE0, testE1"; | ||
InputStream is = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8)); | ||
List<BibEntry> bibEntries = importer.importEntries(is, new OutputPrinterToNull()); | ||
|
||
assertEquals(1, bibEntries.size()); | ||
|
||
BibEntry be = bibEntries.get(0); | ||
assertEquals("Misc", be.getType().getName()); | ||
assertEquals("testA", be.getField("author")); | ||
assertEquals("testE0, testE1", be.getField("editor")); | ||
assertEquals("testO", be.getField("pages")); | ||
} | ||
|
||
@Test | ||
public void testImportEntriesBookExample() throws IOException { | ||
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream("Endnote.book.example.enw")) { | ||
List<BibEntry> bibEntries = importer.importEntries(is, new OutputPrinterToNull()); | ||
|
||
assertEquals(1, bibEntries.size()); | ||
|
||
BibEntry be = bibEntries.get(0); | ||
assertEquals("Book", be.getType().getName()); | ||
assertEquals("Heidelberg", be.getField("address")); | ||
assertEquals("Preißel, René and Stachmann, Bjørn", be.getField("author")); | ||
assertEquals("3., aktualisierte und erweiterte Auflage", be.getField("edition")); | ||
assertEquals("Versionsverwaltung", be.getField("keywords")); | ||
assertEquals("XX, 327", be.getField("pages")); | ||
assertEquals("dpunkt.verlag", be.getField("publisher")); | ||
assertEquals("Git : dezentrale Versionsverwaltung im Team : Grundlagen und Workflows", be.getField("title")); | ||
assertEquals("http://d-nb.info/107601965X", be.getField("url")); | ||
assertEquals("2016", be.getField("year")); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/resources/net/sf/jabref/importer/fileformat/Endnote.book.example.enw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
%0 Book | ||
%A Preißel, René | ||
%A Stachmann, Bjørn | ||
%C Heidelberg | ||
%D 2016 | ||
%I dpunkt.verlag | ||
%K Versionsverwaltung | ||
%L 6H 1249(3) | ||
%P XX, 327 | ||
%T Git : dezentrale Versionsverwaltung im Team : Grundlagen und Workflows | ||
%U http://d-nb.info/107601965X | ||
%7 3., aktualisierte und erweiterte Auflage | ||
%@ 978-3-86490-311-3 | ||
%[ 20151028 | ||
%= 20151125 | ||
%1 UB Vaihingen (geschlossen: 24.12.15 - 3.1.16) |
42 changes: 42 additions & 0 deletions
42
src/test/resources/net/sf/jabref/importer/fileformat/Endnote.entries.enw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
%0 | ||
%A testA0 | ||
%A testA1 | ||
%E testE0 | ||
%E testE1 | ||
%T testT | ||
%0 Journal | ||
%0 Book Section | ||
%0 Book | ||
%0 Edited Book | ||
%0 Conference | ||
%0 Report | ||
%0 Review | ||
%0 Thesis | ||
%0 Test0 | ||
%7 test7 | ||
%C testC | ||
%D testD | ||
%8 test8 | ||
%J testJ | ||
%J testJ1 | ||
%B testB2 | ||
%0 Journal | ||
%B testB0 | ||
%0 Book | ||
%B testB1 | ||
%I testI0 | ||
%0 Thesis | ||
%I testI1 | ||
%P testP | ||
%V testV | ||
%N testN | ||
%U testU | ||
%R testRw | ||
%R doi:testR | ||
%O Artn \\s testO0 | ||
%O testO1 | ||
%K testK | ||
%X testX | ||
%9 Ph.D. | ||
%9 Masters | ||
%F testF |
1 change: 1 addition & 0 deletions
1
src/test/resources/net/sf/jabref/importer/fileformat/Endnote.pattern.A.enw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%A testA |
1 change: 1 addition & 0 deletions
1
src/test/resources/net/sf/jabref/importer/fileformat/Endnote.pattern.E.enw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%E testE |
1 change: 1 addition & 0 deletions
1
src/test/resources/net/sf/jabref/importer/fileformat/Endnote.pattern.no_enw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
%0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split this in 3 different tests.