forked from portfolio-performance/portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JustTradePDFExtractorTest.java
196 lines (150 loc) · 9.39 KB
/
JustTradePDFExtractorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package name.abuchen.portfolio.datatransfer.pdf.justtrade;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.assertThat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.junit.Test;
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.actions.AssertImportActions;
import name.abuchen.portfolio.datatransfer.pdf.JustTradePDFExtractor;
import name.abuchen.portfolio.datatransfer.pdf.PDFInputFile;
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;
@SuppressWarnings("nls")
public class JustTradePDFExtractorTest
{
@Test
public void testKauf01()
{
JustTradePDFExtractor extractor = new JustTradePDFExtractor(new Client());
List<Exception> errors = new ArrayList<>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Kauf01.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();
Security security = ((SecurityItem) item.orElseThrow(IllegalArgumentException::new)).getSecurity();
assertThat(security.getIsin(), is("IE00B1FZS350"));
assertThat(security.getWkn(), is("A0LEW8"));
assertThat(security.getName(), is("ISHSII-DEV.MKTS PROP.YLD U.ETF"));
// check transaction
item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
BuySellEntry entry = (BuySellEntry) item.orElseThrow(IllegalArgumentException::new).getSubject();
PortfolioTransaction tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.BUY));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1340.64))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2020-01-02T00:00")));
assertThat(tx.getShares(), is(Values.Share.factorize(53)));
assertThat(tx.getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0))));
}
@Test
public void testKauf02()
{
JustTradePDFExtractor extractor = new JustTradePDFExtractor(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();
Security security = ((SecurityItem) item.orElseThrow(IllegalArgumentException::new)).getSecurity();
assertThat(security.getIsin(), is("IE00BK5BQT80"));
assertThat(security.getName(), is("Vanguard FTSE All-World U.ETF Re"));
// check transaction
item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
BuySellEntry entry = (BuySellEntry) item.orElseThrow(IllegalArgumentException::new).getSubject();
PortfolioTransaction tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.BUY));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2083.94))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2020-06-03T09:27:01")));
assertThat(tx.getShares(), is(Values.Share.factorize(29)));
assertThat(tx.getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0))));
}
@Test
public void testVerkauf01()
{
JustTradePDFExtractor extractor = new JustTradePDFExtractor(new Client());
List<Exception> errors = new ArrayList<>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkauf01.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();
Security security = ((SecurityItem) item.orElseThrow(IllegalArgumentException::new)).getSecurity();
assertThat(security.getIsin(), is("DE000CL9E825"));
assertThat(security.getName(), is("Leveraged Certificate auf DAX"));
// check transaction
item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
BuySellEntry entry = (BuySellEntry) item.orElseThrow(IllegalArgumentException::new).getSubject();
PortfolioTransaction tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.SELL));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2232.23))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2020-07-31T21:00:15")));
assertThat(tx.getShares(), is(Values.Share.factorize(58)));
assertThat(tx.getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0))));
assertThat(tx.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.77))));
}
@Test
public void testSammelabrechnung01()
{
JustTradePDFExtractor extractor = new JustTradePDFExtractor(new Client());
List<Exception> errors = new ArrayList<>();
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Sammelabrechnung01.txt"), errors);
assertThat(errors, empty());
assertThat(results.size(), is(9));
new AssertImportActions().check(results, CurrencyUnit.EUR);
// check security
Optional<Item> item = results.stream().filter(i -> i instanceof SecurityItem).findFirst();
Security security = ((SecurityItem) item.orElseThrow(IllegalArgumentException::new)).getSecurity();
assertThat(security.getIsin(), is("DE000SR8YZ53"));
assertThat(security.getName(), is("Leveraged Certificate auf DAX / XDAX COMBI INDEX"));
// check first transaction
item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
BuySellEntry entry = (BuySellEntry) item.orElseThrow(IllegalArgumentException::new).getSubject();
PortfolioTransaction tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.BUY));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1228.00))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2020-08-10T14:31:04")));
assertThat(tx.getShares(), is(Values.Share.factorize(100)));
assertThat(tx.getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0))));
assertThat(tx.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0))));
// check second transaction
item = results.stream().filter(i -> i instanceof BuySellEntryItem).skip(1).findFirst();
entry = (BuySellEntry) item.orElseThrow(IllegalArgumentException::new).getSubject();
tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.BUY));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1575.00))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2020-08-10T15:48:16")));
assertThat(tx.getShares(), is(Values.Share.factorize(125)));
// check fifth second transaction
item = results.stream().filter(i -> i instanceof BuySellEntryItem).skip(4).findFirst();
entry = (BuySellEntry) item.orElseThrow(IllegalArgumentException::new).getSubject();
tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.SELL));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1262.00))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2020-08-10T15:33:52")));
assertThat(tx.getShares(), is(Values.Share.factorize(100)));
// check sixth second transaction
item = results.stream().filter(i -> i instanceof BuySellEntryItem).skip(5).findFirst();
entry = (BuySellEntry) item.orElseThrow(IllegalArgumentException::new).getSubject();
tx = entry.getPortfolioTransaction();
assertThat(tx.getType(), is(PortfolioTransaction.Type.SELL));
assertThat(tx.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1576.25))));
assertThat(tx.getDateTime(), is(LocalDateTime.parse("2020-08-10T15:50:52")));
assertThat(tx.getShares(), is(Values.Share.factorize(125)));
}
}