ConnectionExtended tests YAZJ-18
authorJakub Skoczen <jakub@indexdata.dk>
Wed, 8 Apr 2015 11:58:06 +0000 (13:58 +0200)
committerJakub Skoczen <jakub@indexdata.dk>
Wed, 8 Apr 2015 11:58:06 +0000 (13:58 +0200)
src/test/org/yaz4j/ConnectionExtendedTest.java [new file with mode: 0644]

diff --git a/src/test/org/yaz4j/ConnectionExtendedTest.java b/src/test/org/yaz4j/ConnectionExtendedTest.java
new file mode 100644 (file)
index 0000000..b837d05
--- /dev/null
@@ -0,0 +1,44 @@
+package org.yaz4j;
+
+import org.junit.*;
+import static org.junit.Assert.*;
+import org.yaz4j.exception.*;
+import java.util.List;
+
+@SuppressWarnings("deprecation")
+public class ConnectionExtendedTest {
+  
+  @Test
+  public void testConnection() {
+    ConnectionExtended con = new ConnectionExtended("z3950.indexdata.dk:210/gils", 0);
+    assertNotNull(con);
+    try {
+      con.setSyntax("sutrs");
+      System.out.println("Open connection extended to z3950.indexdata.dk:210/gils...");
+      con.connect();
+      ResultSet s = con.search(new PrefixQuery("@attr 1=4 utah"));
+      System.out.println("Search for 'utah'...");
+      assertNotNull(s);
+      assertEquals(s.getHitCount(), 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");
+      System.out.println("Update record..");
+      Package p = con.getPackage("update");
+      p.option("action", "specialUpdate");
+      p.option("record", rec.render());
+      p.send();
+    } catch (ZoomException ze) {
+      assertEquals("Bib1Exception: Error Code = 223 (EsPermissionDeniedOnEsCannotModifyOrDelete)", 
+        ze.getMessage());
+    } finally {
+      con.close();
+    }
+  }
+  
+}