Ejemplo n.º 1
0
  @Test
  public void multiple_query_keys_should_be_posted_3() throws IOException {
    List<Object> keys = new ArrayList<Object>();
    keys.add("key1");
    keys.add("key2");
    keys.add("key3");

    ViewQuery query =
        new ViewQuery()
            .dbPath(TEST_DB_PATH)
            .designDocId("_design/testdoc")
            .viewName("test_view")
            .keys(keys);

    when(httpClient.postUncached(anyString(), anyString()))
        .thenReturn(ResponseOnFileStub.newInstance(200, "view_result.json"));
    dbCon.queryForStream(query).close();
    verify(httpClient).postUncached(query.buildQuery(), query.getKeysAsJson());
  }
Ejemplo n.º 2
0
  @Test
  public void load_query_result() {
    setupGetDocResponse("doc_id1", "doc_id2");

    ViewQuery query =
        new ViewQuery()
            .dbPath(TEST_DB_PATH)
            .designDocId("_design/testdoc")
            .viewName("test_view")
            .key("key_value");

    when(httpClient.getUncached(query.buildQuery()))
        .thenReturn(ResponseOnFileStub.newInstance(200, "view_result.json"));

    ViewResult result = dbCon.queryView(query);

    assertEquals(2, result.getSize());
    assertEquals("doc_id1", result.getRows().get(0).getId());
    assertEquals("doc_id2", result.getRows().get(1).getId());
  }
Ejemplo n.º 3
0
  @Test
  public void documents_embedded_in_view_result_should_be_read_directly() {
    ViewQuery query =
        new ViewQuery()
            .dbPath(TEST_DB_PATH)
            .designDocId("_design/testdoc")
            .viewName("test_view")
            .key("key_value");

    when(httpClient.getUncached(query.buildQuery()))
        .thenReturn(ResponseOnFileStub.newInstance(200, "view_result_with_embedded_docs.json"));

    List<TestDoc> result = dbCon.queryView(query, TestDoc.class);

    assertEquals(2, result.size());
    assertEquals(TestDoc.class, result.get(0).getClass());
    assertEquals("doc_id1", result.get(0).getId());
    assertEquals("doc_id2", result.get(1).getId());
    verify(httpClient, times(1)).getUncached(anyString());
  }
Ejemplo n.º 4
0
  /**
   * Create a list adapter for the provided view, optionally following changes.
   *
   * @param couchDbConnector the CouchDbConnector to use
   * @param viewQuery the ViewQuery describing the view to use
   * @param followChanges true, if you want the list to be updated when the database has changes
   */
  public CouchbaseViewListAdapter(
      CouchDbConnector couchDbConnector, ViewQuery viewQuery, boolean followChanges) {
    this.couchDbConnector = couchDbConnector;
    // add update_seq to any viewQuery we are given
    this.viewQuery = viewQuery.updateSeq(true);
    this.followChanges = followChanges;

    listRows = new ArrayList<Row>();

    // trigger initial update
    updateListItems();
  }
Ejemplo n.º 5
0
  @Test
  public void queries_with_ignore_not_found() {
    ViewQuery query =
        new ViewQuery()
            .dbPath(TEST_DB_PATH)
            .designDocId("_design/testdoc")
            .viewName("test_view")
            .includeDocs(true)
            .keys(Arrays.asList("doc_id1", "doc_id2", "doc_id3", "doc_id4"));
    query.setIgnoreNotFound(true);

    when(httpClient.postUncached(anyString(), anyString()))
        .thenReturn(ResponseOnFileStub.newInstance(200, "view_result_with_ignored_docs.json"));

    List<TestDoc> result = dbCon.queryView(query, TestDoc.class);

    assertEquals(2, result.size());
    assertEquals(TestDoc.class, result.get(0).getClass());
    assertEquals("doc_id1", result.get(0).getId());
    assertEquals("doc_id3", result.get(1).getId());
    verify(httpClient).postUncached(query.buildQuery(), query.getKeysAsJson());
  }