예제 #1
0
 /**
  * Queries empty content.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryEmptyBinary() throws IOException {
   session.execute("create db " + NAME);
   session.store("X", new ArrayInput(""));
   assertEqual("", session.execute("xquery " + RAW + _DB_RETRIEVE.args(NAME, "X")));
   assertEqual("", session.query(RAW + _DB_RETRIEVE.args(NAME, "X")).execute());
   final Query q = session.query(RAW + _DB_RETRIEVE.args(NAME, "X"));
   assertTrue(q.more());
   assertEqual("", q.next());
   assertNull(q.next());
 }
예제 #2
0
 /**
  * Stores binary content in the database.
  *
  * @throws IOException I/O exception
  */
 @Test
 public final void store() throws IOException {
   session.execute("create db " + NAME);
   session.store("X", new ArrayInput("!"));
   assertEqual("true", session.query(_DB_IS_RAW.args(NAME, "X")).execute());
   session.store("X", new ArrayInput(""));
   assertEqual("", session.query(_DB_RETRIEVE.args(NAME, "X")).execute());
   session.store("X", new ArrayInput(new byte[] {0, 1, -1}));
   assertEqual(
       "0001FF", session.query("xs:hexBinary(" + _DB_RETRIEVE.args(NAME, "X") + ')').execute());
   session.execute("drop db " + NAME);
 }
예제 #3
0
 /**
  * Adds documents to a database.
  *
  * @throws IOException I/O exception
  */
 @Test
 public final void add() throws IOException {
   session.execute("create db " + NAME);
   session.add(NAME, new ArrayInput("<X/>"));
   assertEqual("1", session.query("count(" + _DB_OPEN.args(NAME) + ')').execute());
   for (int i = 0; i < 9; i++) session.add(NAME, new ArrayInput("<X/>"));
   assertEqual("10", session.query("count(" + _DB_OPEN.args(NAME) + ')').execute());
 }
예제 #4
0
 /**
  * Stores binary content.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void storeBinary() throws IOException {
   session.execute("create db " + NAME);
   session.store("X", new ArrayInput(new byte[] {-128, -2, -1, 0, 1, 127}));
   assertEqual(
       "-128 -2 -1 0 1 127",
       session.query(_CONVERT_BINARY_TO_BYTES.args(_DB_RETRIEVE.args(NAME, "X"))).execute());
 }
예제 #5
0
 /**
  * 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());
 }
예제 #6
0
 /** Stops a session. */
 @After
 public final void stopSession() {
   try {
     if (cleanup) session.execute(new DropDB(NAME));
     session.close();
   } catch (final IOException ex) {
     fail(Util.message(ex));
   }
 }
예제 #7
0
 /**
  * Replaces documents in a database.
  *
  * @throws IOException I/O exception
  */
 @Test
 public final void replace() throws IOException {
   session.execute("create db " + NAME);
   assertEqual("0", session.query("count(" + _DB_OPEN.args(NAME) + ')').execute());
   session.replace(NAME, new ArrayInput("<X/>"));
   assertEqual("1", session.query("count(" + _DB_OPEN.args(NAME) + ')').execute());
   session.replace(NAME + '2', new ArrayInput("<X/>"));
   assertEqual("2", session.query("count(" + _DB_OPEN.args(NAME) + ')').execute());
   session.replace(NAME + '2', new ArrayInput("<X/>"));
   assertEqual("2", session.query("count(" + _DB_OPEN.args(NAME) + ')').execute());
 }
예제 #8
0
 /**
  * Queries binary content (works only if output stream is specified).
  *
  * @throws IOException I/O exception
  */
 @Test
 public void queryBinary() throws IOException {
   if (out == null) return;
   session.execute("create db " + NAME);
   final byte[] tmp = {0, 1, 2, 127, 0, -1, -2, -128};
   session.store("X", new ArrayInput(tmp));
   final String retr = _DB_RETRIEVE.args(NAME, "X");
   // check command
   session.execute("xquery " + RAW + retr + ',' + retr);
   assertTrue(eq(out.toArray(), concat(tmp, tmp)));
   out.reset();
   // check query execution
   session.query(RAW + retr + ',' + retr).execute();
   assertTrue(eq(out.toArray(), concat(tmp, tmp)));
   out.reset();
   // check iterator
   final Query q = session.query(RAW + retr + ',' + retr);
   q.next();
   assertTrue(eq(out.toArray(), tmp));
   out.reset();
   q.next();
   assertTrue(eq(out.toArray(), tmp));
   assertNull(q.next());
 }
예제 #9
0
 /**
  * Runs a query command and retrieves the result as string.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void commandErr() throws IOException {
   session.execute("1,<a/>+''");
 }
예제 #10
0
 /**
  * Runs an erroneous query command.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void commandError() throws IOException {
   session.execute("xquery (");
 }
예제 #11
0
 /**
  * Runs a query command and wraps the result.
  *
  * @throws IOException I/O exception
  */
 @Test
 public final void commandSerial2() throws IOException {
   assertEqual(
       "<db:results xmlns:db=\"ns\">" + "  <db:result>1</db:result>" + "</db:results>",
       session.execute("xquery " + WRAPPER + '1'));
 }
예제 #12
0
 /**
  * Runs a query command and wraps the result.
  *
  * @throws IOException I/O exception
  */
 @Test
 public final void commandSerial1() throws IOException {
   session.execute("set serializer wrap-prefix=db,wrap-uri=ns");
   assertEqual("<db:results xmlns:db=\"ns\"/>", session.execute("xquery ()"));
 }
예제 #13
0
 /**
  * Runs a query command and retrieves the result as string.
  *
  * @throws IOException I/O exception
  */
 @Test
 public final void command() throws IOException {
   session.execute("set serializer wrap-prefix=,wrap-uri=");
   assertEqual("A", session.execute("xquery 'A'"));
 }
예제 #14
0
 /**
  * Adds a file with an invalid file name.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void addNameErr() throws IOException {
   session.execute("create db " + NAME);
   session.add("", new ArrayInput("<X/>"));
 }
예제 #15
0
 /**
  * Retrieves empty content.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void retrieveEmpty() throws IOException {
   session.execute("create db " + NAME);
   session.store("X", new ArrayInput(""));
   assertEqual("", session.execute("retrieve X"));
 }
예제 #16
0
 /**
  * Stores binary content in the database.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void storeInvalid() throws IOException {
   session.execute("create db " + NAME);
   session.store("..", new ArrayInput("!"));
 }
예제 #17
0
 /**
  * Adds a file with missing input.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void replaceNoInput() throws IOException {
   session.execute("create db " + NAME);
   session.replace("", new ArrayInput(""));
 }