Search in sources :

Example 1 with PortfolioTransferItem

use of name.abuchen.portfolio.datatransfer.Extractor.PortfolioTransferItem in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testTransferTransaction.

@Test
public void testTransferTransaction() throws ParseException {
    Client client = new Client();
    Security security = new Security();
    security.setTickerSymbol("SAP.DE");
    client.addSecurity(security);
    CSVExtractor extractor = new CSVPortfolioTransactionExtractor(client);
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(0, Arrays.<String[]>asList(new String[] { "2013-01-01", "DE0007164600", "SAP.DE", "", "SAP SE", "100", "EUR", "11", "10", "", "", "", "1,2", "TRANSFER_IN", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    PortfolioTransferEntry entry = (PortfolioTransferEntry) results.stream().filter(i -> i instanceof PortfolioTransferItem).findAny().get().getSubject();
    PortfolioTransaction source = entry.getSourceTransaction();
    assertThat(source.getType(), is(PortfolioTransaction.Type.TRANSFER_OUT));
    assertThat(source.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(source.getNote(), is("Notiz"));
    assertThat(source.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
    assertThat(source.getShares(), is(Values.Share.factorize(1.2)));
    assertThat(source.getSecurity(), is(security));
    // security transfers do not support fees and taxes at the moment
    assertThat(source.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
    assertThat(source.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 0)));
    PortfolioTransaction target = entry.getTargetTransaction();
    assertThat(target.getType(), is(PortfolioTransaction.Type.TRANSFER_IN));
    assertThat(target.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
    assertThat(target.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 0)));
}
Also used : ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) ParseException(java.text.ParseException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) PortfolioTransferItem(name.abuchen.portfolio.datatransfer.Extractor.PortfolioTransferItem) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) PortfolioTransferItem(name.abuchen.portfolio.datatransfer.Extractor.PortfolioTransferItem) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Test(org.junit.Test)

Aggregations

ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)1 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)1 PortfolioTransferItem (name.abuchen.portfolio.datatransfer.Extractor.PortfolioTransferItem)1 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)1 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)1 AssertImportActions (name.abuchen.portfolio.datatransfer.actions.AssertImportActions)1 Client (name.abuchen.portfolio.model.Client)1 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)1 PortfolioTransferEntry (name.abuchen.portfolio.model.PortfolioTransferEntry)1 Security (name.abuchen.portfolio.model.Security)1 Test (org.junit.Test)1