Search in sources :

Example 81 with AssertImportActions

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

the class UnicreditPDFExtractorTest method testWertpapierKauf1.

@Test
public void testWertpapierKauf1() throws IOException {
    UnicreditPDFExtractor extractor = new UnicreditPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "UniCreditHypoVereinsbankWertpapierKauf1.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    Optional<Item> item;
    // get security
    item = results.stream().filter(i -> i instanceof SecurityItem).findFirst();
    assertThat(item.isPresent(), is(true));
    Security security = ((SecurityItem) item.get()).getSecurity();
    // assert security
    assertThat(security.getIsin(), is("FR0000120578"));
    assertThat(security.getWkn(), is("920657"));
    assertThat(security.getName(), is("SANOFI S.A."));
    assertThat(security.getCurrencyCode(), is(CurrencyUnit.EUR));
    // get transaction
    item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(BuySellEntry.class));
    BuySellEntry entry = (BuySellEntry) item.get().getSubject();
    // assert transaction
    assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.BUY));
    assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.BUY));
    assertThat(entry.getPortfolioTransaction().getAmount(), is(Values.Amount.factorize(1560.83)));
    assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2016-02-17T00:00")));
    assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(13.57))));
    assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(22)));
}
Also used : SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) UnicreditPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.UnicreditPDFExtractor) 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) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) BuySellEntryItem(name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 82 with AssertImportActions

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

the class CSVAccountTransactionExtractorTest method testDividendTransactionPlusSecurityCreation.

@Test
public void testDividendTransactionPlusSecurityCreation() throws ParseException {
    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" }), 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"));
    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.getNote(), is("Notiz"));
    assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
    assertThat(t.getShares(), is(Values.Share.factorize(10)));
    assertThat(t.getSecurity(), is(security));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) 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) Messages(name.abuchen.portfolio.Messages) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) EnumField(name.abuchen.portfolio.datatransfer.csv.CSVImporter.EnumField) EnumMapFormat(name.abuchen.portfolio.datatransfer.csv.CSVImporter.EnumMapFormat) Map(java.util.Map) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) CSVExtractorTestUtil.buildField2Column(name.abuchen.portfolio.datatransfer.csv.CSVExtractorTestUtil.buildField2Column) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ParseException(java.text.ParseException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) FieldFormat(name.abuchen.portfolio.datatransfer.csv.CSVImporter.FieldFormat) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) List(java.util.List) Column(name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) 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) ParseException(java.text.ParseException) 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) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 83 with AssertImportActions

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

the class CSVAccountTransactionExtractorTest method testDetectionOfFeeRefunds.

@Test
public void testDetectionOfFeeRefunds() {
    Client client = new Client();
    CSVExtractor extractor = new CSVAccountTransactionExtractor(client);
    // setup custom mapping from string -> type
    Map<String, Column> field2column = buildField2Column(extractor);
    Column typeColumn = field2column.get(Messages.CSVColumn_Type);
    @SuppressWarnings("unchecked") EnumField<AccountTransaction.Type> field = (EnumField<AccountTransaction.Type>) typeColumn.getField();
    EnumMapFormat<AccountTransaction.Type> format = field.createFormat();
    format.map().put(AccountTransaction.Type.FEES_REFUND, "Gebührenerstattung");
    format.map().put(AccountTransaction.Type.FEES, "Gebühren");
    typeColumn.setFormat(new FieldFormat(Messages.CSVColumn_Type, format));
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(0, // 
    Arrays.<String[]>asList(new String[] { "2017-04-21", "", "", "", "10", "", "Gebührenerstattung", "", "", "", "" }, new String[] { "2017-04-21", "", "", "", "20", "", "Gebühren", "", "", "", "" }), field2column, errors);
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);
    AccountTransaction t1 = (AccountTransaction) // 
    results.stream().filter(// 
    i -> i instanceof TransactionItem).filter(i -> ((AccountTransaction) ((TransactionItem) i).getSubject()).getType() == AccountTransaction.Type.FEES_REFUND).findAny().get().getSubject();
    assertThat(t1.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10))));
    AccountTransaction t2 = (AccountTransaction) // 
    results.stream().filter(// 
    i -> i instanceof TransactionItem).filter(i -> ((AccountTransaction) ((TransactionItem) i).getSubject()).getType() == AccountTransaction.Type.FEES).findAny().get().getSubject();
    assertThat(t2.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(20))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) 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) Messages(name.abuchen.portfolio.Messages) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) EnumField(name.abuchen.portfolio.datatransfer.csv.CSVImporter.EnumField) EnumMapFormat(name.abuchen.portfolio.datatransfer.csv.CSVImporter.EnumMapFormat) Map(java.util.Map) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) CSVExtractorTestUtil.buildField2Column(name.abuchen.portfolio.datatransfer.csv.CSVExtractorTestUtil.buildField2Column) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ParseException(java.text.ParseException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) FieldFormat(name.abuchen.portfolio.datatransfer.csv.CSVImporter.FieldFormat) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) List(java.util.List) Column(name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) Unit(name.abuchen.portfolio.model.Transaction.Unit) EnumField(name.abuchen.portfolio.datatransfer.csv.CSVImporter.EnumField) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) ArrayList(java.util.ArrayList) FieldFormat(name.abuchen.portfolio.datatransfer.csv.CSVImporter.FieldFormat) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) ParseException(java.text.ParseException) 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) CSVExtractorTestUtil.buildField2Column(name.abuchen.portfolio.datatransfer.csv.CSVExtractorTestUtil.buildField2Column) Column(name.abuchen.portfolio.datatransfer.csv.CSVImporter.Column) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 84 with AssertImportActions

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

the class CSVAccountTransactionExtractorTest method testDividendTransaction.

@Test
public void testDividendTransaction() {
    Client client = new Client();
    Security security = new Security();
    security.setIsin("DE0007164600");
    client.addSecurity(security);
    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" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    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.getNote(), is("Notiz"));
    assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
    assertThat(t.getShares(), is(Values.Share.factorize(10)));
    assertThat(t.getSecurity(), is(security));
}
Also used : TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) ParseException(java.text.ParseException) 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) 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