예제 #1
0
 @Override
 protected String run(final String... args) throws IOException {
   try {
     final ArrayOutput ao = new ArrayOutput();
     System.setOut(new PrintStream(ao));
     System.setErr(NULL);
     new BaseX(args);
     return ao.toString();
   } finally {
     System.setOut(OUT);
     System.setErr(ERR);
   }
 }
예제 #2
0
  /**
   * Runs a request with the specified arguments and server arguments.
   *
   * @param args command-line arguments
   * @param sargs server arguments
   * @return result
   * @throws IOException I/O exception
   */
  private static String run(final String[] args, final String[] sargs) throws IOException {
    final BaseXServer server = createServer(sargs);
    final ArrayOutput ao = new ArrayOutput();
    System.setOut(new PrintStream(ao));
    System.setErr(NULL);

    final StringList sl = new StringList();
    sl.add("-p9999").add("-U" + Text.S_ADMIN).add("-P" + Text.S_ADMIN).add(args);
    try {
      new BaseXClient(sl.finish());
      return ao.toString();
    } finally {
      System.setErr(ERR);
      stopServer(server);
    }
  }
예제 #3
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());
 }
예제 #4
0
 /**
  * Checks if the most recent output equals the specified string.
  *
  * @param exp expected string
  * @param ret string returned from the client API
  */
 private void assertEqual(final Object exp, final Object ret) {
   final String result = (out != null ? out : ret).toString();
   if (out != null) out.reset();
   assertEquals(exp.toString(), result.replaceAll("\\r|\\n", ""));
 }