Esempio n. 1
0
  /**
   * Compares results.
   *
   * @param expected expected result
   * @param returned returned result
   * @throws Exception exception
   */
  private static void compare(final ItemList expected, final ItemList returned) throws Exception {

    // Compare response with expected result
    assertEquals("Different number of results", expected.size(), returned.size());

    final long es = expected.size();
    for (int e = 0; e < es; e++) {
      final Item exp = expected.get(e), ret = returned.get(e);
      if (!new DeepEqual().equal(exp, ret)) {
        final TokenBuilder tb = new TokenBuilder("Result ").addLong(e).add(" differs:\nReturned: ");
        tb.addExt(ret.serialize()).add("\nExpected: ").addExt(exp.serialize());
        fail(tb.toString());
      }
    }
  }
Esempio n. 2
0
 /**
  * Tests response handling with specified charset in the header 'Content-Type'.
  *
  * @throws IOException I/O Exception
  * @throws QueryException query exception
  */
 @Test
 public void responseWithCharset() throws IOException, QueryException {
   // Create fake HTTP connection
   final FakeHttpConnection conn = new FakeHttpConnection(new URL("http://www.test.com"));
   // Set content type
   conn.contentType = "text/plain; charset=CP1251";
   // set content encoded in CP1251
   final String test = "\u0442\u0435\u0441\u0442";
   conn.content = Charset.forName("CP1251").encode(test).array();
   final ItemList res = new HttpResponse(null, ctx.options).getResponse(conn, true, null);
   // compare results
   assertEquals(test, string(res.get(1).string(null)));
 }