Search in sources :

Example 46 with AssertImportActions

use of name.abuchen.portfolio.datatransfer.actions.AssertImportActions in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testGrossValueIsCreated.

@Test
public void testGrossValueIsCreated() throws ParseException {
    Client client = new Client();
    Security security = new Security();
    security.setIsin("LU0419741177");
    security.setCurrencyCode(CurrencyUnit.USD);
    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[] { "2015-09-15", "LU0419741177", "", "", "", "56", "EUR", "0,14", "", "", "USD", "1,1194", "-0,701124", "BUY", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    BuySellEntry entry = (BuySellEntry) results.get(0).getSubject();
    assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.BUY));
    assertThat(entry.getPortfolioTransaction().getMonetaryAmount(), is(Money.of("EUR", Values.Amount.factorize(56))));
    assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(0.701124)));
    assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.14))));
    assertThat(entry.getPortfolioTransaction().getUnit(Unit.Type.GROSS_VALUE).get().getForex(), is(Money.of(security.getCurrencyCode(), Values.Amount.factorize(62.53))));
}
Also used : 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) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) ParseException(java.text.ParseException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Test(org.junit.Test)

Example 47 with AssertImportActions

use of name.abuchen.portfolio.datatransfer.actions.AssertImportActions 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)

Example 48 with AssertImportActions

use of name.abuchen.portfolio.datatransfer.actions.AssertImportActions in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testBuyTransactionWithForex.

@Test
public void testBuyTransactionWithForex() throws ParseException {
    Client client = new Client();
    Security security = new Security();
    security.setTickerSymbol("SAP.DE");
    security.setCurrencyCode("USD");
    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-02", "DE0007164600", "SAP.DE", "", "SAP SE", "-100", "EUR", "", "12", "110", "USD", "0,9091", "1,9", "SELL", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    BuySellEntry entry = (BuySellEntry) results.stream().filter(i -> i instanceof BuySellEntryItem).findAny().get().getSubject();
    PortfolioTransaction t = entry.getPortfolioTransaction();
    assertThat(t.getType(), is(PortfolioTransaction.Type.SELL));
    assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(t.getSecurity(), is(security));
    assertThat(t.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 12_00)));
    assertThat(t.getUnit(Unit.Type.FEE).isPresent(), is(false));
    Unit grossAmount = t.getUnit(Unit.Type.GROSS_VALUE).get();
    assertThat(grossAmount.getAmount(), is(Money.of("EUR", 100_00)));
    assertThat(grossAmount.getForex(), is(Money.of("USD", 110_00)));
    assertThat(grossAmount.getExchangeRate(), is(BigDecimal.valueOf(0.9091)));
}
Also used : BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) 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) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 49 with AssertImportActions

use of name.abuchen.portfolio.datatransfer.actions.AssertImportActions in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testDeliveryTransactionPlusSecurityCreation.

@Test
public void testDeliveryTransactionPlusSecurityCreation() throws ParseException {
    Client client = new Client();
    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", "DELIVERY_INBOUND", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    Security security = results.stream().filter(i -> i instanceof SecurityItem).findAny().get().getSecurity();
    assertThat(security.getName(), is("SAP SE"));
    assertThat(security.getIsin(), is("DE0007164600"));
    assertThat(security.getWkn(), is(nullValue()));
    assertThat(security.getTickerSymbol(), is("SAP.DE"));
    PortfolioTransaction t = (PortfolioTransaction) results.stream().filter(i -> i instanceof TransactionItem).findAny().get().getSubject();
    assertThat(t.getType(), is(PortfolioTransaction.Type.DELIVERY_INBOUND));
    assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(t.getNote(), is("Notiz"));
    assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
    assertThat(t.getShares(), is(Values.Share.factorize(1.2)));
    assertThat(t.getSecurity(), is(security));
    assertThat(t.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 11_00)));
    assertThat(t.getUnitSum(Unit.Type.TAX), is(Money.of("EUR", 10_00)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Arrays(java.util.Arrays) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) PortfolioTransferItem(name.abuchen.portfolio.datatransfer.Extractor.PortfolioTransferItem) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) CSVExtractorTestUtil.buildField2Column(name.abuchen.portfolio.datatransfer.csv.CSVExtractorTestUtil.buildField2Column) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ParseException(java.text.ParseException) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) List(java.util.List) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) 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) Test(org.junit.Test)

Example 50 with AssertImportActions

use of name.abuchen.portfolio.datatransfer.actions.AssertImportActions in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testTypeIsInferred.

@Test
public void testTypeIsInferred() throws ParseException {
    Client client = new Client();
    Security security = new Security();
    security.setTickerSymbol("SAP.DE");
    security.setCurrencyCode("EUR");
    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-02", "", "SAP.DE", "", "SAP SE", "-100", "EUR", "11", "", "", "", "", "1,9", "", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    BuySellEntry entry = (BuySellEntry) results.get(0).getSubject();
    assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.BUY));
    assertThat(entry.getPortfolioTransaction().getMonetaryAmount(), is(Money.of("EUR", 100_00)));
}
Also used : 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) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) ParseException(java.text.ParseException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)84 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)84 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)84 AssertImportActions (name.abuchen.portfolio.datatransfer.actions.AssertImportActions)84 Client (name.abuchen.portfolio.model.Client)84 Test (org.junit.Test)84 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)82 Security (name.abuchen.portfolio.model.Security)82 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)79 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)77 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)74 IOException (java.io.IOException)73 List (java.util.List)70 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)70 CoreMatchers.is (org.hamcrest.CoreMatchers.is)70 IsEmptyCollection.empty (org.hamcrest.collection.IsEmptyCollection.empty)70 Assert.assertThat (org.junit.Assert.assertThat)70 LocalDateTime (java.time.LocalDateTime)69 Money (name.abuchen.portfolio.money.Money)69 Values (name.abuchen.portfolio.money.Values)69