|
7 | 7 | import org.junit.Test; |
8 | 8 | import org.junit.runner.RunWith; |
9 | 9 |
|
10 | | -import java.io.IOException; |
| 10 | +import java.io.*; |
11 | 11 | import java.nio.file.Files; |
12 | 12 | import java.nio.file.Paths; |
13 | 13 |
|
14 | | -import static com.codingchili.Model.FileParser.ITEMS; |
15 | | - |
16 | 14 | /** |
17 | 15 | * @author Robin Duda |
18 | 16 | */ |
19 | 17 | @RunWith(VertxUnitRunner.class) |
20 | 18 | public class TestParser { |
21 | | - private static final int ROW_OFFSET = 5; |
| 19 | + public static final String TEST_XLSX_FILE = "src/test/java/test.xlsx"; |
| 20 | + public static final String TEST_XLS_FILE = "src/test/java/test.xls"; |
| 21 | + public static final String TEST_INVALID_FILE = "src/test/java/test_invalid.xlsx"; |
| 22 | + public static final int ROW_OFFSET = 5; |
22 | 23 | private static final String XLSX = ".xlsx"; |
23 | 24 |
|
24 | 25 | @Test |
25 | 26 | public void failParseInvalid() throws Exception { |
26 | 27 | try { |
27 | | - new FileParser(new byte[2048], 5, XLSX); |
| 28 | + new FileParser(new File(TEST_INVALID_FILE), 5, XLSX); |
28 | 29 | throw new Exception("Should fail for invalid bytes."); |
29 | 30 | } catch (ParserException ignored) { |
30 | 31 | } |
31 | 32 | } |
32 | 33 |
|
33 | 34 | @Test |
34 | 35 | public void testParseOOXML(TestContext context) throws IOException, ParserException { |
35 | | - testParseFile(context, "src/test/java/test.xlsx"); |
| 36 | + testParseFile(context, TEST_XLSX_FILE); |
36 | 37 | } |
37 | 38 |
|
38 | 39 | @Test |
39 | 40 | public void testParse2007(TestContext context) throws IOException, ParserException { |
40 | | - testParseFile(context, "src/test/java/test.xls"); |
| 41 | + testParseFile(context, TEST_XLS_FILE); |
41 | 42 | } |
42 | 43 |
|
43 | 44 | private void testParseFile(TestContext context, String fileName) throws IOException, ParserException { |
44 | | - FileParser parser = new FileParser(Files.readAllBytes(Paths.get(fileName)), ROW_OFFSET, fileName); |
45 | | - JsonArray list = parser.toImportable("index", "mapping", false).getJsonArray(ITEMS); |
| 45 | + FileParser parser = new FileParser( |
| 46 | + Paths.get(fileName).toFile(), |
| 47 | + ROW_OFFSET, |
| 48 | + fileName |
| 49 | + ); |
| 50 | + |
| 51 | + parser.assertFileParsable(); |
| 52 | + |
| 53 | + JsonArray list = new JsonArray(); |
| 54 | + parser.parseRowRange(0, parser.getNumberOfElements(), list::add); |
46 | 55 |
|
47 | 56 | context.assertEquals(2, list.size()); |
48 | 57 |
|
|
0 commit comments