InMemoryPortfolioMaster extends SimpleAbstractInMemoryMaster<PortfolioDocument> implements PortfolioMaster { @Override public PortfolioDocument add(PortfolioDocument document) { ArgumentChecker.notNull(document, "document"); ArgumentChecker.notNull(document.getPortfolio(), "document.portfolio"); final ObjectId objectId = _objectIdSupplier.get(); final UniqueId uniqueId = objectId.atVersion(""); final Instant now = Instant.now(); final PortfolioDocument clonedDoc = clonePortfolioDocument(document); setDocumentId(document, clonedDoc, uniqueId); setVersionTimes(document, clonedDoc, now, null, now, null); _store.put(objectId, clonedDoc); storeNodes(clonedDoc.getPortfolio().getRootNode(), document.getPortfolio().getRootNode(), uniqueId, null); _changeManager.entityChanged(ChangeType.ADDED, objectId, document.getVersionFromInstant(), document.getVersionToInstant(), now); updateCaches(null, clonedDoc); return document; } InMemoryPortfolioMaster();  InMemoryPortfolioMaster(final ChangeManager changeManager);  InMemoryPortfolioMaster(final Supplier<ObjectId> objectIdSupplier);  InMemoryPortfolioMaster(final Supplier<ObjectId> objectIdSupplier, final ChangeManager changeManager); @Override PortfolioDocument get(UniqueId uniqueId); @Override PortfolioDocument get(ObjectIdentifiable objectId, VersionCorrection versionCorrection); @Override PortfolioDocument add(PortfolioDocument document); @Override PortfolioDocument update(PortfolioDocument document); @Override void remove(ObjectIdentifiable objectIdentifiable); @Override PortfolioDocument correct(PortfolioDocument document); @Override PortfolioSearchResult search(PortfolioSearchRequest request); @Override PortfolioHistoryResult history(PortfolioHistoryRequest request); @Override ManageablePortfolioNode getNode(UniqueId nodeId); static final String DEFAULT_OID_SCHEME; }
@Test public void test_defaultSupplier() { InMemoryPortfolioMaster master = new InMemoryPortfolioMaster(); PortfolioDocument added = master.add(new PortfolioDocument(generatePortfolio())); assertEquals("MemPrt", added.getUniqueId().getScheme()); }
@Test public void test_alternateSupplier() { InMemoryPortfolioMaster master = new InMemoryPortfolioMaster(new ObjectIdSupplier("Hello")); PortfolioDocument added = master.add(new PortfolioDocument(generatePortfolio())); assertEquals("Hello", added.getUniqueId().getScheme()); }
@Test public void test_add_emptyMaster() { ManageablePortfolio origPortfolio = generatePortfolio(); PortfolioDocument addedDoc = _emptyMaster.add(new PortfolioDocument(origPortfolio)); assertNotNull(addedDoc.getVersionFromInstant()); assertEquals("MemPrt", addedDoc.getUniqueId().getScheme()); assertEquals("1", addedDoc.getUniqueId().getValue()); ManageablePortfolio addedPortfolio = addedDoc.getPortfolio(); assertNotNull(addedPortfolio); assertSame(origPortfolio, addedPortfolio); assertEquals(addedDoc.getUniqueId(), addedPortfolio.getUniqueId()); assertAddedPortfolioNodes(addedPortfolio.getRootNode(), addedPortfolio.getUniqueId(), null); }