Beispiel #1
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);
 }
Beispiel #2
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());
 }
Beispiel #3
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());
 }
Beispiel #4
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());
 }
Beispiel #5
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"));
 }
Beispiel #6
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("!"));
 }
Beispiel #7
0
 /**
  * Stores binary content in the database.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void storeNoDB() throws IOException {
   session.store("X", new ArrayInput("!"));
 }