private static final String SECURITY_TYPE = "Equity";
@Test
public void testCsvToMastersToCsv() throws Exception {
PortfolioCopier portfolioCopier = new SimplePortfolioCopier();
PositionMaster positionMaster = new InMemoryPositionMaster();
SecurityMaster securityMaster = new InMemorySecurityMaster();
SecuritySource securitySource = new MasterSecuritySource(securityMaster);
// 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);
portfolioCopier.copy(portfolioReader, portfolioWriter);
portfolioReader.close();
portfolioWriter.close();
// Compare source and destination
try (CSVReader sourceReader = new CSVReader(new InputStreamReader(new FileInputStream(PORTFOLIO_FILE)))) {