|
| 1 | +package name.abuchen.portfolio.datatransfer.pdf.vdkbanknv; |
| 2 | + |
| 3 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.check; |
| 4 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.dividend; |
| 5 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasAmount; |
| 6 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasCurrencyCode; |
| 7 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasDate; |
| 8 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasFees; |
| 9 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasForexGrossValue; |
| 10 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasGrossValue; |
| 11 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasIsin; |
| 12 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasName; |
| 13 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasNote; |
| 14 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasShares; |
| 15 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasSource; |
| 16 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasTaxes; |
| 17 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasTicker; |
| 18 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasWkn; |
| 19 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.purchase; |
| 20 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.sale; |
| 21 | +import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.security; |
| 22 | +import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countAccountTransactions; |
| 23 | +import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countBuySell; |
| 24 | +import static name.abuchen.portfolio.datatransfer.ExtractorTestUtilities.countSecurities; |
| 25 | +import static org.hamcrest.CoreMatchers.hasItem; |
| 26 | +import static org.hamcrest.CoreMatchers.is; |
| 27 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | +import static org.hamcrest.collection.IsEmptyCollection.empty; |
| 29 | + |
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.List; |
| 32 | + |
| 33 | +import org.junit.Test; |
| 34 | + |
| 35 | +import name.abuchen.portfolio.datatransfer.ImportAction.Status; |
| 36 | +import name.abuchen.portfolio.datatransfer.actions.AssertImportActions; |
| 37 | +import name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction; |
| 38 | +import name.abuchen.portfolio.datatransfer.pdf.PDFInputFile; |
| 39 | +import name.abuchen.portfolio.datatransfer.pdf.VDKBankNVPDFExtractor; |
| 40 | +import name.abuchen.portfolio.model.Client; |
| 41 | +import name.abuchen.portfolio.model.Portfolio; |
| 42 | +import name.abuchen.portfolio.model.PortfolioTransaction; |
| 43 | +import name.abuchen.portfolio.model.Security; |
| 44 | + |
| 45 | +@SuppressWarnings("nls") |
| 46 | +public class VDKBankNVPDFExtractorTest |
| 47 | +{ |
| 48 | + @Test |
| 49 | + public void testAankoop01() |
| 50 | + { |
| 51 | + var extractor = new VDKBankNVPDFExtractor(new Client()); |
| 52 | + |
| 53 | + List<Exception> errors = new ArrayList<>(); |
| 54 | + |
| 55 | + var results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Aankoop01.txt"), errors); |
| 56 | + |
| 57 | + assertThat(errors, empty()); |
| 58 | + assertThat(countSecurities(results), is(1L)); |
| 59 | + assertThat(countBuySell(results), is(1L)); |
| 60 | + assertThat(countAccountTransactions(results), is(0L)); |
| 61 | + assertThat(results.size(), is(2)); |
| 62 | + new AssertImportActions().check(results, "EUR"); |
| 63 | + |
| 64 | + // check security |
| 65 | + assertThat(results, hasItem(security( // |
| 66 | + hasIsin("US0138721065"), hasWkn(null), hasTicker(null), // |
| 67 | + hasName("Alcoa Corp"), // |
| 68 | + hasCurrencyCode("USD")))); |
| 69 | + |
| 70 | + // check buy sell transaction |
| 71 | + assertThat(results, hasItem(purchase( // |
| 72 | + hasDate("2025-04-21T19:44"), hasShares(100.00), // |
| 73 | + hasSource("Aankoop01.txt"), // |
| 74 | + hasNote("Borderel-Ref.: 2025.000123456789 | Ord.-Ref.: 395693"), // |
| 75 | + hasAmount("EUR", 2047.36), hasGrossValue("EUR", 2004.63), // |
| 76 | + hasForexGrossValue("USD", 2298.56), // |
| 77 | + hasTaxes("EUR", (8.04 / 1.146626)), hasFees("EUR", 35.72)))); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testAankoop01WithSecurityInEUR() |
| 82 | + { |
| 83 | + var security = new Security("Alcoa Corp", "EUR"); |
| 84 | + security.setIsin("US0138721065"); |
| 85 | + |
| 86 | + var client = new Client(); |
| 87 | + client.addSecurity(security); |
| 88 | + |
| 89 | + var extractor = new VDKBankNVPDFExtractor(client); |
| 90 | + |
| 91 | + List<Exception> errors = new ArrayList<>(); |
| 92 | + |
| 93 | + var results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Aankoop01.txt"), errors); |
| 94 | + |
| 95 | + assertThat(errors, empty()); |
| 96 | + assertThat(countSecurities(results), is(0L)); |
| 97 | + assertThat(countBuySell(results), is(1L)); |
| 98 | + assertThat(countAccountTransactions(results), is(0L)); |
| 99 | + assertThat(results.size(), is(1)); |
| 100 | + new AssertImportActions().check(results, "EUR"); |
| 101 | + |
| 102 | + // check buy sell transaction |
| 103 | + assertThat(results, hasItem(purchase( // |
| 104 | + hasDate("2025-04-21T19:44"), hasShares(100.00), // |
| 105 | + hasSource("Aankoop01.txt"), // |
| 106 | + hasNote("Borderel-Ref.: 2025.000123456789 | Ord.-Ref.: 395693"), // |
| 107 | + hasAmount("EUR", 2047.36), hasGrossValue("EUR", 2004.63), // |
| 108 | + hasTaxes("EUR", (8.04 / 1.146626)), hasFees("EUR", 35.72), // |
| 109 | + check(tx -> { |
| 110 | + var c = new CheckCurrenciesAction(); |
| 111 | + var s = c.process((PortfolioTransaction) tx, new Portfolio()); |
| 112 | + assertThat(s, is(Status.OK_STATUS)); |
| 113 | + })))); |
| 114 | + } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void testVerkoop01() |
| 118 | + { |
| 119 | + var extractor = new VDKBankNVPDFExtractor(new Client()); |
| 120 | + |
| 121 | + List<Exception> errors = new ArrayList<>(); |
| 122 | + |
| 123 | + var results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkoop01.txt"), errors); |
| 124 | + |
| 125 | + assertThat(errors, empty()); |
| 126 | + assertThat(countSecurities(results), is(1L)); |
| 127 | + assertThat(countBuySell(results), is(1L)); |
| 128 | + assertThat(countAccountTransactions(results), is(0L)); |
| 129 | + assertThat(results.size(), is(2)); |
| 130 | + new AssertImportActions().check(results, "EUR"); |
| 131 | + |
| 132 | + // check security |
| 133 | + assertThat(results, hasItem(security( // |
| 134 | + hasIsin("BE0974320526"), hasWkn(null), hasTicker(null), // |
| 135 | + hasName("Umicore NV"), // |
| 136 | + hasCurrencyCode("EUR")))); |
| 137 | + |
| 138 | + // check buy sell transaction |
| 139 | + assertThat(results, hasItem(sale( // |
| 140 | + hasDate("2025-04-03T12:45:20"), hasShares(100.00), // |
| 141 | + hasSource("Verkoop01.txt"), // |
| 142 | + hasNote("Borderel-Ref.: 2025.000123456789 | Ord.-Ref.: 297671"), // |
| 143 | + hasAmount("EUR", 852.07), hasGrossValue("EUR", 870.00), // |
| 144 | + hasTaxes("EUR", 3.05), hasFees("EUR", 9.92 + 4.96)))); |
| 145 | + } |
| 146 | + |
| 147 | + @Test |
| 148 | + public void testVerkoop02() |
| 149 | + { |
| 150 | + var extractor = new VDKBankNVPDFExtractor(new Client()); |
| 151 | + |
| 152 | + List<Exception> errors = new ArrayList<>(); |
| 153 | + |
| 154 | + var results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkoop02.txt"), errors); |
| 155 | + |
| 156 | + assertThat(errors, empty()); |
| 157 | + assertThat(countSecurities(results), is(1L)); |
| 158 | + assertThat(countBuySell(results), is(1L)); |
| 159 | + assertThat(countAccountTransactions(results), is(0L)); |
| 160 | + assertThat(results.size(), is(2)); |
| 161 | + new AssertImportActions().check(results, "EUR"); |
| 162 | + |
| 163 | + // check security |
| 164 | + assertThat(results, hasItem(security( // |
| 165 | + hasIsin("NO0010786288"), hasWkn(null), hasTicker(null), // |
| 166 | + hasName("Norwegian Govt 1,750% 17/02/2027"), // |
| 167 | + hasCurrencyCode("NOK")))); |
| 168 | + |
| 169 | + // check buy sell transaction |
| 170 | + assertThat(results, hasItem(sale( // |
| 171 | + hasDate("2024-07-19T12:44:20"), hasShares(800.00), // |
| 172 | + hasSource("Verkoop02.txt"), // |
| 173 | + hasNote("Borderel-Ref.: 2024.000123456789 | Ord.-Ref.: 088618"), // |
| 174 | + hasAmount("EUR", 6449.78), hasGrossValue("EUR", 6493.67), // |
| 175 | + hasForexGrossValue("NOK", 76443.20), // |
| 176 | + hasTaxes("EUR", 0.00), hasFees("EUR", 43.89)))); |
| 177 | + } |
| 178 | + |
| 179 | + @Test |
| 180 | + public void testVerkoop02WithSecurityInEUR() |
| 181 | + { |
| 182 | + var security = new Security("Norwegian Govt 1,750% 17/02/2027", "EUR"); |
| 183 | + security.setIsin("NO0010786288"); |
| 184 | + |
| 185 | + var client = new Client(); |
| 186 | + client.addSecurity(security); |
| 187 | + |
| 188 | + var extractor = new VDKBankNVPDFExtractor(client); |
| 189 | + |
| 190 | + List<Exception> errors = new ArrayList<>(); |
| 191 | + |
| 192 | + var results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkoop02.txt"), errors); |
| 193 | + |
| 194 | + assertThat(errors, empty()); |
| 195 | + assertThat(countSecurities(results), is(0L)); |
| 196 | + assertThat(countBuySell(results), is(1L)); |
| 197 | + assertThat(countAccountTransactions(results), is(0L)); |
| 198 | + assertThat(results.size(), is(1)); |
| 199 | + new AssertImportActions().check(results, "EUR"); |
| 200 | + |
| 201 | + // check buy sell transaction |
| 202 | + assertThat(results, hasItem(sale( // |
| 203 | + hasDate("2024-07-19T12:44:20"), hasShares(800.00), // |
| 204 | + hasSource("Verkoop02.txt"), // |
| 205 | + hasNote("Borderel-Ref.: 2024.000123456789 | Ord.-Ref.: 088618"), // |
| 206 | + hasAmount("EUR", 6449.78), hasGrossValue("EUR", 6493.67), // |
| 207 | + hasTaxes("EUR", 0.00), hasFees("EUR", 43.89), // |
| 208 | + check(tx -> { |
| 209 | + var c = new CheckCurrenciesAction(); |
| 210 | + var s = c.process((PortfolioTransaction) tx, new Portfolio()); |
| 211 | + assertThat(s, is(Status.OK_STATUS)); |
| 212 | + })))); |
| 213 | + } |
| 214 | + |
| 215 | + @Test |
| 216 | + public void testDividende01() |
| 217 | + { |
| 218 | + var extractor = new VDKBankNVPDFExtractor(new Client()); |
| 219 | + |
| 220 | + List<Exception> errors = new ArrayList<>(); |
| 221 | + |
| 222 | + var results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Dividend01.txt"), errors); |
| 223 | + |
| 224 | + assertThat(errors, empty()); |
| 225 | + assertThat(countSecurities(results), is(1L)); |
| 226 | + assertThat(countBuySell(results), is(0L)); |
| 227 | + assertThat(countAccountTransactions(results), is(1L)); |
| 228 | + assertThat(results.size(), is(2)); |
| 229 | + new AssertImportActions().check(results, "EUR"); |
| 230 | + |
| 231 | + // check security |
| 232 | + assertThat(results, hasItem(security( // |
| 233 | + hasIsin("BE0003470755"), hasWkn(null), hasTicker(null), // |
| 234 | + hasName("Solvay NV"), // |
| 235 | + hasCurrencyCode("EUR")))); |
| 236 | + |
| 237 | + // check dividends transaction |
| 238 | + assertThat(results, hasItem(dividend( // |
| 239 | + hasDate("2024-01-17T00:00"), hasShares(100.00), // |
| 240 | + hasSource("Dividend01.txt"), // |
| 241 | + hasNote("Borderel-Ref.: 2024.000123456789 | Ord.-Ref.: D046336-758"), // |
| 242 | + hasAmount("EUR", 113.40), hasGrossValue("EUR", 162.00), // |
| 243 | + hasTaxes("EUR", 48.60), hasFees("EUR", 0.00)))); |
| 244 | + } |
| 245 | +} |
0 commit comments