Fix bug #3115, add test cases.
package org.yaz4j;
+import org.yaz4j.exception.ZoomException;
import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p;
import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p;
import org.yaz4j.jni.yaz4jlib;
return this;
}
- public Record getRecord(int index) {
+ public Record getRecord(int index) throws ZoomException {
SWIGTYPE_p_ZOOM_record_p record =
yaz4jlib.ZOOM_resultset_record(resultSet, index);
+ //may be out of range or unsupported syntax
+ if (record == null) {
+ return null;
+ }
+ int errorCode = yaz4jlib.ZOOM_record_error(record, null, null, null);
+ if (errorCode != 0) throw new ZoomException("Record excpetion, code " + errorCode);
return new Record(record, this);
}
+++ /dev/null
-package yaz4jtest;
-
-import org.junit.*;
-import static org.junit.Assert.*;
-import org.yaz4j.Connection.QueryType;
-import org.yaz4j.exception.ZoomException;
-
-public class ConnectionTest {
-
- @Test
- public void testConnection() {
- org.yaz4j.Connection con = new org.yaz4j.Connection("z3950.indexdata.dk:210/gils", 0);
- assertNotNull(con);
- try {
- con.setSyntax("sutrs");
- System.out.println("Open connection to z3950.indexdata.dk:210/gils...");
- con.connect();
- org.yaz4j.ResultSet s = con.search("@attr 1=4 utah", QueryType.PrefixQuery);
- assertNotNull(s);
- assertEquals(s.getSize(), 9);
- org.yaz4j.Record rec = s.getRecord(0);
- assertNotNull(rec);
- byte[] content = rec.getContent();
- // first SUTRS record
- assertEquals(content.length, 1940);
- assertEquals(content[0], 103);
- assertEquals(rec.getSyntax(), "SUTRS");
- assertEquals(rec.getDatabase(), "gils");
- } catch (ZoomException ze) {
- fail(ze.getMessage());
- } finally {
- con.close();
- }
- }
-}
+++ /dev/null
-package yaz4jtest;
-
-import org.junit.*;
-import static org.junit.Assert.*;
-import org.yaz4j.*;
-import org.yaz4j.exception.ZoomException;
-
-/**
- * @author adam
- */
-public class DinosaurTest {
-
- @Test
- public void test() {
- Connection con = new Connection("z3950.loc.gov:7090/voyager", 0);
- try {
- assertNotNull(con);
- con.setSyntax("usmarc");
- con.connect();
- ResultSet set = con.search("@attr 1=7 0253333490", Connection.QueryType.PrefixQuery);
- assertNotNull(set);
- Record rec = set.getRecord(0);
- assertNotNull(rec);
- } catch (ZoomException ze) {
- fail(ze.getMessage());
- } finally {
- con.close();
- }
- }
-}
--- /dev/null
+package org.yaz4j;
+
+import org.junit.*;
+import static org.junit.Assert.*;
+import org.yaz4j.exception.*;
+
+public class ConnectionTest {
+
+ @Test
+ public void testConnection() {
+ Connection con = new Connection("z3950.indexdata.dk:210/gils", 0);
+ assertNotNull(con);
+ try {
+ con.setSyntax("sutrs");
+ System.out.println("Open connection to z3950.indexdata.dk:210/gils...");
+ con.connect();
+ ResultSet s = con.search("@attr 1=4 utah", Connection.QueryType.PrefixQuery);
+ System.out.println("Search for 'utah'...");
+ assertNotNull(s);
+ assertEquals(s.getSize(), 9);
+ Record rec = s.getRecord(0);
+ assertNotNull(rec);
+ byte[] content = rec.getContent();
+ // first SUTRS record
+ assertEquals(content.length, 1940);
+ assertEquals(content[0], 103);
+ assertEquals(rec.getSyntax(), "SUTRS");
+ assertEquals(rec.getDatabase(), "gils");
+ } catch (ZoomException ze) {
+ fail(ze.getMessage());
+ } finally {
+ con.close();
+ }
+ }
+
+ @Test
+ public void unsupportedSyntax() {
+ System.out.println("Open connection to z3950.loc.gov:7090/voyager...");
+ Connection con = new Connection("z3950.loc.gov:7090/voyager", 0);
+ try {
+ System.out.println("Set syntax to 'rusmarc'");
+ con.setSyntax("rusmarc");
+ con.connect();
+ System.out.println("Search for something that exists...");
+ ResultSet set = con.search("@attr 1=7 0253333490", Connection.QueryType.PrefixQuery);
+ System.out.println("Result set size: " + set.getSize());
+ System.out.println("Get the first record...");
+ Record rec = set.getRecord(0);
+ if (rec == null) {
+ System.out.println("Record is null");
+ } else {
+ System.out.print(rec.render());
+ }
+ } catch (ZoomException ze) {
+ //fail(ze.getMessage());
+ } finally {
+ con.close();
+ }
+ }
+}
--- /dev/null
+package org.yaz4j;
+
+import org.junit.*;
+import static org.junit.Assert.*;
+import org.yaz4j.exception.ZoomException;
+
+/**
+ * @author adam
+ */
+public class DinosaurTest {
+
+ @Test
+ public void test() {
+ Connection con = new Connection("z3950.loc.gov:7090/voyager", 0);
+ try {
+ assertNotNull(con);
+ con.setSyntax("usmarc");
+ con.connect();
+ ResultSet set = con.search("@attr 1=7 0253333490", Connection.QueryType.PrefixQuery);
+ assertNotNull(set);
+ Record rec = set.getRecord(0);
+ assertNotNull(rec);
+ } catch (ZoomException ze) {
+ fail(ze.getMessage());
+ } finally {
+ con.close();
+ }
+ }
+}