Esempio 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());
 }
Esempio 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);
 }
Esempio 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));
   }
 }
Esempio 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));
   }
 }
Esempio 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) {
   }
 }
Esempio n. 6
0
 /**
  * Performs the specified query n times and and returns the result.
  *
  * @param query query to be evaluated
  * @param n number of runs
  * @return resulting string
  * @throws IOException I/O exception
  */
 protected static String eval(final int n, final String query) throws IOException {
   // loop through number of runs for a single query
   check();
   String result = "";
   for (int rn = 0; rn < n; ++rn) result = session.execute(new XQuery(query));
   return result;
 }
Esempio n. 7
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());
 }
Esempio 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());
 }
Esempio n. 9
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());
 }
Esempio n. 10
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));
   }
 }
Esempio n. 11
0
  /**
   * Initializes the benchmark.
   *
   * @throws IOException I/O exception
   */
  @BeforeClass
  public static void init() throws IOException {
    // check if server is (not) running
    final int sp = context.soptions.get(StaticOptions.SERVERPORT);
    server = local || BaseXServer.ping(S_LOCALHOST, sp) ? null : createServer();
    session = local ? new LocalSession(context) : createClient();

    // create test database
    session.execute(new Set(MainOptions.QUERYINFO, true));
  }
Esempio n. 12
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());
 }
Esempio n. 13
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());
 }
Esempio n. 14
0
 /**
  * Creates or opens the test database.
  *
  * @throws IOException I/O exception
  */
 private static void check() throws IOException {
   session.execute(new Check(INPUT));
 }
Esempio n. 15
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(""));
 }
Esempio n. 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("!"));
 }
Esempio n. 17
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"));
 }
Esempio n. 18
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/>+''");
 }
Esempio n. 19
0
 /**
  * Runs an erroneous query command.
  *
  * @throws IOException I/O exception
  */
 @Test(expected = BaseXException.class)
 public final void commandError() throws IOException {
   session.execute("xquery (");
 }
Esempio n. 20
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'));
 }
Esempio n. 21
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 ()"));
 }
Esempio n. 22
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'"));
 }
Esempio n. 23
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/>"));
 }