use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class FinTechGroupBankPDFExtractorTest method testWertpapierKauf6.
@Test
public void testWertpapierKauf6() throws IOException {
FinTechGroupBankPDFExtractor extractor = new FinTechGroupBankPDFExtractor(new Client());
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "FlatexKauf6.txt"), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
Optional<Item> item;
// security
item = results.stream().filter(i -> i instanceof SecurityItem).findFirst();
assertThat(item.isPresent(), is(true));
Security security = ((SecurityItem) item.get()).getSecurity();
assertThat(security.getIsin(), is("IE00B2NPKV68"));
assertThat(security.getWkn(), is("A0NECU"));
assertThat(security.getName(), is("ISHSII-JPM DL EM BD DLDIS"));
PortfolioTransaction transaction = results.stream().filter(i -> i instanceof Extractor.BuySellEntryItem).map(i -> (BuySellEntry) ((Extractor.BuySellEntryItem) i).getSubject()).map(b -> b.getPortfolioTransaction()).findAny().get();
assertThat(transaction.getType(), is(PortfolioTransaction.Type.BUY));
assertThat(transaction.getAmount(), is(Values.Amount.factorize(1000)));
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2017-06-15T00:00")));
assertThat(transaction.getUnitSum(Unit.Type.FEE), is(Money.of("EUR", Values.Amount.factorize(0.9))));
assertThat(transaction.getShares(), is(Values.Share.factorize(9.703363)));
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class HelloBankPDFExtractorTest method testKauf02.
@Test
public void testKauf02() throws IOException {
HelloBankPDFExtractor extractor = new HelloBankPDFExtractor(new Client());
List<Exception> errors = new ArrayList<>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Kauf02.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("GB00B03MLX29"));
assertThat(security.getName(), is("R o y a l D u t c h Shell"));
assertThat(security.getCurrencyCode(), is("GBP"));
// check 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();
PortfolioTransaction tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.BUY));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.BUY));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1314.03))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2017-04-27T00:00")));
assertThat(tx.getShares(), is(Values.Share.factorize(55)));
assertThat(tx.getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(6.53 + 1.55))));
Unit grossValueUnit = tx.getUnit(Unit.Type.GROSS_VALUE).get();
assertThat(grossValueUnit.getAmount(), is(Money.of("EUR", Values.Amount.factorize(1305.95))));
assertThat(grossValueUnit.getForex(), is(Money.of("GBP", Values.Amount.factorize(1100))));
assertThat(grossValueUnit.getExchangeRate(), is(BigDecimal.ONE.divide(BigDecimal.valueOf(0.8423), 10, BigDecimal.ROUND_HALF_UP)));
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class OnvistaPDFExtractorTest method testUmtauschFonds.
@Test
public void testUmtauschFonds() throws IOException {
OnvistaPDFExtractor extractor = new OnvistaPDFExtractor(new Client());
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "OnvistaUmtauschFonds.txt"), errors);
assertThat(errors, empty());
assertThat(results.size(), is(6));
// check security
Security security = assertSecurityUmtauschZiel(results);
// check transaction (target security, in)
Optional<Item> item = //
results.stream().filter(i -> i.getSubject() instanceof PortfolioTransaction).filter(i -> ((PortfolioTransaction) i.getSubject()).getType() == PortfolioTransaction.Type.DELIVERY_INBOUND).findFirst();
assertThat(item.isPresent(), is(true));
assertThat(item.get().getSubject(), instanceOf(PortfolioTransaction.class));
PortfolioTransaction transaction = (PortfolioTransaction) item.get().getSubject();
assertThat(transaction.getType(), is(PortfolioTransaction.Type.DELIVERY_INBOUND));
assertThat(transaction.getSecurity(), is(security));
assertThat(transaction.getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2015-11-26T00:00")));
assertThat(transaction.getShares(), is(Values.Share.factorize(156.729)));
assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
// check Steuererstattung
Item itemTaxReturn = //
results.stream().filter(i -> i.getSubject() instanceof AccountTransaction).filter(i -> ((AccountTransaction) i.getSubject()).getType() == AccountTransaction.Type.TAX_REFUND).findFirst().get();
AccountTransaction entryTaxReturn = (AccountTransaction) itemTaxReturn.getSubject();
assertThat(entryTaxReturn.getType(), is(AccountTransaction.Type.TAX_REFUND));
assertThat(entryTaxReturn.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(7.90))));
assertThat(entryTaxReturn.getDateTime(), is(is(LocalDateTime.parse("2015-11-26T00:00"))));
// check security (original)
assertSecurityUmtauschOriginal(results.stream().filter(i -> i instanceof SecurityItem).collect(Collectors.toList()).get(1));
Item targetItem = //
results.stream().filter(i -> i.getSubject() instanceof PortfolioTransaction).filter(i -> ((PortfolioTransaction) i.getSubject()).getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND).findFirst().get();
// check transaction (original security, out)
PortfolioTransaction entry2 = (PortfolioTransaction) targetItem.getSubject();
assertThat(entry2.getType(), is(PortfolioTransaction.Type.DELIVERY_OUTBOUND));
assertThat(entry2.getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry2.getDateTime(), is(LocalDateTime.parse("2015-11-23T00:00")));
assertThat(entry2.getShares(), is(Values.Share.factorize(28)));
assertThat(entry2.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(12.86))));
assertThat(entry2.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(12.86))));
// check Steuerbuchung
Item itemTax = //
results.stream().filter(i -> i.getSubject() instanceof AccountTransaction).filter(i -> ((AccountTransaction) i.getSubject()).getType() == AccountTransaction.Type.TAXES).findFirst().get();
AccountTransaction entryTax = (AccountTransaction) itemTax.getSubject();
assertThat(entryTax.getType(), is(AccountTransaction.Type.TAXES));
assertThat(entryTax.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(12.86))));
assertThat(entryTax.getDateTime(), is(is(LocalDateTime.parse("2015-11-23T00:00"))));
}
use of name.abuchen.portfolio.model.PortfolioTransaction 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)));
}
use of name.abuchen.portfolio.model.PortfolioTransaction 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)));
}
Aggregations