4 import static org.junit.Assert.*;
5 import org.yaz4j.exception.*;
7 public class ConnectionTest {
10 public void testConnection() {
11 Connection con = new Connection("z3950.indexdata.dk:210/gils", 0);
14 con.setSyntax("sutrs");
15 System.out.println("Open connection to z3950.indexdata.dk:210/gils...");
17 ResultSet s = con.search("@attr 1=4 utah",
18 Connection.QueryType.PrefixQuery);
19 System.out.println("Search for 'utah'...");
21 assertEquals(s.getHitCount(), 9);
22 Record rec = s.getRecord(0);
24 byte[] content = rec.getContent();
26 assertEquals(content.length, 1940);
27 assertEquals(content[0], 103);
28 assertEquals(rec.getSyntax(), "SUTRS");
29 assertEquals(rec.getDatabase(), "gils");
30 } catch (ZoomException ze) {
31 fail(ze.getMessage());
38 public void unsupportedSyntax() {
39 System.out.println("Open connection to z3950.loc.gov:7090/voyager...");
40 Connection con = new Connection("z3950.loc.gov:7090/voyager", 0);
42 System.out.println("Set syntax to 'rusmarc'");
43 con.setSyntax("rusmarc");
45 System.out.println("Search for something that exists...");
46 ResultSet set = con.search("@attr 1=7 0253333490",
47 Connection.QueryType.PrefixQuery);
48 System.out.println("Result set size: " + set.getHitCount());
49 System.out.println("Get the first record...");
50 Record rec = set.getRecord(0);
52 System.out.println("Record is null");
54 System.out.print(rec.render());
56 } catch (ZoomException ze) {
57 //fail(ze.getMessage());
65 * This only works with local ztest
67 public void recordError() {
68 Connection con = new Connection("localhost:9999", 0);
71 con.setSyntax("postscript");
72 System.out.println("Open connection to localhost:9999...");
74 ResultSet s = con.search("100", Connection.QueryType.PrefixQuery);
76 assertEquals(s.getHitCount(), 100);
77 Record rec = s.getRecord(0);
78 fail("We should never get here and get ZoomeException instead");
79 } catch (ZoomException ze) {
80 // we need more specific exceptions here
81 System.out.println(ze.getMessage());
88 public void testScan() {
89 System.out.println("Open connection to z3950cat.bl.uk:9909/BLAC");
90 Connection con = new Connection("z3950cat.bl.uk:9909/BLAC", 0);
93 con.option("number", "20");
94 ScanSet set = con.scan("@attr 1=21 \"development\"");
95 System.out.println("getSize(): " + set.getSize());
96 assertEquals(20, set.getSize());
98 } catch (ZoomException ex) {
99 fail(ex.getMessage());