Search in sources :

Example 36 with AssertImportActions

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

the class BankSLMPDFExtractorTest method testDividende_Ausland1.

@Test
public void testDividende_Ausland1() throws IOException {
    BankSLMPDFExtractor extractor = new BankSLMPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "BankSLM_Dividende_Ausland1.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, "CHF");
    // check security
    Security security = results.stream().filter(i -> i instanceof SecurityItem).findFirst().get().getSecurity();
    assertThat(security.getWkn(), is("472672"));
    assertThat(security.getName(), is("Nokia Corp"));
    // check transaction
    Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));
    AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(transaction.getSecurity(), is(security));
    assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2016-07-05T00:00")));
    assertThat(transaction.getMonetaryAmount(), is(Money.of("CHF", 3302_00L)));
    assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of("CHF", 1415_14L)));
    assertThat(transaction.getGrossValue(), is(Money.of("CHF", 4717_14L)));
    assertThat(transaction.getShares(), is(Values.Share.factorize(17000)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) LocalDateTime(java.time.LocalDateTime) BankSLMPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.BankSLMPDFExtractor) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) 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) Optional(java.util.Optional) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) BankSLMPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.BankSLMPDFExtractor) 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) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 37 with AssertImportActions

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

the class CSVAccountTransactionExtractorTest method testTaxesOnDividends.

@Test
public void testTaxesOnDividends() {
    Client client = new Client();
    CSVExtractor extractor = new CSVAccountTransactionExtractor(client);
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(0, // 
    Arrays.<String[]>asList(new String[] { "2013-01-01", "DE0007164600", "SAP.DE", "", "100", "EUR", "DIVIDENDS", "SAP SE", "10", "Notiz", "10" }), buildField2Column(extractor), errors);
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    AccountTransaction t = (AccountTransaction) results.stream().filter(i -> i instanceof TransactionItem).findAny().get().getSubject();
    assertThat(t.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(t.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, 10_00)));
}
Also used : Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) ParseException(java.text.ParseException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Test(org.junit.Test)

Example 38 with AssertImportActions

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

the class FinTechGroupBankPDFExtractorTest method testKontoauszug2.

@Test
public void testKontoauszug2() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexKontoauszug2.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));
    AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.REMOVAL));
    assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2016-01-26T00:00")));
    assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 15000_00L)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) Quote(name.abuchen.portfolio.money.Quote) 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) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) List(java.util.List) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) Optional(java.util.Optional) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) 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) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) IOException(java.io.IOException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Test(org.junit.Test)

Example 39 with AssertImportActions

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

the class HelloBankPDFExtractorTest method testErtrag01WithExistingSecurity.

@Test
public void testErtrag01WithExistingSecurity() throws IOException {
    Security security = new Security("Marine Harvest ASA", CurrencyUnit.EUR);
    security.setIsin("NO0003054108");
    Client client = new Client();
    client.addSecurity(security);
    HelloBankPDFExtractor extractor = new HelloBankPDFExtractor(client);
    List<Exception> errors = new ArrayList<>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Ertrag01.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    // check transaction
    Optional<Item> item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));
    AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(transaction.getSecurity(), is(security));
    assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2017-09-06T00:00")));
    assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(48.71))));
    assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.95 + 0.19 + (176.01 / 9.308)))));
    assertThat(transaction.getShares(), is(Values.Share.factorize(200)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) 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) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) HelloBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.HelloBankPDFExtractor) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) 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) Optional(java.util.Optional) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) 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) HelloBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.HelloBankPDFExtractor) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 40 with AssertImportActions

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

the class HelloBankPDFExtractorTest method testErtrag04.

@Test
public void testErtrag04() throws IOException {
    HelloBankPDFExtractor extractor = new HelloBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Ertrag04.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    // check security
    Optional<Item> item = results.stream().filter(i -> i instanceof SecurityItem).findFirst();
    assertThat(item.isPresent(), is(true));
    Security security = ((SecurityItem) item.get()).getSecurity();
    assertThat(security.getIsin(), is("US3682872078"));
    assertThat(security.getName(), is("G a z p r o m  P J S C"));
    assertThat(security.getCurrencyCode(), is("USD"));
    // check transaction
    item = results.stream().filter(i -> i instanceof TransactionItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(AccountTransaction.class));
    AccountTransaction transaction = (AccountTransaction) item.get().getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(transaction.getSecurity(), is(security));
    assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2017-08-21T00:00")));
    assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(116.91))));
    assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.19 + 0.95 + ((32.14 + 26.79 + 16) / 1.1805)))));
    assertThat(transaction.getShares(), is(Values.Share.factorize(800)));
    Unit grossValueUnit = transaction.getUnit(Unit.Type.GROSS_VALUE).get();
    assertThat(grossValueUnit.getAmount(), is(Money.of("EUR", Values.Amount.factorize(214.28 / 1.1805))));
    assertThat(grossValueUnit.getForex(), is(Money.of("USD", Values.Amount.factorize(214.28))));
    assertThat(grossValueUnit.getExchangeRate(), is(BigDecimal.ONE.divide(BigDecimal.valueOf(1.1805), 10, BigDecimal.ROUND_HALF_UP)));
    assertThat(grossValueUnit.getAmount().getAmount() - transaction.getUnitSum(Unit.Type.TAX).getAmount(), is(transaction.getMonetaryAmount().getAmount()));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) 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) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) HelloBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.HelloBankPDFExtractor) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) 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) Optional(java.util.Optional) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) IOException(java.io.IOException) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) 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) HelloBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.HelloBankPDFExtractor) Client(name.abuchen.portfolio.model.Client) 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