From 7e61cc6b46fb775cf7509e02ada0fe54dec0ccc2 Mon Sep 17 00:00:00 2001 From: mairdl Date: Mon, 21 Dec 2015 19:08:32 +0100 Subject: [PATCH] Added the MedlineImporterTest and a testfile --- .../fileformat/MedlineImporterTest.java | 89 ++++++++++ .../fileformat/MedlineImporterTest.xml | 167 ++++++++++++++++++ 2 files changed, 256 insertions(+) create mode 100644 src/test/java/net/sf/jabref/importer/fileformat/MedlineImporterTest.java create mode 100644 src/test/resources/net/sf/jabref/importer/fileformat/MedlineImporterTest.xml diff --git a/src/test/java/net/sf/jabref/importer/fileformat/MedlineImporterTest.java b/src/test/java/net/sf/jabref/importer/fileformat/MedlineImporterTest.java new file mode 100644 index 000000000000..34701fd1442e --- /dev/null +++ b/src/test/java/net/sf/jabref/importer/fileformat/MedlineImporterTest.java @@ -0,0 +1,89 @@ +package net.sf.jabref.importer.fileformat; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +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 org.junit.Assert; + +/** + * @author Daniel Mair/Bruehl + * + */ +public class MedlineImporterTest { + + MedlineImporter medlineImporter; + + @Before + public void setUp() throws Exception { + Globals.prefs = JabRefPreferences.getInstance(); + this.medlineImporter = new MedlineImporter(); + } + + @Test + public void testIsRecognizedFormatAccept() throws Throwable { + List list = Arrays.asList("MedlineImporterTest.xml"); + for (String str : list) { + try (InputStream is = MedlineImporterTest.class.getResourceAsStream(str);) { + Assert.assertTrue(medlineImporter.isRecognizedFormat(is)); + } + } + } + + @Test + public void testIsRecognizedFormatReject() throws Throwable { + List list = Arrays.asList("CopacImporterTest1.txt", "CopacImporterTest2.txt", + "IEEEImport1.txt", "IsiImporterTestWOS.isi"); + for (String str : list) { + try (InputStream is = MedlineImporterTest.class.getResourceAsStream(str);) { + Assert.assertFalse(medlineImporter.isRecognizedFormat(is)); + } + } + } + + @Test + public void testImportEntries() throws IOException { + try (InputStream is = MedlineImporter.class.getResourceAsStream("MedlineImporterTest.xml")) { + List entries = medlineImporter.importEntries(is, new OutputPrinterToNull()); + Assert.assertEquals(1, entries.size()); + } + } + + @Test + public void testImportEntries2() throws IOException { + try (InputStream is = MedlineImporter.class.getResourceAsStream("CopacImporterTest1.txt")) { + // Trigger a catchblock + List entries = medlineImporter.importEntries(is, new OutputPrinterToNull()); + //Assert.fail("Error during XML parsing"); + } + } + + @Test + public void testGetFormatName() { + assertEquals("testGetFormatName failed", "Medline", medlineImporter.getFormatName()); + } + + @Test + public void testGetCLIId() { + assertEquals("testGetCLIID failed", "medline", medlineImporter.getCLIId()); + } + + @Test + public void testFetchMedline() { + List validMedLine = medlineImporter.fetchMedline("1", new OutputPrinterToNull()); + List emptyMedLine = medlineImporter.fetchMedline("zzzzzz", new OutputPrinterToNull()); + assertNotNull(validMedLine); + assertEquals(0, emptyMedLine.size()); + } + +} diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/MedlineImporterTest.xml b/src/test/resources/net/sf/jabref/importer/fileformat/MedlineImporterTest.xml new file mode 100644 index 000000000000..b641e755c0d0 --- /dev/null +++ b/src/test/resources/net/sf/jabref/importer/fileformat/MedlineImporterTest.xml @@ -0,0 +1,167 @@ + + + +1 + +1976 +01 +16 + + +1976 +01 +16 + + +2013 +11 +21 + +
+ +0006-2944 + +13 +2 + +1975 +Jun + + +Biochemical medicine +Biochem Med + + +Formate assay in body fluids: application in methanol poisoning. + + +117-26 + + + +Makar +A B +AB + + +McMartin +K E +KE + + +Palese +M +M + + +Tephly +T R +TR + + +eng + +Journal Article +Research Support, U.S. Gov't, P.H.S. + +
+ +UNITED STATES +Biochem Med +0151424 +0006-2944 + + + +0 +Formates + + +142M471B3J +Carbon Dioxide + + +EC 1.2.- +Aldehyde Oxidoreductases + + +Y4S76JWI15 +Methanol + + +IM + + +Aldehyde Oxidoreductases +metabolism + + +Animals + + +Body Fluids +analysis + + +Carbon Dioxide +blood + + +Formates +blood +poisoning + + +Haplorhini + + +Humans + + +Hydrogen-Ion Concentration + + +Kinetics + + +Methanol +blood + + +Methods + + +Pseudomonas +enzymology + + +
+ + + +1975 +6 +1 + + +1975 +6 +1 +0 +1 + + +1975 +6 +1 +0 +0 + + +ppublish + +1 + + +
+
\ No newline at end of file