Search in sources :

Example 81 with Client

use of name.abuchen.portfolio.model.Client in project portfolio by buchen.

the class FinTechGroupBankPDFExtractorTest method testDividendeAusland.

@Test
public void testDividendeAusland() throws IOException {
    FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FinTechGroupBankDividendeAusland1.txt"), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    // 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("US8552441094"));
    assertThat(security.getWkn(), is("884437"));
    assertThat(security.getName(), is("STARBUCKS CORP."));
    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-25T00:00")));
    assertThat(transaction.getAmount(), is(Values.Amount.factorize(14.45)));
    assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(7.78))));
    assertThat(transaction.getShares(), is(Values.Share.factorize(105)));
}
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) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) TransactionItem(name.abuchen.portfolio.datatransfer.Extractor.TransactionItem) FinTechGroupBankPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.FinTechGroupBankPDFExtractor) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) 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) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 82 with Client

use of name.abuchen.portfolio.model.Client in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testRequiredFieldDate.

@Test
public void testRequiredFieldDate() {
    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[] { "", "DE0007164600", "", "", "SAP SE", "100", "EUR", "11", "", "", "", "", "1,9", "BUY", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(results, empty());
    assertThat(errors.size(), is(1));
}
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) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 83 with Client

use of name.abuchen.portfolio.model.Client in project portfolio by buchen.

the class CSVPortfolioTransactionExtractorTest method testBuyTransaction.

@Test
public void testBuyTransaction() 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-02", "DE0007164600", "SAP.DE", "", "SAP SE", "100", "EUR", "11", "", "", "", "", "1,9", "BUY", "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.BUY));
    assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(t.getNote(), is("Notiz"));
    assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-02T00:00")));
    assertThat(t.getShares(), is(Values.Share.factorize(1.9)));
    assertThat(t.getSecurity(), is(security));
    assertThat(t.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 11_00)));
    assertThat(t.getUnit(Unit.Type.TAX).isPresent(), is(false));
    AccountTransaction at = entry.getAccountTransaction();
    assertThat(at.getType(), is(AccountTransaction.Type.BUY));
    assertThat(at.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", 0)));
}
Also used : BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) 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) 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 84 with Client

use of name.abuchen.portfolio.model.Client in project portfolio by buchen.

the class CSVSecurityExtractorTest method testSecurityCreation.

@Test
public void testSecurityCreation() throws ParseException {
    Client client = new Client();
    CSVExtractor extractor = new CSVSecurityExtractor(client);
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(0, Arrays.<String[]>asList(new String[] { "DE0007164600", "716460", "SAP.DE", "SAP SE", "EUR", "Notiz" }), buildField2Column(extractor), errors);
    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    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("716460"));
    assertThat(security.getTickerSymbol(), is("SAP.DE"));
    assertThat(security.getCurrencyCode(), is("EUR"));
    assertThat(security.getNote(), is("Notiz"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) Client(name.abuchen.portfolio.model.Client) Item(name.abuchen.portfolio.datatransfer.Extractor.Item) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) IsEmptyCollection.empty(org.hamcrest.collection.IsEmptyCollection.empty) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) List(java.util.List) AssertImportActions(name.abuchen.portfolio.datatransfer.actions.AssertImportActions) CSVExtractorTestUtil.buildField2Column(name.abuchen.portfolio.datatransfer.csv.CSVExtractorTestUtil.buildField2Column) ParseException(java.text.ParseException) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) 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) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 85 with Client

use of name.abuchen.portfolio.model.Client in project portfolio by buchen.

the class CSVSecurityPriceExtractorTest method testErrorIfAmountIsMissing.

@Test
public void testErrorIfAmountIsMissing() throws ParseException {
    Client client = new Client();
    CSVExtractor extractor = new CSVSecurityPriceExtractor(client);
    List<Exception> errors = new ArrayList<Exception>();
    List<Item> results = extractor.extract(0, // 
    Arrays.<String[]>asList(new String[] { "2015-01-01", "" }), buildField2Column(extractor), errors);
    assertThat(errors.size(), is(1));
    assertThat(results, empty());
}
Also used : Item(name.abuchen.portfolio.datatransfer.Extractor.Item) SecurityItem(name.abuchen.portfolio.datatransfer.Extractor.SecurityItem) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

Client (name.abuchen.portfolio.model.Client)352 Test (org.junit.Test)315 Security (name.abuchen.portfolio.model.Security)285 ArrayList (java.util.ArrayList)268 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)230 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)230 IOException (java.io.IOException)221 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)220 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)218 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)204 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)204 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)198 List (java.util.List)195 Money (name.abuchen.portfolio.money.Money)195 Values (name.abuchen.portfolio.money.Values)195 CoreMatchers.is (org.hamcrest.CoreMatchers.is)194 Assert.assertThat (org.junit.Assert.assertThat)194 LocalDateTime (java.time.LocalDateTime)193 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)187 Unit (name.abuchen.portfolio.model.Transaction.Unit)174