Search in sources :

Example 76 with Security

use of name.abuchen.portfolio.model.Security 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 77 with Security

use of name.abuchen.portfolio.model.Security 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 78 with Security

use of name.abuchen.portfolio.model.Security 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 79 with Security

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

the class ISINFieldTest method testPartialMatch.

@Test
public void testPartialMatch() throws ParseException {
    ISINField field = new ISINField(Messages.CSVColumn_ISIN);
    Format format = field.createFormat(Arrays.asList(new Security("SAP", "DE0007164600", "SAP.DE", QuoteFeed.MANUAL)));
    assertThat(format.parseObject("Zins/Dividende ISIN DE0007164600 SAP SE O."), is("DE0007164600"));
    assertThat(format.parseObject("ISIN DE0007164600"), is("DE0007164600"));
}
Also used : Format(java.text.Format) ISINField(name.abuchen.portfolio.datatransfer.csv.CSVImporter.ISINField) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Example 80 with Security

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

the class ISINFieldTest method testValidAndExistingISIN.

@Test
public void testValidAndExistingISIN() throws ParseException {
    ISINField field = new ISINField(Messages.CSVColumn_ISIN);
    Format format = field.createFormat(Arrays.asList(new Security("BASF", "DE000BASF111", "BAS.DE", QuoteFeed.MANUAL)));
    assertThat(format.parseObject("DE000BASF111"), is("DE000BASF111"));
}
Also used : Format(java.text.Format) ISINField(name.abuchen.portfolio.datatransfer.csv.CSVImporter.ISINField) Security(name.abuchen.portfolio.model.Security) Test(org.junit.Test)

Aggregations

Security (name.abuchen.portfolio.model.Security)375 Test (org.junit.Test)283 Client (name.abuchen.portfolio.model.Client)265 ArrayList (java.util.ArrayList)252 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)211 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)208 IOException (java.io.IOException)196 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)195 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)195 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)190 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)185 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)181 List (java.util.List)180 Unit (name.abuchen.portfolio.model.Transaction.Unit)175 Values (name.abuchen.portfolio.money.Values)173 Money (name.abuchen.portfolio.money.Money)170 LocalDateTime (java.time.LocalDateTime)162 CoreMatchers.is (org.hamcrest.CoreMatchers.is)162 Assert.assertThat (org.junit.Assert.assertThat)162 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)159