Ejemplo n.º 1
0
 @Test
 public void shouldExtractTokenFromOAuthStandardResponse() {
   String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03";
   Token extracted = extractor.extract(response);
   assertEquals("hh5s93j4hdidpola", extracted.getToken());
   assertEquals("hdhd0244k9j7ao03", extracted.getSecret());
 }
Ejemplo n.º 2
0
 @Test
 public void shouldExtractTokenFromResponseWithCallbackConfirmed() {
   String response =
       "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03&callback_confirmed=true";
   Token extracted = extractor.extract(response);
   assertEquals("hh5s93j4hdidpola", extracted.getToken());
   assertEquals("hdhd0244k9j7ao03", extracted.getSecret());
 }
Ejemplo n.º 3
0
  /**
   * Test concurrent reader and writer (GH-458).
   *
   * <p><b>Test case:</b>
   *
   * <ol>
   *   <li/>start a long running reader;
   *   <li/>try to start a writer: it should time out;
   *   <li/>stop the reader;
   *   <li/>start the writer again: it should succeed.
   * </ol>
   *
   * @throws Exception error during request execution
   */
  @Test
  @Ignore("There is no way to stop a query on the server!")
  public void testReaderWriter() throws Exception {
    final String readerQuery = "?query=(1%20to%20100000000000000)%5b.=1%5d";
    final String writerQuery = "/test.xml";
    final byte[] content = Token.token("<a/>");

    final Get readerAction = new Get(readerQuery);
    final Put writerAction = new Put(writerQuery, content);

    final ExecutorService exec = Executors.newFixedThreadPool(2);

    // start reader
    exec.submit(readerAction);
    Performance.sleep(TIMEOUT); // delay in order to be sure that the reader has started
    // start writer
    Future<HTTPResponse> writer = exec.submit(writerAction);

    try {
      final HTTPResponse result = writer.get(TIMEOUT, TimeUnit.MILLISECONDS);

      if (result.status.isSuccess()) fail("Database modified while a reader is running");
      throw new Exception(result.toString());
    } catch (final TimeoutException e) {
      // writer is blocked by the reader: stop it
      writerAction.stop = true;
    }

    // stop reader
    readerAction.stop = true;

    // start the writer again
    writer = exec.submit(writerAction);
    assertEquals(HTTPCode.CREATED, writer.get().status);
  }
Ejemplo n.º 4
0
 /**
  * Test client with different user.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void user() throws IOException {
   run("-cexit", "-cdrop user " + NAME);
   equals(
       "5",
       new String[] {"-U" + NAME, "-P" + NAME, "-q5"},
       new String[] {"-ccreate user " + NAME + ' ' + Token.md5(NAME)});
   run("-cexit", "-cdrop user " + NAME);
 }
Ejemplo n.º 5
0
  /**
   * Test concurrent writers (GH-458).
   *
   * <p><b>Test case:</b>
   *
   * <ol>
   *   <li/>start several writers one after another;
   *   <li/>all writers should succeed.
   * </ol>
   *
   * @throws Exception error during request execution
   */
  @Test
  public void testMultipleWriters() throws Exception {
    final int count = 10;
    final String template =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<command xmlns=\"http://basex.org/rest\"><text><![CDATA["
            + "ADD TO %1$d <node id=\"%1$d\"/>"
            + "]]></text></command>";

    @SuppressWarnings("unchecked")
    final Future<HTTPResponse>[] tasks = new Future[count];
    final ExecutorService exec = Executors.newFixedThreadPool(count);

    // start all writers (not at the same time, but still in parallel)
    for (int i = 0; i < count; i++) {
      final String command = String.format(template, i);
      tasks[i] = exec.submit(new Post("", Token.token(command)));
    }

    // check if all have finished successfully
    for (final Future<HTTPResponse> task : tasks) {
      assertEquals(HTTPCode.OK, task.get(TIMEOUT, TimeUnit.MILLISECONDS).status);
    }
  }
Ejemplo n.º 6
0
 /**
  * Compares two byte arrays for equality.
  *
  * @param data1 first array
  * @param data2 first array
  */
 private static void assertSame(final byte[] data1, final byte[] data2) {
   assertEquals("Different array size: ", data1.length, data2.length);
   assertTrue("Data arrays differ: ", Token.eq(data1, data2));
 }
Ejemplo n.º 7
0
 /**
  * Test alternate encoding.
  *
  * @param enc encoding to be tested
  * @param input input string
  * @throws IOException I/O exception
  */
 private static void encoding(final String enc, final String input) throws IOException {
   final byte[] utf8 = Token.token(input);
   final IO io = new IOContent(input.getBytes(enc));
   final byte[] cache = new TextInput(io).encoding(enc).content();
   assertSame(cache, utf8);
 }
 @Test
 public void shouldParseResponse() {
   Token token = extractor.extract(response);
   assertEquals(token.getToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X");
 }