@Test
public void test_update_getUpdateGet() {
Instant now = Instant.now(_prtMaster.getClock());
UniqueId oldPortfolioId = UniqueId.of("DbPrt", "101", "0");
PortfolioDocument base = _prtMaster.get(oldPortfolioId);
Map<String, String> oldAttr = base.getPortfolio().getAttributes();
assertNotNull(oldAttr);
ManageablePortfolio port = new ManageablePortfolio("NewName");
port.setUniqueId(oldPortfolioId);
port.setRootNode(base.getPortfolio().getRootNode());
Map<String, String> newAttr = getNewAttributes();
port.setAttributes(newAttr);
PortfolioDocument input = new PortfolioDocument(port);
PortfolioDocument updated = _prtMaster.update(input);
assertEquals(UniqueId.of("DbPrt", "101"), updated.getUniqueId().toLatest());
assertEquals(false, base.getUniqueId().getVersion().equals(updated.getUniqueId().getVersion()));
assertEquals(now, updated.getVersionFromInstant());
assertEquals(null, updated.getVersionToInstant());
assertEquals(now, updated.getCorrectionFromInstant());
assertEquals(null, updated.getCorrectionToInstant());
assertEquals(input.getPortfolio(), updated.getPortfolio());
PortfolioDocument old = _prtMaster.get(oldPortfolioId);
assertEquals(base.getUniqueId(), old.getUniqueId());
assertEquals(base.getVersionFromInstant(), old.getVersionFromInstant());
assertEquals(now, old.getVersionToInstant()); // old version ended
assertEquals(base.getCorrectionFromInstant(), old.getCorrectionFromInstant());
assertEquals(base.getCorrectionToInstant(), old.getCorrectionToInstant());
assertEquals("TestPortfolio101", old.getPortfolio().getName());
assertEquals("TestNode111", old.getPortfolio().getRootNode().getName());
assertEquals(base.getPortfolio().getAttributes(), old.getPortfolio().getAttributes());
PortfolioDocument newer = _prtMaster.get(updated.getUniqueId());
assertEquals(updated.getUniqueId(), newer.getUniqueId());
assertEquals(now, newer.getVersionFromInstant());
assertEquals(null, newer.getVersionToInstant());
assertEquals(now, newer.getCorrectionFromInstant());
assertEquals(null, newer.getCorrectionToInstant());
assertEquals("NewName", newer.getPortfolio().getName());
assertEquals("TestNode111", newer.getPortfolio().getRootNode().getName());
assertEquals(old.getPortfolio().getRootNode().getUniqueId().toLatest(),
newer.getPortfolio().getRootNode().getUniqueId().toLatest());
assertEquals(false, old.getPortfolio().getRootNode().getUniqueId().getVersion().equals(
newer.getPortfolio().getRootNode().getUniqueId().getVersion()));
assertEquals(newAttr, newer.getPortfolio().getAttributes());
PortfolioHistoryRequest search = new PortfolioHistoryRequest(base.getUniqueId(), null, now);
PortfolioHistoryResult searchResult = _prtMaster.history(search);
assertEquals(2, searchResult.getDocuments().size());
assertEquals(updated.getUniqueId(), searchResult.getDocuments().get(0).getUniqueId());