-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
172 additions
and
62 deletions.
There are no files selected for viewing
107 changes: 50 additions & 57 deletions
107
src/test/java/net/sf/jabref/importer/fileformat/CopacImporterTest.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 |
---|---|---|
@@ -1,91 +1,84 @@ | ||
package net.sf.jabref.importer.fileformat; | ||
|
||
import net.sf.jabref.*; | ||
|
||
import net.sf.jabref.importer.OutputPrinterToNull; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class CopacImporterTest { | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
if (Globals.prefs == null) { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormat() throws IOException { | ||
private final List<String> testFiles = getTestFiles(); | ||
|
||
CopacImporter importer = new CopacImporter(); | ||
try (InputStream stream1 = CopacImporterTest.class | ||
.getResourceAsStream("CopacImporterTest1.txt"); InputStream stream2 = CopacImporterTest.class | ||
.getResourceAsStream("CopacImporterTest2.txt"); InputStream stream3 = CopacImporterTest.class | ||
.getResourceAsStream("IsiImporterTest1.isi"); InputStream stream4 = CopacImporterTest.class | ||
.getResourceAsStream("IsiImporterTestInspec.isi"); InputStream stream5 = CopacImporterTest.class | ||
.getResourceAsStream("IsiImporterTestWOS.isi"); InputStream stream6 = CopacImporterTest.class | ||
.getResourceAsStream("IsiImporterTestMedline.isi")) { | ||
|
||
Assert.assertTrue(importer.isRecognizedFormat(stream1)); | ||
|
||
Assert.assertTrue(importer.isRecognizedFormat(stream2)); | ||
|
||
Assert.assertFalse(importer.isRecognizedFormat(stream3)); | ||
/** | ||
* Generates a List of all files in the package "/src/test/resources/net/sf/jabref/importer/fileformat" | ||
* @return A list of Names | ||
*/ | ||
public List<String> getTestFiles() { | ||
List<String> files = new ArrayList<>(); | ||
File d = new File(System.getProperty("user.dir") + "/src/test/resources/net/sf/jabref/importer/fileformat"); | ||
for (File f : d.listFiles()) { | ||
files.add(f.getName()); | ||
} | ||
return files; | ||
|
||
Assert.assertFalse(importer.isRecognizedFormat(stream4)); | ||
} | ||
|
||
Assert.assertFalse(importer.isRecognizedFormat(stream5)); | ||
@BeforeClass | ||
public static void setUp() { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
} | ||
|
||
Assert.assertFalse(importer.isRecognizedFormat(stream6)); | ||
} | ||
@Test(expected = IOException.class) | ||
public void testImportEntriesException() throws IOException { | ||
CopacImporter importer = new CopacImporter(); | ||
importer.importEntries(null, new OutputPrinterToNull()); | ||
} | ||
|
||
@Test | ||
public void testImportEntries() throws IOException { | ||
Globals.prefs.put("defaultEncoding", StandardCharsets.UTF_8.name()); | ||
|
||
public void testGetFormatName() { | ||
CopacImporter importer = new CopacImporter(); | ||
Assert.assertEquals("Copac", importer.getFormatName()); | ||
} | ||
|
||
try (InputStream stream = CopacImporterTest.class | ||
.getResourceAsStream("CopacImporterTest1.txt")) { | ||
List<BibEntry> entries = importer.importEntries(stream, new OutputPrinterToNull()); | ||
Assert.assertEquals(1, entries.size()); | ||
BibEntry entry = entries.get(0); | ||
|
||
Assert.assertEquals("The SIS project : software reuse with a natural language approach", entry.getField("title")); | ||
Assert.assertEquals( | ||
"Prechelt, Lutz and Universität Karlsruhe. Fakultät für Informatik", | ||
entry.getField("author")); | ||
Assert.assertEquals("Interner Bericht ; Nr.2/92", entry.getField("series")); | ||
Assert.assertEquals("1992", entry.getField("year")); | ||
Assert.assertEquals("Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik", entry.getField("publisher")); | ||
Assert.assertEquals("book", entry.getType()); | ||
} | ||
@Test | ||
public void testGetCLIId() { | ||
CopacImporter importer = new CopacImporter(); | ||
Assert.assertEquals("cpc", importer.getCLIId()); | ||
} | ||
|
||
@Test | ||
public void testImportEntries2() throws IOException { | ||
public void testIsRecognizedFormatReject() throws IOException { | ||
CopacImporter importer = new CopacImporter(); | ||
|
||
try (InputStream stream = CopacImporterTest.class | ||
.getResourceAsStream("CopacImporterTest2.txt")) { | ||
List<BibEntry> entries = importer.importEntries(stream, new OutputPrinterToNull()); | ||
Assert.assertEquals(2, entries.size()); | ||
BibEntry one = entries.get(0); | ||
List<String> list = testFiles.stream().filter(n -> !n.startsWith("CopacImporterTest")) | ||
.filter(n -> !n.startsWith("InspecSilverPlatterImporterTest")).collect(Collectors.toList()); | ||
|
||
Assert.assertEquals("Computing and operational research at the London Hospital", one.getField("title")); | ||
for (String str : list) { | ||
try (InputStream is = CopacImporterTest.class.getResourceAsStream(str)) { | ||
Assert.assertFalse(importer.isRecognizedFormat(is)); | ||
} | ||
} | ||
} | ||
|
||
BibEntry two = entries.get(1); | ||
@Test | ||
public void testImportEmptyEntries() throws IOException { | ||
CopacImporter importer = new CopacImporter(); | ||
|
||
Assert.assertEquals("Real time systems : management and design", two.getField("title")); | ||
try (InputStream is = CopacImporterTest.class.getResourceAsStream("Empty.txt")) { | ||
List<BibEntry> entries = importer.importEntries(is, new OutputPrinterToNull()); | ||
Assert.assertEquals(0, entries.size()); | ||
Assert.assertEquals(Collections.emptyList(), entries); | ||
} | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/test/java/net/sf/jabref/importer/fileformat/CopacImporterTestFiles.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,81 @@ | ||
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.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RunWith(Parameterized.class) | ||
public class CopacImporterTestFiles { | ||
|
||
private CopacImporter copacImporter; | ||
|
||
@Parameter | ||
public String fileName; | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
copacImporter = new CopacImporter(); | ||
} | ||
|
||
@Parameters(name = "{0}") | ||
public static Collection<String> fileNames() { | ||
List<String> files = new ArrayList<>(); | ||
File d = new File(System.getProperty("user.dir") + "/src/test/resources/net/sf/jabref/importer/fileformat"); | ||
for (File f : d.listFiles()) { | ||
files.add(f.getName()); | ||
} | ||
return files.stream().filter(n -> n.startsWith("CopacImporterTest")).filter(n -> n.endsWith(".txt")) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormat() throws IOException { | ||
try (InputStream stream = CopacImporterTest.class.getResourceAsStream(fileName)) { | ||
Assert.assertTrue(copacImporter.isRecognizedFormat(stream)); | ||
} | ||
} | ||
|
||
@Test | ||
public void testImportEntries() throws IOException { | ||
try (InputStream copacStream = CopacImporterTest.class.getResourceAsStream(fileName)) { | ||
|
||
List<BibEntry> copacEntries = copacImporter.importEntries(copacStream, new OutputPrinterToNull()); | ||
fileName = fileName.replace(".txt", ".bib"); | ||
|
||
Assert.assertFalse(copacEntries.isEmpty()); | ||
|
||
int size = copacEntries.size(); | ||
|
||
// workaround because BibtexEntryAssert can only test 1 entry | ||
if (size != 1) { | ||
for (int i = 1; i <= size; i++) { | ||
fileName = fileName.replaceAll(".bib", "-" + i + ".bib"); | ||
BibtexEntryAssert.assertEquals(CopacImporterTest.class, fileName, copacEntries.get(i - 1)); | ||
fileName = fileName.replaceAll("-" + i + ".bib", ".bib"); | ||
} | ||
} else { | ||
BibtexEntryAssert.assertEquals(CopacImporterTest.class, fileName, copacEntries); | ||
} | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.bib
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,9 @@ | ||
@Book{, | ||
title = {The SIS project : software reuse with a natural language approach}, | ||
publisher = {Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik}, | ||
year = {1992}, | ||
author = {Prechelt, Lutz and Universität Karlsruhe. Fakultät für Informatik}, | ||
series = {Interner Bericht ; Nr.2/92}, | ||
documenttype = {TXT}, | ||
hl = {Edinburgh} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest2-1.bib
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,13 @@ | ||
@Book{, | ||
title = {Computing and operational research at the London Hospital}, | ||
publisher = {London : Butterworths}, | ||
year = {1972}, | ||
author = {Barber, Barry and Abbott, W.}, | ||
series = {Computers in medicine series}, | ||
note = {Bibl.p.94-97. - Index}, | ||
documenttype = {TXT, PDF}, | ||
hl = {Aberdeen ; Birmingham ; Edinburgh ; Trinity College Dublin ; UCL (University College London)}, | ||
isbn = {0407517006 (Pbk)}, | ||
keywords = {London Hospital and Medical College, Electronic data processing - Medicine, Computers - Hospital administration, Hospital planning, Operations research, Hospital equipment and supplies, Electronic data processing - Hospitals - Administration, Hospitals, London, London Hospital and Medical College, Records management, Applications of computer systems, to 1971}, | ||
physicaldimensions = {x, 102p, leaf : ill., form, port ; 22cm} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest2-2.bib
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,12 @@ | ||
@Book{, | ||
title = {Real time systems : management and design}, | ||
publisher = {London ; New York : McGraw-Hill}, | ||
year = {1977}, | ||
author = {Tebbs, David and Collins, Garfield}, | ||
note = {Index}, | ||
documenttype = {TXT, PDF}, | ||
hl = {Aberdeen ; Birmingham ; Edinburgh ; Imperial College ; Liverpool ; Manchester ; Oxford ; Trinity College Dublin}, | ||
isbn = {0070844828}, | ||
keywords = {Real-time data processing - Management, Real time computer systems, Design}, | ||
physicaldimensions = {ix, 357p : ill., forms ; 24cm} | ||
} |
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