New gzip test
authorDennis Schafroth <dennis@indexdata.com>
Mon, 9 Jan 2012 16:22:46 +0000 (17:22 +0100)
committerDennis Schafroth <dennis@indexdata.com>
Mon, 9 Jan 2012 16:22:46 +0000 (17:22 +0100)
src/org/marc4j/test/GzipRecordTest.java [new file with mode: 0644]

diff --git a/src/org/marc4j/test/GzipRecordTest.java b/src/org/marc4j/test/GzipRecordTest.java
new file mode 100644 (file)
index 0000000..3e0c190
--- /dev/null
@@ -0,0 +1,45 @@
+package org.marc4j.test;\r
+\r
+import java.io.InputStream;\r
+import java.util.zip.GZIPInputStream;\r
+\r
+import junit.framework.Test;\r
+import junit.framework.TestCase;\r
+import junit.framework.TestSuite;\r
+import junit.textui.TestRunner;\r
+\r
+import org.marc4j.MarcReader;\r
+import org.marc4j.MarcStreamReader;\r
+import org.marc4j.marc.Record;\r
+\r
+public class GzipRecordTest extends TestCase {\r
+\r
+    Record record = null;\r
+\r
+    public void testGzipRecordRead() throws Exception {\r
+        InputStream input = getClass().getResourceAsStream(\r
+                "resources/oais.26.mrc.gz");\r
+        assertTrue("No test data", input != null);\r
+        GZIPInputStream gzipped = new GZIPInputStream(input);\r
+        MarcReader reader = new MarcStreamReader(gzipped, "MARC-8");\r
+        int index = 0;\r
+        while (reader.hasNext()) {\r
+            record = reader.next();\r
+            ++index;\r
+        }\r
+        assertTrue("Number of records was not correct: " +  index, index == 60221); \r
+        input.close();\r
+    }\r
+\r
+    public void tearDown() {\r
+        record = null;\r
+    }\r
+\r
+    public static Test suite() {\r
+        return new TestSuite(GzipRecordTest.class);\r
+    }\r
+\r
+    public static void main(String args[]) {\r
+        TestRunner.run(suite());\r
+    }\r
+}\r