/** * Runs a query and checks the updating flag. * * @throws IOException I/O exception */ @Test public void queryUpdating() throws IOException { // test non-updating query Query query = session.query("12345678"); assertFalse(query.updating()); assertEqual("12345678", query.execute()); assertFalse(query.updating()); query.close(); // test updating query query = session.query("insert node <a/> into <b/>"); assertTrue(query.updating()); assertEqual("", query.execute()); assertTrue(query.updating()); query.close(); }
/** * Runs a query with additional serialization parameters. * * @throws IOException I/O exception */ @Test public void querySerial1() throws IOException { session.execute("set serializer wrap-prefix=db,wrap-uri=ns"); final Query query = session.query(WRAPPER + "()"); assertTrue("Result expected.", query.more()); assertEqual("<db:results xmlns:db=\"ns\"/>", query.next()); assertFalse("No result expected.", query.more()); }
/** * Queries binary content. * * @throws IOException I/O exception */ @Test public void queryNullBinary() throws IOException { session.execute("create db " + NAME); session.store("X", new ArrayInput("\0")); assertEqual("\0", session.execute("xquery " + RAW + _DB_RETRIEVE.args(NAME, "X"))); assertEqual("\0", session.query(RAW + _DB_RETRIEVE.args(NAME, "X")).execute()); final Query q = session.query(RAW + _DB_RETRIEVE.args(NAME, "X")); assertTrue(q.more()); assertEqual("\0", q.next()); assertFalse(q.more()); }
/** * Test wild-card matching. * * @throws QueryException wild-card expression is not parsed */ @Test public void testMatch() throws QueryException { for (int i = 0; i < VALIDWC.length; i++) { final String q = VALIDWC[i]; final FTWildcard wc = new FTWildcard(token(q), null); final String[] good = TEXTS_GOOD[i]; for (final String element : good) { assertTrue('"' + q + "\" did NOT match \"" + element + '"', wc.match(token(element))); } final String[] bad = TEXTS_BAD[i]; for (final String element : bad) { assertFalse('"' + q + "\" matched \"" + element + '"', wc.match(token(element))); } } }
/** * Runs a query, using more(). * * @throws IOException I/O exception */ @Test public void queryInit() throws IOException { final Query query = session.query("()"); assertFalse("No result was expected.", query.more()); }