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)));
}
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));
}
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))));
}
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));
}
Aggregations