예제 #1
0
  /** 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);
  }
예제 #2
0
  /** 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);
  }
예제 #3
0
  /** Tests the "inclusive_end" argument. */
  @Test
  public void testInclusiveEnd() {
    Query query = new Query();
    query.setInclusiveEnd(true);

    assertEquals(1, query.getArgs().size());
    assertEquals("?inclusive_end=true", query.toString());
  }
예제 #4
0
  /** Tests the "endkey_docid" argument. */
  @Test
  public void testEndkey() {
    Query query = new Query();
    query.setEndkeyDocID("56789111");

    assertEquals(1, query.getArgs().size());
    assertEquals("?endkey_docid=56789111", query.toString());
  }
예제 #5
0
  /** Tests the "startkey_docid" argument. */
  @Test
  public void testStartkey() {
    Query query = new Query();
    query.setStartkeyDocID("1234");

    assertEquals(1, query.getArgs().size());
    assertEquals("?startkey_docid=1234", query.toString());
  }
예제 #6
0
  /** Tests the "descending" argument. */
  @Test
  public void testDescending() {
    Query query = new Query();
    query.setDescending(true);

    assertEquals(1, query.getArgs().size());
    assertEquals("?descending=true", query.toString());
  }
예제 #7
0
  /** Tests the "on_error" argument. */
  @Test
  public void testOnError() {
    Query query = new Query();
    query.setOnError(OnError.CONTINUE);

    assertEquals(1, query.getArgs().size());
    assertEquals("?on_error=continue", query.toString());
  }
예제 #8
0
  /** Tests the "stale" argument. */
  @Test
  public void testStale() {
    Query query = new Query();
    query.setStale(Stale.UPDATE_AFTER);

    assertEquals(1, query.getArgs().size());
    assertEquals("?stale=update_after", query.toString());
  }
예제 #9
0
  /** Test docs to skip. */
  @Test
  public void testSkip() {
    Query query = new Query();
    query.setSkip(50);

    assertEquals(1, query.getArgs().size());
    assertEquals("?skip=50", query.toString());
  }
예제 #10
0
  /** Tests the "reduce" argument. */
  @Test
  public void testReduce() {
    Query query = new Query();
    query.setReduce(true);

    assertEquals(1, query.getArgs().size());
    assertEquals("?reduce=true", query.toString());
  }
예제 #11
0
  /** Tests both the "group" and the "group_level" arguments. */
  @Test
  public void testGroup() {
    Query query = new Query();
    query.setGroup(true);
    query.setGroupLevel(2);

    assertEquals(2, query.getArgs().size());
    assertEquals("?group_level=2&group=true", query.toString());
  }
예제 #12
0
  /** Tests the default settings of the Query object. */
  @Test
  public void testInit() {
    Query query = new Query();

    assertEquals(0, query.getArgs().size());
    assertEquals(false, query.willReduce());
    assertEquals(false, query.willIncludeDocs());
    assertEquals("", query.toString());
  }
예제 #13
0
  /** Tests the "bbox" argument. */
  @Test
  public void testBbox() throws UnsupportedEncodingException {
    Query query = new Query();
    query.setBbox(0, 1, 2.0, 3);

    assertEquals(1, query.getArgs().size());
    String result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?bbox=0.0,1.0,2.0,3.0", result);
  }
예제 #14
0
  /** Tests the "limit" argument. */
  @Test
  public void testLimit() {
    Query query = new Query();
    query.setLimit(5);

    assertEquals(5, query.getLimit());
    assertEquals(1, query.getArgs().size());
    assertEquals("?limit=5", query.toString());
  }
예제 #15
0
  /** Tests the "keys" argument. */
  @Test
  public void testKeys() throws UnsupportedEncodingException {
    Query query = new Query();
    query.setKeys("[2, 3, 4]");

    assertEquals(1, query.getArgs().size());
    String result = URLDecoder.decode(query.toString(), "UTF-8");
    assertEquals("?keys=[2, 3, 4]", result);
  }
예제 #16
0
 public ImmutableList<Arg> getArgs() {
   return query.getArgs();
 }