Пример #1
0
  private void testWithDatabase() {
    LOGGER.debug("Test with database...");

    DmVersion version = new DmVersion(new DmObjectImpl(collection));
    version.save();
    LOGGER.debug("document: {}", version);

    DmVersion newVersion = (DmVersion) version.create();
    newVersion.save();
    LOGGER.debug("new version: {}", newVersion);

    List parents = newVersion.getParentIds();

    assertTrue(version.isRoot());
    assertTrue(parents.contains(version.getObjectId()));
    assertEquals(version.getObjectId(), version.getRootId());
    assertEquals(version.getObjectId(), newVersion.getRootId());

    assertFalse(version.getCurrent().isPresent());
    version.makeCurrent();
    LOGGER.debug("version is current: {}", version);
    assertTrue(version.getCurrent().isPresent());
    assertTrue(version.isCurrent());

    newVersion.makeCurrent();
    LOGGER.debug("new version is current: {}", newVersion);
    assertTrue(version.getCurrent().isPresent());
    assertTrue(newVersion.isCurrent());
    version.load(null);
    LOGGER.debug("old version is not current: {}", version);
    assertFalse(version.isCurrent());

    assertTrue(newVersion.getParentId().get().equals(version.getObjectId()));
    assertFalse(version.getParentId().isPresent());
    assertEquals(ImmutableList.of(), newVersion.getAllChildIds());
    assertEquals(ImmutableList.of(), newVersion.getChildIds());
    assertEquals(ImmutableList.of(newVersion.getObjectId()), version.getAllChildIds());
    assertEquals(ImmutableList.of(newVersion.getObjectId()), version.getChildIds());
  }
Пример #2
0
  @Test
  public void test() {
    DmVersion version = new DmVersion(new DmObjectImpl());
    version.getObject().put("_id", new ObjectId());
    LOGGER.debug("document: {}", version);

    DmVersion newVersion = (DmVersion) version.create();
    LOGGER.debug("new version: {}", newVersion);

    List parents = newVersion.getParentIds();

    assertTrue(version.isRoot());
    assertTrue(parents.contains(version.getObjectId()));
    assertEquals(version.getObjectId(), version.getRootId());
    assertEquals(version.getObjectId(), newVersion.getRootId());
    assertFalse(version.isCurrent());
    assertTrue(newVersion.getParentId().get().equals(version.getObjectId()));
    assertFalse(version.getParentId().isPresent());

    // It's now checked not to add/remove "current" label manually in addLabels/removeLabels.
    version.doAddLabels(ImmutableList.of(DmVersion.CURRENT_LABEL));
    assertTrue(version.isCurrent());
    version.doRemoveLabels(ImmutableList.of(DmVersion.CURRENT_LABEL));
    assertFalse(version.isCurrent());

    if (databaseEnabled) testWithDatabase();
  }