Exemple #1
0
  @Test
  public void testCommonUpdate() {
    try {
      if (backend.doesDocumentExist("foodb", "common")) {
        backend.deleteDocument("foodb", "common");
      }
      JSONDocument d =
          (JSONDocument) Document.newDocument(db.getBackend(), "foodb", "common", "unittest");
      d.put("foo", "bar");
      d.getCommonData().put("_commonfoo", "bar");
      d = (JSONDocument) db.getBackend().saveDocument(d);
      String rev = d.getRevision();

      // d = (JSONDocument) Document.newRevision(db.getBackend(), d);
      d.getCommonData().put("_commonfoo", "baz");
      d = (JSONDocument) db.getBackend().saveDocument(d);
      assertEquals(rev, d.getRevision());

      Document current = db.getBackend().getDocument("foodb", "common");
      assertEquals(current.getRevision(), rev);
      assertTrue(db.getBackend().getDocumentRevisions("foodb", "common").length() == 1);

    } catch (BackendException e) {
      e.printStackTrace();
      assertNull(e);
    } catch (DocumentCreationException e) {
      e.printStackTrace();
      assertNull(e);
    }
  }
Exemple #2
0
  @Test
  public void test() {
    try {
      if (backend.doesDocumentExist("foodb", "foo")) {
        backend.deleteDocument("foodb", "foo");
      }
      String firstRev;
      String secondRev;

      JSONDocument d =
          (JSONDocument) Document.newDocument(db.getBackend(), "foodb", "foo", "unittest");

      d.put("foo", "bar");
      d = (JSONDocument) db.getBackend().saveDocument(d);
      assertNotNull(d);
      firstRev = d.getRevision();

      JSONDocument current = (JSONDocument) db.getBackend().getDocument("foodb", "foo");
      assertNotNull(current);
      assertEquals(current.getRevision(), d.getRevision());

      d = (JSONDocument) Document.newRevision(db.getBackend(), d, "unittest");

      d.put("foo", "baz");
      d = (JSONDocument) db.getBackend().saveDocument(d);
      secondRev = d.getRevision();

      JSONDocument one = (JSONDocument) db.getBackend().getDocument("foodb", "foo", firstRev);
      JSONDocument two = (JSONDocument) db.getBackend().getDocument("foodb", "foo", secondRev);

      assertEquals(one.get("foo"), "bar");
      assertEquals(two.get("foo"), "baz");
      assertTrue(db.getBackend().getDocumentRevisions("foodb", "foo").length() == 2);

    } catch (BackendException e) {
      e.printStackTrace();
      assertNull(e);
    } catch (DocumentCreationException e) {
      e.printStackTrace();
      assertNull(e);
    }
  }