embulk-parser-poi_excel 0.1.4 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -5
  3. data/build.gradle +18 -8
  4. data/src/main/java/org/embulk/parser/poi_excel/PoiExcelColumnValueType.java +4 -0
  5. data/src/main/java/org/embulk/parser/poi_excel/PoiExcelParserPlugin.java +80 -3
  6. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnBean.java +103 -6
  7. data/src/main/java/org/embulk/parser/poi_excel/bean/PoiExcelColumnIndex.java +74 -37
  8. data/src/main/java/org/embulk/parser/poi_excel/bean/util/PoiExcelCellAddress.java +50 -0
  9. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellFontVisitor.java +0 -6
  10. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellStyleVisitor.java +11 -11
  11. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellTypeVisitor.java +52 -0
  12. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelCellValueVisitor.java +106 -37
  13. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelClientAnchorVisitor.java +1 -1
  14. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelColumnVisitor.java +64 -4
  15. data/src/main/java/org/embulk/parser/poi_excel/visitor/PoiExcelVisitorFactory.java +14 -0
  16. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/BooleanCellVisitor.java +5 -0
  17. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/CellVisitor.java +3 -0
  18. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/DoubleCellVisitor.java +5 -0
  19. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/LongCellVisitor.java +5 -0
  20. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/StringCellVisitor.java +30 -2
  21. data/src/main/java/org/embulk/parser/poi_excel/visitor/embulk/TimestampCellVisitor.java +5 -0
  22. data/src/main/java/org/embulk/parser/poi_excel/visitor/util/MergedRegionMap.java +51 -0
  23. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin.java +27 -79
  24. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellAddress.java +69 -0
  25. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellComment.java +1 -1
  26. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellError.java +1 -1
  27. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellFont.java +1 -1
  28. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellStyle.java +14 -14
  29. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_cellType.java +79 -0
  30. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_columnNumber.java +1 -1
  31. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_constant.java +1 -1
  32. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_convertError.java +1 -1
  33. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_formula.java +90 -0
  34. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_mergedCell.java +89 -0
  35. data/src/test/java/org/embulk/parser/poi_excel/TestPoiExcelParserPlugin_sheets.java +35 -1
  36. metadata +26 -18
@@ -0,0 +1,69 @@
1
+ package org.embulk.parser.poi_excel;
2
+
3
+ import static org.hamcrest.CoreMatchers.is;
4
+ import static org.hamcrest.MatcherAssert.assertThat;
5
+
6
+ import java.net.URL;
7
+ import java.text.ParseException;
8
+ import java.util.List;
9
+
10
+ import org.embulk.parser.EmbulkPluginTester;
11
+ import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
12
+ import org.embulk.parser.EmbulkTestParserConfig;
13
+ import org.junit.experimental.theories.DataPoints;
14
+ import org.junit.experimental.theories.Theories;
15
+ import org.junit.experimental.theories.Theory;
16
+ import org.junit.runner.RunWith;
17
+
18
+ @RunWith(Theories.class)
19
+ public class TestPoiExcelParserPlugin_cellAddress {
20
+
21
+ @DataPoints
22
+ public static String[] FILES = { "test1.xls", "test2.xlsx" };
23
+
24
+ @Theory
25
+ public void testCellAddress(String excelFile) throws ParseException {
26
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
27
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
28
+
29
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
30
+ parser.set("sheet", "test1");
31
+ parser.set("skip_header_lines", 1);
32
+ parser.addColumn("text", "string").set("column_number", "D");
33
+ parser.addColumn("fix_value", "string").set("cell_address", "B1").set("value", "cell_value");
34
+ parser.addColumn("fix_sheet", "string").set("cell_address", "B1").set("value", "sheet_name");
35
+ parser.addColumn("fix_row", "long").set("cell_address", "B1").set("value", "row_number");
36
+ parser.addColumn("fix_col", "long").set("cell_address", "B1").set("value", "column_number");
37
+ parser.addColumn("other_sheet_value", "string").set("cell_address", "style!B5").set("value", "cell_value");
38
+ parser.addColumn("other_sheet_name", "string").set("cell_address", "style!B5").set("value", "sheet_name");
39
+ parser.addColumn("other_sheet_row", "long").set("cell_address", "style!B5").set("value", "row_number");
40
+ parser.addColumn("other_sheet_col", "string").set("cell_address", "style!B5").set("value", "column_number");
41
+
42
+ URL inFile = getClass().getResource(excelFile);
43
+ List<OutputRecord> result = tester.runParser(inFile, parser);
44
+
45
+ assertThat(result.size(), is(7));
46
+ check1(result, 0, "abc");
47
+ check1(result, 1, "def");
48
+ check1(result, 2, "456");
49
+ check1(result, 3, "abc");
50
+ check1(result, 4, "abc");
51
+ check1(result, 5, "true");
52
+ check1(result, 6, null);
53
+ }
54
+ }
55
+
56
+ private void check1(List<OutputRecord> result, int index, String text) {
57
+ OutputRecord record = result.get(index);
58
+ // System.out.println(record);
59
+ assertThat(record.getAsString("text"), is(text));
60
+ assertThat(record.getAsString("fix_value"), is("long"));
61
+ assertThat(record.getAsString("fix_sheet"), is("test1"));
62
+ assertThat(record.getAsLong("fix_row"), is(1L));
63
+ assertThat(record.getAsLong("fix_col"), is(2L));
64
+ assertThat(record.getAsString("other_sheet_value"), is("bottom"));
65
+ assertThat(record.getAsString("other_sheet_name"), is("style"));
66
+ assertThat(record.getAsLong("other_sheet_row"), is(5L));
67
+ assertThat(record.getAsString("other_sheet_col"), is("B"));
68
+ }
69
+ }
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
4
  import static org.hamcrest.CoreMatchers.nullValue;
5
- import static org.junit.Assert.assertThat;
5
+ import static org.hamcrest.MatcherAssert.assertThat;
6
6
  import static org.junit.Assert.fail;
7
7
 
8
8
  import java.net.URL;
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
4
  import static org.hamcrest.CoreMatchers.nullValue;
5
- import static org.junit.Assert.assertThat;
5
+ import static org.hamcrest.MatcherAssert.assertThat;
6
6
  import static org.junit.Assert.fail;
7
7
 
8
8
  import java.net.URL;
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
4
  import static org.hamcrest.CoreMatchers.nullValue;
5
- import static org.junit.Assert.assertThat;
5
+ import static org.hamcrest.MatcherAssert.assertThat;
6
6
  import static org.junit.Assert.fail;
7
7
 
8
8
  import java.net.URL;
@@ -1,7 +1,7 @@
1
1
  package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
- import static org.junit.Assert.assertThat;
4
+ import static org.hamcrest.MatcherAssert.assertThat;
5
5
  import static org.junit.Assert.fail;
6
6
 
7
7
  import java.net.URL;
@@ -9,7 +9,7 @@ import java.text.ParseException;
9
9
  import java.util.Arrays;
10
10
  import java.util.List;
11
11
 
12
- import org.apache.poi.ss.usermodel.CellStyle;
12
+ import org.apache.poi.ss.usermodel.BorderStyle;
13
13
  import org.embulk.parser.EmbulkPluginTester;
14
14
  import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
15
15
  import org.embulk.parser.EmbulkTestParserConfig;
@@ -44,11 +44,11 @@ public class TestPoiExcelParserPlugin_cellStyle {
44
44
  List<OutputRecord> result = tester.runParser(inFile, parser);
45
45
 
46
46
  assertThat(result.size(), is(5));
47
- check1(result, 0, "red", 255, 0, 0, "top", CellStyle.BORDER_THIN, 0, 0, 0);
47
+ check1(result, 0, "red", 255, 0, 0, "top", BorderStyle.THIN.getCode(), 0, 0, 0);
48
48
  check1(result, 1, "green", 0, 128, 0, null, 0, 0, 0, 0);
49
- check1(result, 2, "blue", 0, 0, 255, "left", 0, 0, CellStyle.BORDER_THIN, 0);
50
- check1(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, CellStyle.BORDER_THIN);
51
- check1(result, 4, "black", 0, 0, 0, "bottom", 0, CellStyle.BORDER_MEDIUM, 0, 0);
49
+ check1(result, 2, "blue", 0, 0, 255, "left", 0, 0, BorderStyle.THIN.getCode(), 0);
50
+ check1(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, BorderStyle.THIN.getCode());
51
+ check1(result, 4, "black", 0, 0, 0, "bottom", 0, BorderStyle.MEDIUM.getCode(), 0, 0);
52
52
  }
53
53
  }
54
54
 
@@ -81,11 +81,11 @@ public class TestPoiExcelParserPlugin_cellStyle {
81
81
  List<OutputRecord> result = tester.runParser(inFile, parser);
82
82
 
83
83
  assertThat(result.size(), is(5));
84
- check2(result, 0, "red", 255, 0, 0, "top", CellStyle.BORDER_THIN, 0, 0, 0);
84
+ check2(result, 0, "red", 255, 0, 0, "top", BorderStyle.THIN.getCode(), 0, 0, 0);
85
85
  check2(result, 1, "green", 0, 128, 0, null, 0, 0, 0, 0);
86
- check2(result, 2, "blue", 0, 0, 255, "left", 0, 0, CellStyle.BORDER_THIN, 0);
87
- check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, CellStyle.BORDER_THIN);
88
- check2(result, 4, "black", 0, 0, 0, "bottom", 0, CellStyle.BORDER_MEDIUM, 0, 0);
86
+ check2(result, 2, "blue", 0, 0, 255, "left", 0, 0, BorderStyle.THIN.getCode(), 0);
87
+ check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, BorderStyle.THIN.getCode());
88
+ check2(result, 4, "black", 0, 0, 0, "bottom", 0, BorderStyle.MEDIUM.getCode(), 0, 0);
89
89
  }
90
90
  }
91
91
 
@@ -130,11 +130,11 @@ public class TestPoiExcelParserPlugin_cellStyle {
130
130
  List<OutputRecord> result = tester.runParser(inFile, parser);
131
131
 
132
132
  assertThat(result.size(), is(5));
133
- check2(result, 0, "red", 255, 0, 0, "top", CellStyle.BORDER_THIN, 0, 0, 0);
133
+ check2(result, 0, "red", 255, 0, 0, "top", BorderStyle.THIN.getCode(), 0, 0, 0);
134
134
  check2(result, 1, "green", 0, 128, 0, null, 0, 0, 0, 0);
135
- check2(result, 2, "blue", 0, 0, 255, "left", 0, 0, CellStyle.BORDER_THIN, 0);
136
- check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, CellStyle.BORDER_THIN);
137
- check2(result, 4, "black", 0, 0, 0, "bottom", 0, CellStyle.BORDER_MEDIUM, 0, 0);
135
+ check2(result, 2, "blue", 0, 0, 255, "left", 0, 0, BorderStyle.THIN.getCode(), 0);
136
+ check2(result, 3, "white", 255, 255, 255, "right", 0, 0, 0, BorderStyle.THIN.getCode());
137
+ check2(result, 4, "black", 0, 0, 0, "bottom", 0, BorderStyle.MEDIUM.getCode(), 0, 0);
138
138
  }
139
139
  }
140
140
  }
@@ -0,0 +1,79 @@
1
+ package org.embulk.parser.poi_excel;
2
+
3
+ import static org.hamcrest.CoreMatchers.is;
4
+ import static org.hamcrest.MatcherAssert.assertThat;
5
+
6
+ import java.net.URL;
7
+ import java.text.ParseException;
8
+ import java.util.Arrays;
9
+ import java.util.List;
10
+
11
+ import org.apache.poi.ss.usermodel.CellType;
12
+ import org.embulk.parser.EmbulkPluginTester;
13
+ import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
14
+ import org.embulk.parser.EmbulkTestParserConfig;
15
+ import org.junit.experimental.theories.DataPoints;
16
+ import org.junit.experimental.theories.Theories;
17
+ import org.junit.experimental.theories.Theory;
18
+ import org.junit.runner.RunWith;
19
+
20
+ @RunWith(Theories.class)
21
+ public class TestPoiExcelParserPlugin_cellType {
22
+
23
+ @DataPoints
24
+ public static String[] FILES = { "test1.xls", "test2.xlsx" };
25
+
26
+ @Theory
27
+ public void testCellType(String excelFile) throws ParseException {
28
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
29
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
30
+
31
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
32
+ parser.set("sheets", Arrays.asList("test1"));
33
+ parser.set("skip_header_lines", 3);
34
+ parser.addColumn("long", "long").set("column_number", "A").set("value", "cell_type");
35
+ parser.addColumn("string", "string").set("column_number", "A").set("value", "cell_type");
36
+
37
+ URL inFile = getClass().getResource(excelFile);
38
+ List<OutputRecord> result = tester.runParser(inFile, parser);
39
+
40
+ assertThat(result.size(), is(5));
41
+ check1(result, 0, CellType.NUMERIC, "NUMERIC");
42
+ check1(result, 1, CellType.STRING, "STRING");
43
+ check1(result, 2, CellType.FORMULA, "FORMULA");
44
+ check1(result, 3, CellType.BOOLEAN, "BOOLEAN");
45
+ check1(result, 4, CellType.FORMULA, "FORMULA");
46
+ }
47
+ }
48
+
49
+ @Theory
50
+ public void testCellCachedType(String excelFile) throws ParseException {
51
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
52
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
53
+
54
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
55
+ parser.set("sheets", Arrays.asList("test1"));
56
+ parser.set("skip_header_lines", 3);
57
+ parser.addColumn("long", "long").set("column_number", "A").set("value", "cell_cached_type");
58
+ parser.addColumn("string", "string").set("column_number", "A").set("value", "cell_cached_type");
59
+
60
+ URL inFile = getClass().getResource(excelFile);
61
+ List<OutputRecord> result = tester.runParser(inFile, parser);
62
+
63
+ assertThat(result.size(), is(5));
64
+ check1(result, 0, CellType.NUMERIC, "NUMERIC");
65
+ check1(result, 1, CellType.STRING, "STRING");
66
+ check1(result, 2, CellType.BOOLEAN, "BOOLEAN");
67
+ check1(result, 3, CellType.BOOLEAN, "BOOLEAN");
68
+ check1(result, 4, CellType.ERROR, "ERROR");
69
+ }
70
+ }
71
+
72
+ @SuppressWarnings("deprecation")
73
+ private void check1(List<OutputRecord> result, int index, CellType cellType, String s) throws ParseException {
74
+ OutputRecord r = result.get(index);
75
+ // System.out.println(r);
76
+ assertThat(r.getAsLong("long"), is((long) cellType.getCode()));
77
+ assertThat(r.getAsString("string"), is(s));
78
+ }
79
+ }
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
4
  import static org.hamcrest.CoreMatchers.nullValue;
5
- import static org.junit.Assert.assertThat;
5
+ import static org.hamcrest.MatcherAssert.assertThat;
6
6
 
7
7
  import java.net.URL;
8
8
  import java.text.ParseException;
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
4
  import static org.hamcrest.CoreMatchers.nullValue;
5
- import static org.junit.Assert.assertThat;
5
+ import static org.hamcrest.MatcherAssert.assertThat;
6
6
 
7
7
  import java.net.URL;
8
8
  import java.text.ParseException;
@@ -2,7 +2,7 @@ package org.embulk.parser.poi_excel;
2
2
 
3
3
  import static org.hamcrest.CoreMatchers.is;
4
4
  import static org.hamcrest.CoreMatchers.nullValue;
5
- import static org.junit.Assert.assertThat;
5
+ import static org.hamcrest.MatcherAssert.assertThat;
6
6
  import static org.junit.Assert.fail;
7
7
 
8
8
  import java.net.URL;
@@ -0,0 +1,90 @@
1
+ package org.embulk.parser.poi_excel;
2
+
3
+ import static org.hamcrest.CoreMatchers.is;
4
+ import static org.hamcrest.MatcherAssert.assertThat;
5
+
6
+ import java.net.URL;
7
+ import java.text.ParseException;
8
+ import java.util.Arrays;
9
+ import java.util.List;
10
+
11
+ import org.embulk.config.ConfigSource;
12
+ import org.embulk.parser.EmbulkPluginTester;
13
+ import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
14
+ import org.embulk.parser.EmbulkTestParserConfig;
15
+ import org.junit.experimental.theories.DataPoints;
16
+ import org.junit.experimental.theories.Theories;
17
+ import org.junit.experimental.theories.Theory;
18
+ import org.junit.runner.RunWith;
19
+
20
+ @RunWith(Theories.class)
21
+ public class TestPoiExcelParserPlugin_formula {
22
+
23
+ @DataPoints
24
+ public static String[] FILES = { "test1.xls", "test2.xlsx" };
25
+
26
+ @Theory
27
+ public void testForumlaHandlingCashedValue(String excelFile) throws ParseException {
28
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
29
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
30
+
31
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
32
+ parser.set("sheet", "formula_replace");
33
+
34
+ parser.addColumn("text", "string").set("formula_handling", "cashed_value");
35
+
36
+ URL inFile = getClass().getResource(excelFile);
37
+ List<OutputRecord> result = tester.runParser(inFile, parser);
38
+
39
+ assertThat(result.size(), is(2));
40
+ assertThat(result.get(0).getAsString("text"), is("boolean"));
41
+ assertThat(result.get(1).getAsString("text"), is("test2-b1"));
42
+ }
43
+ }
44
+
45
+ @Theory
46
+ public void testForumlaHandlingEvaluate(String excelFile) throws ParseException {
47
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
48
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
49
+
50
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
51
+ parser.set("sheet", "formula_replace");
52
+
53
+ parser.addColumn("text", "string").set("formula_handling", "evaluate");
54
+
55
+ URL inFile = getClass().getResource(excelFile);
56
+ List<OutputRecord> result = tester.runParser(inFile, parser);
57
+
58
+ assertThat(result.size(), is(2));
59
+ assertThat(result.get(0).getAsString("text"), is("boolean"));
60
+ assertThat(result.get(1).getAsString("text"), is("test2-b1"));
61
+ }
62
+ }
63
+
64
+ @Theory
65
+ public void testForumlaReplace(String excelFile) throws ParseException {
66
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
67
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
68
+
69
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
70
+ parser.set("sheet", "formula_replace");
71
+
72
+ ConfigSource replace0 = tester.newConfigSource();
73
+ replace0.set("regex", "test1");
74
+ replace0.set("to", "merged_cell");
75
+ ConfigSource replace1 = tester.newConfigSource();
76
+ replace1.set("regex", "B1");
77
+ replace1.set("to", "B${row}");
78
+ parser.set("formula_replace", Arrays.asList(replace0, replace1));
79
+
80
+ parser.addColumn("text", "string");
81
+
82
+ URL inFile = getClass().getResource(excelFile);
83
+ List<OutputRecord> result = tester.runParser(inFile, parser);
84
+
85
+ assertThat(result.size(), is(2));
86
+ assertThat(result.get(0).getAsString("text"), is("test3-a1"));
87
+ assertThat(result.get(1).getAsString("text"), is("test2-b2"));
88
+ }
89
+ }
90
+ }
@@ -0,0 +1,89 @@
1
+ package org.embulk.parser.poi_excel;
2
+
3
+ import static org.hamcrest.CoreMatchers.is;
4
+ import static org.hamcrest.MatcherAssert.assertThat;
5
+
6
+ import java.net.URL;
7
+ import java.text.ParseException;
8
+ import java.util.List;
9
+
10
+ import org.embulk.parser.EmbulkPluginTester;
11
+ import org.embulk.parser.EmbulkTestOutputPlugin.OutputRecord;
12
+ import org.embulk.parser.EmbulkTestParserConfig;
13
+ import org.junit.experimental.theories.DataPoints;
14
+ import org.junit.experimental.theories.Theories;
15
+ import org.junit.experimental.theories.Theory;
16
+ import org.junit.runner.RunWith;
17
+
18
+ @RunWith(Theories.class)
19
+ public class TestPoiExcelParserPlugin_mergedCell {
20
+
21
+ @DataPoints
22
+ public static String[] FILES = { "test1.xls", "test2.xlsx" };
23
+
24
+ @Theory
25
+ public void testSearchMergedCell_default(String excelFile) throws ParseException {
26
+ test(excelFile, null, true);
27
+ }
28
+
29
+ @Theory
30
+ public void testSearchMergedCell_true(String excelFile) throws ParseException {
31
+ // compatibility ver 0.1.7
32
+ test(excelFile, true, true);
33
+ }
34
+
35
+ @Theory
36
+ public void testSearchMergedCell_false(String excelFile) throws ParseException {
37
+ // compatibility ver 0.1.7
38
+ test(excelFile, false, false);
39
+ }
40
+
41
+ @Theory
42
+ public void testSearchMergedCell_none(String excelFile) throws ParseException {
43
+ test(excelFile, "none", false);
44
+ }
45
+
46
+ @Theory
47
+ public void testSearchMergedCell_linear(String excelFile) throws ParseException {
48
+ test(excelFile, "linear_search", true);
49
+ }
50
+
51
+ @Theory
52
+ public void testSearchMergedCell_tree(String excelFile) throws ParseException {
53
+ test(excelFile, "tree_search", true);
54
+ }
55
+
56
+ private void test(String excelFile, Object arg, boolean search) {
57
+ try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
58
+ tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);
59
+
60
+ EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
61
+ parser.set("sheet", "merged_cell");
62
+ if (arg != null) {
63
+ parser.set("search_merged_cell", arg);
64
+ }
65
+ parser.addColumn("a", "string");
66
+ parser.addColumn("b", "string");
67
+
68
+ URL inFile = getClass().getResource(excelFile);
69
+ List<OutputRecord> result = tester.runParser(inFile, parser);
70
+
71
+ assertThat(result.size(), is(4));
72
+ if (search) {
73
+ check6(result, 0, "test3-a1", "test3-a1");
74
+ } else {
75
+ check6(result, 0, "test3-a1", null);
76
+ }
77
+ check6(result, 1, "data", "0");
78
+ check6(result, 2, null, null);
79
+ check6(result, 3, null, null);
80
+ }
81
+ }
82
+
83
+ private void check6(List<OutputRecord> result, int index, String a, String b) {
84
+ OutputRecord r = result.get(index);
85
+ // System.out.println(r);
86
+ assertThat(r.getAsString("a"), is(a));
87
+ assertThat(r.getAsString("b"), is(b));
88
+ }
89
+ }