package name.abuchen.portfolio.datatransfer.pdf;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertThat;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;
import java.util.stream.Collectors;
import name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem;
import name.abuchen.portfolio.datatransfer.Extractor.Item;
import name.abuchen.portfolio.datatransfer.Extractor.SecurityItem;
import name.abuchen.portfolio.datatransfer.Extractor.TransactionItem;
import name.abuchen.portfolio.model.AccountTransaction;
import name.abuchen.portfolio.model.BuySellEntry;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.PortfolioTransaction;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.model.Transaction.Unit;
import name.abuchen.portfolio.money.CurrencyUnit;
import name.abuchen.portfolio.money.Money;
import name.abuchen.portfolio.money.Values;
import org.junit.Test;
@SuppressWarnings("nls")
public class DkbPDFExtractorTest
{
@Test
public void testSanityCheckForBankName() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return "some text";
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(results, empty());
assertThat(errors.size(), is(1));
assertThat(errors.get(0), instanceOf(UnsupportedOperationException.class));
}
private Security assertSecurityBuy(List<Item> results)
{
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("DE000A1HLTD2"));
assertThat(security.getWkn(), is("A1HLTD"));
assertThat(security.getName(), is("8,75 % METALCORP GROUP B.V."));
return security;
}
private Security assertSecurityBuyAktien(List<Item> results)
{
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("BMG7945E1057"));
assertThat(security.getWkn(), is("A0ERZ0"));
assertThat(security.getName(), is("SEADRILL LTD."));
return security;
}
private Security assertSecurityBuyFonds(List<Item> results)
{
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("LU0392494562"));
assertThat(security.getWkn(), is("ETF110"));
assertThat(security.getName(), is("COMSTAGE-MSCI WORLD TRN U.ETF"));
return security;
}
private Security assertSecuritySell(List<Item> results)
{
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("AT0000A0U9J2"));
assertThat(security.getWkn(), is("A1MLSS"));
assertThat(security.getName(), is("8,5 % SCHOLZ HOLDING"));
return security;
}
private Security assertSecuritySellAktien(List<Item> results)
{
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("DE0005140008"));
assertThat(security.getWkn(), is("514000"));
assertThat(security.getName(), is("DEUTSCHE BANK AG"));
return security;
}
private Security assertSecurityErtragsgutschriftZinsgutschrift(List<Item> results)
{
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("DE000A1R1AN5"));
assertThat(security.getWkn(), is("A1R1AN"));
assertThat(security.getName(), is("PCC SE"));
return security;
}
private Security assertSecurityErtragsgutschriftDividende(List<Item> results)
{
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("DE0007100000"));
assertThat(security.getWkn(), is("710000"));
assertThat(security.getName(), is("DAIMLER AG"));
return security;
}
private Security assertSecurityErtragsgutschriftDividendeQuellensteuern(List<Item> results)
{
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("US0378331005"));
assertThat(security.getWkn(), is("865985"));
assertThat(security.getName(), is("APPLE INC."));
return security;
}
private Security assertSecurityRueckzahlung(List<Item> results)
{
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("XS0149161217"));
assertThat(security.getWkn(), is("858865"));
assertThat(security.getName(), is("2,309 % RBS CAPITAL TRUST A"));
return security;
}
private Security assertSecurityRueckzahlungHerabschreibung(List<Item> results)
{
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("DE000A1RE7V0"));
assertThat(security.getWkn(), is("A1RE7V"));
assertThat(security.getName(), is("6,875 % MS DEUTSCHLAND GMBH"));
return security;
}
private Security assertSecurityDepotuebertragAusgehend(List<Item> results)
{
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("DE000US9RGR9"));
assertThat(security.getWkn(), is("US9RGR"));
assertThat(security.getName(), is("24,75 % UBS AG (LONDON BRANCH)"));
return security;
}
@Test
public void testErtragsgutschriftZinsen() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbErtragsgutschrift.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
// check security
Security security = assertSecurityErtragsgutschriftZinsgutschrift(results);
// 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.getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(transaction.getDate(), is(LocalDate.parse("2016-01-04")));
assertThat(transaction.getAmount(), is(14452L));
assertThat(transaction.getShares(), is(Values.Share.factorize(100)));
}
@Test
public void testErtragsgutschriftZinsenAlt() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbErtragsgutschriftAlt.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
// check security
Security security = assertSecurityErtragsgutschriftZinsgutschrift(results);
// 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.getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(transaction.getDate(), is(LocalDate.parse("2014-01-02")));
assertThat(transaction.getAmount(), is(17302L));
assertThat(transaction.getShares(), is(Values.Share.factorize(100)));
assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(8.23))));
}
@Test
public void testErtragsgutschriftDividende() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbErtragsgutschriftDividende.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
// check security
Security security = assertSecurityErtragsgutschriftDividende(results);
// 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.getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(transaction.getDate(), is(LocalDate.parse("2016-04-07")));
assertThat(transaction.getAmount(), is(9750L));
assertThat(transaction.getShares(), is(Values.Share.factorize(30)));
}
@Test
public void testErtragsgutschriftDividendeQuellensteuern() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbErtragsgutschriftDividendeQuellensteuern.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
// check security
Security security = assertSecurityErtragsgutschriftDividendeQuellensteuern(results);
// 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.getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(transaction.getDate(), is(LocalDate.parse("2017-02-20")));
assertThat(transaction.getAmount(), is(2995L));
assertThat(transaction.getShares(), is(Values.Share.factorize(66)));
assertThat(transaction.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.29))));
}
@Test
public void testWertpapierKauf() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbKauf.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
// check security
assertSecurityBuy(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.BUY));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.BUY));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2030.66))));
assertThat(entry.getPortfolioTransaction().getDate(), is(LocalDate.parse("2015-11-27")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(20)));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR,
Values.Amount.factorize(/* 80.66 */0.00))));
}
@Test
public void testWertpapierKauf2() throws IOException // Aktien
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbKaufAktien.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
assertSecurityBuyAktien(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.BUY));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.BUY));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1760.00))));
assertThat(entry.getPortfolioTransaction().getDate(), is(LocalDate.parse("2016-01-27")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(1000)));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10.00))));
}
@Test
public void testWertpapierKauf3() throws IOException // Fonds
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbKaufFonds.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
assertSecurityBuyFonds(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.BUY));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.BUY));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1400.00))));
assertThat(entry.getPortfolioTransaction().getDate(), is(LocalDate.parse("2017-03-08")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(29.2893)));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
}
@Test
public void testWertpapierVerkauf() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbVerkauf.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
assertSecuritySell(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4937.19))));
assertThat(entry.getPortfolioTransaction().getDate(), is(is(LocalDate.parse("2015-10-29"))));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(60)));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(481.17))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10.00))));
}
@Test
public void testWertpapierVerkaufAktien() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbVerkaufAktien.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
assertSecuritySellAktien(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(3000))));
assertThat(entry.getPortfolioTransaction().getDate(), is(is(LocalDate.parse("2016-02-12"))));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(200)));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10.00))));
}
@Test
public void testWertpapierRueckzahlung() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbRueckzahlung.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
assertSecurityRueckzahlung(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.DELIVERY_OUTBOUND));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.TRANSFER_IN));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2974.39))));
assertThat(entry.getPortfolioTransaction().getDate(), is(is(LocalDate.parse("2014-07-31"))));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(30)));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(25.61))));
}
@Test
public void testWertpapierRueckzahlungNennwertHerabschreibung() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbRueckzahlungHerabschreibung.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
assertSecurityRueckzahlungHerabschreibung(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.DELIVERY_OUTBOUND));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.TRANSFER_IN));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1908.39))));
assertThat(entry.getPortfolioTransaction().getDate(), is(is(LocalDate.parse("2016-01-13"))));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(20)));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(91.61))));
}
@Test
public void testWertpapierTeilliquidation() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbTeilliquidation.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
assertSecurityRueckzahlungHerabschreibung(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.DELIVERY_OUTBOUND));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.TRANSFER_IN));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2000.00))));
assertThat(entry.getPortfolioTransaction().getDate(), is(is(LocalDate.parse("2016-01-13"))));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(20)));
}
@Test
public void testDepotuebertragAusgang() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbDepotuebertragAusgehend.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(2));
// check security
assertSecurityDepotuebertragAusgehend(results);
// check transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.TRANSFER_OUT));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getDate(), is(LocalDate.parse("2015-11-30")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(250)));
}
@Test
public void testStornoWertpapierTeilliquidation() throws IOException
{
DkbPDFExtractor extractor = new DkbPDFExtractor(new Client())
{
@Override
protected String strip(File file) throws IOException
{
return from("DkbStornoTeilliquidation.txt");
}
};
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);
assertThat(errors, empty());
assertThat(results.size(), is(3));
assertSecurityRueckzahlungHerabschreibung(results);
// check buy sell transaction
Optional<Item> 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();
assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.DELIVERY_INBOUND));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.TRANSFER_OUT));
assertThat(entry.getPortfolioTransaction().getCurrencyCode(), is(CurrencyUnit.EUR));
assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1908.39))));
assertThat(entry.getPortfolioTransaction().getDate(), is(is(LocalDate.parse("2016-01-13"))));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(20)));
// Steuergutschrift bei Storno:
Item itemTaxReturn = results.stream().filter(i -> i instanceof TransactionItem).collect(Collectors.toList())
.get(0);
AccountTransaction entryTaxReturn = (AccountTransaction) itemTaxReturn.getSubject();
assertThat(entryTaxReturn.getType(), is(AccountTransaction.Type.TAX_REFUND));
assertThat(entryTaxReturn.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(91.61))));
assertThat(entryTaxReturn.getDate(), is(is(LocalDate.parse("2016-01-13"))));
}
private String from(String resource)
{
try (Scanner scanner = new Scanner(getClass().getResourceAsStream(resource), StandardCharsets.UTF_8.name()))
{
return scanner.useDelimiter("\\A").next();
}
}
}