Exemplo n.º 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());
 }
Exemplo n.º 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);
 }
Exemplo n.º 3
0
 /** Clean up method. */
 @After
 public void cleanUp() {
   try {
     testSession.close();
     adminSession.execute(new DropDB(RENAMED));
     adminSession.execute(new DropDB(NAME));
     adminSession.close();
     // give the server some time to clean up the sessions before next test
     Performance.sleep(100);
   } catch (final Exception ex) {
     fail(Util.message(ex));
   }
 }
Exemplo n.º 4
0
 /**
  * Assumes that this command is successful.
  *
  * @param cmd command reference
  * @param s session
  */
 private static void ok(final Command cmd, final Session s) {
   try {
     s.execute(cmd);
   } catch (final IOException ex) {
     fail(Util.message(ex));
   }
 }
Exemplo n.º 5
0
 /**
  * Assumes that this command fails.
  *
  * @param cmd command reference
  * @param s session
  */
 private static void no(final Command cmd, final Session s) {
   try {
     s.execute(cmd);
     fail("\"" + cmd + "\" was supposed to fail.");
   } catch (final IOException ignored) {
   }
 }
Exemplo n.º 6
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());
 }
Exemplo n.º 7
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());
 }
Exemplo n.º 8
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());
 }
Exemplo n.º 9
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));
   }
 }
Exemplo n.º 10
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());
 }
Exemplo n.º 11
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());
 }
Exemplo n.º 12
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(""));
 }
Exemplo n.º 13
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/>+''");
 }
Exemplo n.º 14
0
 /**
  * Runs an erroneous query command.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void commandError() throws IOException {
   session.execute("xquery (");
 }
Exemplo n.º 15
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'));
 }
Exemplo n.º 16
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 ()"));
 }
Exemplo n.º 17
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'"));
 }
Exemplo n.º 18
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/>"));
 }
Exemplo n.º 19
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("!"));
 }
Exemplo n.º 20
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"));
 }