Added parseExcel for backwards compatibility
This commit is contained in:
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
|
||||
@Component
|
||||
@@ -32,6 +33,7 @@ public class FlowableExcelParser {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ArrayList<ArrayList<Object>> parseExcelSheet(String excelPath) {
|
||||
try (FileInputStream fileInputStream = new FileInputStream(excelPath)) {
|
||||
Workbook workBook = new XSSFWorkbook(fileInputStream);
|
||||
@@ -120,4 +122,33 @@ public class FlowableExcelParser {
|
||||
}
|
||||
return maxCol;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ArrayList<LinkedHashMap<String, Object>> parseExcel(String resourcePath) {
|
||||
try (FileInputStream fileInputStream = new FileInputStream(resourcePath)) {
|
||||
Workbook workBook = new XSSFWorkbook(fileInputStream);
|
||||
FormulaEvaluator formulaEvaluator = workBook.getCreationHelper().createFormulaEvaluator();
|
||||
ArrayList<ArrayList<Object>> sheet = parseSheet(workBook.getSheetAt(0), formulaEvaluator);
|
||||
ArrayList<String> colHeaders = new ArrayList<>();
|
||||
ArrayList<LinkedHashMap<String, Object>> rowList = new ArrayList<>();
|
||||
for (int rowIndex = 0; rowIndex < sheet.size(); rowIndex++) {
|
||||
ArrayList<Object> row = sheet.get(rowIndex);
|
||||
if (rowIndex == 0) {
|
||||
// Header row
|
||||
for (Object cell : row) {
|
||||
colHeaders.add(String.valueOf(cell));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
LinkedHashMap<String, Object> rowMap = new LinkedHashMap<>();
|
||||
for (int colIndex = 0; colIndex < row.size(); colIndex++) {
|
||||
rowMap.put(colHeaders.get(colIndex), row.get(colIndex));
|
||||
}
|
||||
rowList.add(rowMap);
|
||||
}
|
||||
return rowList;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class FlowableExcelParserTest {
|
||||
return resourceUrl.getPath();
|
||||
}
|
||||
|
||||
protected Stream<Arguments> getArgumentsFromExcel(String path) {
|
||||
protected Stream<Arguments> getRowsFromExcel(String path) {
|
||||
ArrayList<Arguments> argumentList = new ArrayList<>();
|
||||
ArrayList<ArrayList<ArrayList<Object>>> book = flowableExcelParser.parseExcelBook(getResourcePath(path));
|
||||
for (ArrayList<ArrayList<Object>> sheet : book) {
|
||||
@@ -45,11 +45,11 @@ class FlowableExcelParserTest {
|
||||
|
||||
@NotNull
|
||||
protected Stream<Arguments> booleanExcelParserTestData() {
|
||||
return getArgumentsFromExcel("flowableExcelParserTestData1.xlsx");
|
||||
return getRowsFromExcel("flowableExcelParserTestDataBoolean.xlsx");
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleanExcelParserTestData")
|
||||
void booleanExcelParserTest(ArrayList<Object> row) {
|
||||
public void booleanExcelParserTest(ArrayList<Object> row) {
|
||||
Boolean valOr = (Boolean) row.get(0) || (Boolean) row.get(1) || (Boolean) row.get(2);
|
||||
Assertions.assertThat(row.get(3)).isEqualTo(valOr);
|
||||
|
||||
@@ -59,11 +59,11 @@ class FlowableExcelParserTest {
|
||||
|
||||
@NotNull
|
||||
protected Stream<Arguments> stringExcelParserTestData() {
|
||||
return getArgumentsFromExcel("flowableExcelParserTestData2.xlsx");
|
||||
return getRowsFromExcel("flowableExcelParserTestDataString.xlsx");
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("stringExcelParserTestData")
|
||||
void stringExcelParserTest(ArrayList<Object> row) {
|
||||
public void stringExcelParserTest(ArrayList<Object> row) {
|
||||
String val12 = row.get(0).toString() + row.get(1).toString();
|
||||
Assertions.assertThat(row.get(3)).isEqualTo(val12);
|
||||
|
||||
@@ -76,11 +76,11 @@ class FlowableExcelParserTest {
|
||||
|
||||
@NotNull
|
||||
protected Stream<Arguments> numberExcelParserTestData() {
|
||||
return getArgumentsFromExcel("flowableExcelParserTestData3.xlsx");
|
||||
return getRowsFromExcel("flowableExcelParserTestDataInteger.xlsx");
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("numberExcelParserTestData")
|
||||
void numberExcelParserTest(ArrayList<Object> row) {
|
||||
public void numberExcelParserTest(ArrayList<Object> row) {
|
||||
Double val12 = (Double) row.get(0) + (Double) row.get(1);
|
||||
Assertions.assertThat(row.get(3)).isEqualTo(val12);
|
||||
|
||||
@@ -90,4 +90,93 @@ class FlowableExcelParserTest {
|
||||
Double val123 = (Double) row.get(0) + (Double) row.get(1) + (Double) row.get(2);
|
||||
Assertions.assertThat(row.get(5)).isEqualTo(val123);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected Stream<Arguments> getArgumentsFromExcel(String path) {
|
||||
ArrayList<Arguments> argumentList = new ArrayList<>();
|
||||
ArrayList<LinkedHashMap<String, Object>> rowList = flowableExcelParser.parseExcel(getResourcePath(path));
|
||||
for (LinkedHashMap<String, Object> row : rowList) {
|
||||
LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, Object> outputMap = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (List.of("input1", "input2", "input3").contains(key)) {
|
||||
inputMap.put(key, entry.getValue());
|
||||
}
|
||||
if (List.of("output1", "output2", "output3").contains(key)) {
|
||||
outputMap.put(key, entry.getValue());
|
||||
}
|
||||
}
|
||||
argumentList.add(Arguments.of(inputMap, outputMap));
|
||||
}
|
||||
return argumentList.stream();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Stream<Arguments> booleanExcelParserTestDataProvider() {
|
||||
return getArgumentsFromExcel("flowableExcelParserTestDataBooleanOld.xlsx");
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("booleanExcelParserTestDataProvider")
|
||||
public void booleanExcelParserTest(LinkedHashMap<String, Object> inputMap, LinkedHashMap<String, Object> outputMap) {
|
||||
for (Map.Entry<String, Object> entry : outputMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (key.equals("output1")) {
|
||||
Boolean val = (Boolean)inputMap.get("input1") || (Boolean)inputMap.get("input2") || (Boolean)inputMap.get("input3");
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
if (key.equals("output2")) {
|
||||
Boolean val = (Boolean)inputMap.get("input1") && (Boolean)inputMap.get("input2") && (Boolean)inputMap.get("input3");
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Stream<Arguments> stringExcelParserTestDataProvider() {
|
||||
return getArgumentsFromExcel("flowableExcelParserTestDataStringOld.xlsx");
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("stringExcelParserTestDataProvider")
|
||||
public void stringExcelParserTest(LinkedHashMap<String, Object> inputMap, LinkedHashMap<String, Object> outputMap) {
|
||||
for (Map.Entry<String, Object> entry : outputMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (key.equals("output1")) {
|
||||
String val = inputMap.get("input1").toString() + inputMap.get("input2").toString();
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
if (key.equals("output2")) {
|
||||
String val = inputMap.get("input2").toString() + inputMap.get("input3").toString();
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
if (key.equals("output3")) {
|
||||
String val = inputMap.get("input1").toString() + inputMap.get("input2").toString() + inputMap.get("input3").toString();
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Stream<Arguments> numberExcelParserTestDataProvider() {
|
||||
return getArgumentsFromExcel("flowableExcelParserTestDataIntegerOld.xlsx");
|
||||
}
|
||||
@ParameterizedTest
|
||||
@MethodSource("numberExcelParserTestDataProvider")
|
||||
public void numberExcelParserTest(LinkedHashMap<String, Object> inputMap, LinkedHashMap<String, Object> outputMap) {
|
||||
for (Map.Entry<String, Object> entry : outputMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (key.equals("output1")) {
|
||||
Double val = (Double)inputMap.get("input1") + (Double)inputMap.get("input2");
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
if (key.equals("output2")) {
|
||||
Double val = (Double)inputMap.get("input2") + (Double)inputMap.get("input3");
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
if (key.equals("output3")) {
|
||||
Double val = (Double)inputMap.get("input1") + (Double)inputMap.get("input2") + (Double)inputMap.get("input3");
|
||||
Assertions.assertThat(entry.getValue()).isEqualTo(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user