Example #1
0
 /**
  * Create a test database and start BaseXHTTP.
  *
  * @throws Exception if database cannot be created or server cannot be started
  */
 @Before
 public void setUp() throws Exception {
   startBaseXHTTP();
   try (final ClientSession cs = new ClientSession(context, UserText.ADMIN, UserText.ADMIN)) {
     cs.execute(new CreateDB(NAME));
   }
 }
Example #2
0
 /**
  * Drop the test database and stop BaseXHTTP.
  *
  * @throws Exception if database cannot be dropped or server cannot be stopped
  */
 @After
 public void tearDown() throws Exception {
   try (final ClientSession cs = new ClientSession(context, UserText.ADMIN, UserText.ADMIN)) {
     cs.execute(new DropDB(NAME));
   }
   stopBaseXHTTP();
 }
Example #3
0
  /**
   * Executes a command and sends the result to the specified output stream.
   *
   * @param cmd server command
   * @param arg argument
   * @param os target output stream
   * @return string
   * @throws IOException I/O exception
   */
  protected String exec(final ServerCmd cmd, final String arg, final OutputStream os)
      throws IOException {

    final OutputStream o = os == null ? new ArrayOutput() : os;
    sout.write(cmd.code);
    send(arg);
    sout.flush();
    final BufferInput bi = new BufferInput(sin);
    ClientSession.receive(bi, o);
    if (!ClientSession.ok(bi)) throw new BaseXException(bi.readString());
    return o.toString();
  }