/** Tests the usage of complex keys for supported methods. */
  @Test
  public void testComplexKeys() throws UnsupportedEncodingException {
    ComplexKey start = ComplexKey.of(2012, 05, 05);
    ComplexKey end = ComplexKey.of(2012, 05, 12);
    ComplexKey key = ComplexKey.of("mykey");
    ComplexKey keys = ComplexKey.of("users:10", "users:11");

    Query query = new Query();
    query.setRangeStart(start);
    query.setRangeEnd(end);
    assertEquals(2, query.getArgs().size());
    String result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?startkey=[2012,5,5]&endkey=[2012,5,12]", result);

    query = new Query();
    query.setRange(start, end);
    assertEquals(2, query.getArgs().size());
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?startkey=[2012,5,5]&endkey=[2012,5,12]", result);

    query = new Query();
    query.setKey(key);
    assertEquals(1, query.getArgs().size());
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=\"mykey\"", result);

    query = new Query();
    query.setKeys(keys);
    assertEquals(1, query.getArgs().size());
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?keys=[\"users:10\",\"users:11\"]", result);
  }
  /** Tests the "range" argument. */
  @Test
  public void testRange() throws UnsupportedEncodingException {
    Query query = new Query();
    query.setRangeStart("startkey");
    query.setRangeEnd("endkey");
    assertEquals(2, query.getArgs().size());
    String result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?startkey=\"startkey\"&endkey=\"endkey\"", result);

    query = new Query();
    query.setRange("foo", "bar");
    assertEquals(2, query.getArgs().size());
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?startkey=\"foo\"&endkey=\"bar\"", result);
  }
  /**
   * This test verifies how numeric strings passed in are casted to integer values and how the
   * ComplexKey class can be used to pass in numeric strings accordingly.
   */
  @Test
  public void testNumericStrings() throws UnsupportedEncodingException {
    Query query = new Query();
    query.setKey("300");
    String result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=300", result);

    query.setKey("\"300\"");
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=\"300\"", result);

    query.setKey("[300,400,\"500\"]");
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=[300,400,\"500\"]", result);

    query.setKey(ComplexKey.of("300"));
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=\"300\"", result);

    query.setKey(ComplexKey.of(300));
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=300", result);

    query.setKey(ComplexKey.of(99999999999l));
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=99999999999", result);

    query.setKey(ComplexKey.of(3.141159f));
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=3.141159", result);

    query.setKey(ComplexKey.of(3.141159));
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=3.141159", result);

    query.setKey(ComplexKey.of(300, 400, "500"));
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?key=[300,400,\"500\"]", result);

    query = new Query();
    query.setRangeStart(ComplexKey.of("0000"));
    query.setRangeEnd(ComplexKey.of("Level+2"));
    result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?startkey=\"0000\"&endkey=\"Level+2\"", result);
  }