// Set up mock portfolio master
PortfolioMaster portfolioMaster = mock(PortfolioMaster.class);
PortfolioSearchRequest portSearchRequest = new PortfolioSearchRequest();
portSearchRequest.setName(PORTFOLIO_NAME);
PortfolioSearchResult portSearchResult = new PortfolioSearchResult();
when(portfolioMaster.search(portSearchRequest)).thenReturn(portSearchResult);
ManageablePortfolioNode rootNode = new ManageablePortfolioNode(PORTFOLIO_NAME);
rootNode.setUniqueId(UniqueId.of("abc", "123"));
ManageablePortfolio portfolio = new ManageablePortfolio(PORTFOLIO_NAME, rootNode);
PortfolioDocument portfolioDocument = new PortfolioDocument();
portfolioDocument.setPortfolio(portfolio);
when(portfolioMaster.add(any(PortfolioDocument.class))).thenReturn(portfolioDocument);
// file to masters
PortfolioReader portfolioReader =
new SingleSheetSimplePortfolioReader(PORTFOLIO_FILE, SECURITY_TYPE);
PortfolioWriter portfolioWriter =
new MasterPortfolioWriter(PORTFOLIO_NAME, portfolioMaster, positionMaster, securityMaster, false, false, false);
portfolioCopier.copy(portfolioReader, portfolioWriter);
portfolioReader.close();
portfolioWriter.close();
portSearchResult.setDocuments(Collections.singletonList(portfolioDocument));
// Masters to file
portfolioReader = new MasterPortfolioReader(PORTFOLIO_NAME, portfolioMaster, positionMaster, securitySource);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
portfolioWriter = new SingleSheetSimplePortfolioWriter(SheetFormat.CSV, outputStream, SECURITY_TYPE);