Added handling of Excel work books
This commit is contained in:
@@ -2,7 +2,6 @@ package com.example.parser;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
@@ -21,12 +20,37 @@ public class FlowableExcelMapper {
|
|||||||
protected static FlowableExcelParser flowableExcelParser = new FlowableExcelParser();
|
protected static FlowableExcelParser flowableExcelParser = new FlowableExcelParser();
|
||||||
|
|
||||||
public FlowableExcelMapper() {
|
public FlowableExcelMapper() {
|
||||||
|
// Enable ObjectMapper for handling Instant
|
||||||
objectMapper.registerModule(javaTimeModule);
|
objectMapper.registerModule(javaTimeModule);
|
||||||
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayNode excelToJsonNode(String excelPath) {
|
// excelPath defines the location of the Excel file
|
||||||
ArrayList<ArrayList<Object>> rows = flowableExcelParser.parseExcel(excelPath);
|
// FlowableExcelParser is used to create an ArrayList from the Excel file
|
||||||
|
// The first row of every sheet contains the path of the variables to be created in the JsonNode
|
||||||
|
// Delimiter is "." for an ObjectNode and "*" for an ArrayNode
|
||||||
|
// The 2nd row contains tht type of the variable. Supported types are:
|
||||||
|
// - String
|
||||||
|
// - Boolean
|
||||||
|
// - Integer
|
||||||
|
// - Double
|
||||||
|
// - Date
|
||||||
|
// All sheets are added to an ArrayNode
|
||||||
|
// All rows are added to an ArrayNode in the sheets ArrayNode
|
||||||
|
// All cell values are added to an ObjectNode in the rows ArrayNode
|
||||||
|
public ArrayNode excelBookToJsonNode(String excelPath) {
|
||||||
|
ArrayList<ArrayList<ArrayList<Object>>> book = flowableExcelParser.parseExcelBook(excelPath);
|
||||||
|
return bookToJsonNode(book);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArrayNode bookToJsonNode(ArrayList<ArrayList<ArrayList<Object>>> book) {
|
||||||
|
ArrayNode bookNode = objectMapper.createArrayNode();
|
||||||
|
for (ArrayList<ArrayList<Object>> sheet : book) {
|
||||||
|
bookNode.add(sheetToJsonNode(sheet));
|
||||||
|
}
|
||||||
|
return bookNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArrayNode sheetToJsonNode(ArrayList<ArrayList<Object>> rows) {
|
||||||
ArrayList<Object> paths = new ArrayList<>();
|
ArrayList<Object> paths = new ArrayList<>();
|
||||||
ArrayList<Object> types = new ArrayList<>();
|
ArrayList<Object> types = new ArrayList<>();
|
||||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||||
@@ -39,31 +63,35 @@ public class FlowableExcelMapper {
|
|||||||
types.addAll(rows.get(rowNum));
|
types.addAll(rows.get(rowNum));
|
||||||
} else {
|
} else {
|
||||||
// All other rows contain the values of the variables
|
// All other rows contain the values of the variables
|
||||||
JsonNode jsonNode = null;
|
arrayNode.add(rowToJsonNode(types, paths, rows.get(rowNum), null));
|
||||||
ArrayList<Object> row = rows.get(rowNum);
|
|
||||||
for (int cellNum = 0; cellNum < row.size(); cellNum++) {
|
|
||||||
Object content = row.get(cellNum);
|
|
||||||
String type = types.get(cellNum).toString();
|
|
||||||
switch (type) {
|
|
||||||
case "String": content = content.toString(); break;
|
|
||||||
case "Boolean": content = Boolean.parseBoolean(content.toString()); break;
|
|
||||||
case "Integer": content = (int) Double.parseDouble(content.toString()); break;
|
|
||||||
case "Double": content = Double.parseDouble(content.toString()); break;
|
|
||||||
case "Date":
|
|
||||||
// Excel considers dates as local dates, but we want them as UTC
|
|
||||||
Date dateTime = DateUtil.getJavaDate(Double.parseDouble(content.toString()));
|
|
||||||
content = dateTime.toInstant().plusSeconds(ZonedDateTime.now().getOffset().getTotalSeconds());
|
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
jsonNode = addNode(jsonNode, paths.get(cellNum).toString(), content);
|
|
||||||
}
|
|
||||||
arrayNode.add(jsonNode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return arrayNode;
|
return arrayNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected JsonNode rowToJsonNode(ArrayList<Object> types, ArrayList<Object> paths, ArrayList<Object> row, JsonNode jsonNode) {
|
||||||
|
for (int cellNum = 0; cellNum < row.size(); cellNum++) {
|
||||||
|
Object content = row.get(cellNum);
|
||||||
|
if (content != null) {
|
||||||
|
String type = types.get(cellNum).toString();
|
||||||
|
switch (type) {
|
||||||
|
case "String": content = content.toString(); break;
|
||||||
|
case "Boolean": content = Boolean.parseBoolean(content.toString()); break;
|
||||||
|
case "Integer": content = (int) Double.parseDouble(content.toString()); break;
|
||||||
|
case "Double": content = Double.parseDouble(content.toString()); break;
|
||||||
|
case "Date":
|
||||||
|
// Excel considers dates as local dates, but we want them as UTC
|
||||||
|
Date dateTime = DateUtil.getJavaDate(Double.parseDouble(content.toString()));
|
||||||
|
content = dateTime.toInstant().plusSeconds(ZonedDateTime.now().getOffset().getTotalSeconds());
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonNode = addNode(jsonNode, paths.get(cellNum).toString(), content);
|
||||||
|
}
|
||||||
|
return jsonNode;
|
||||||
|
}
|
||||||
|
|
||||||
protected JsonNode addNode(JsonNode parent, String path, Object value) {
|
protected JsonNode addNode(JsonNode parent, String path, Object value) {
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
parent = objectMapper.createObjectNode();
|
parent = objectMapper.createObjectNode();
|
||||||
@@ -77,7 +105,8 @@ public class FlowableExcelMapper {
|
|||||||
} else {
|
} else {
|
||||||
// Index of a value in an ArrayNode
|
// Index of a value in an ArrayNode
|
||||||
int index = Integer.parseInt(path);
|
int index = Integer.parseInt(path);
|
||||||
for (int i = 0; parent.size() <= index; i++) {
|
while (parent.size() <= index) {
|
||||||
|
// Create empty entries to parent ArrayNode
|
||||||
((ArrayNode) parent).add(objectMapper.createObjectNode());
|
((ArrayNode) parent).add(objectMapper.createObjectNode());
|
||||||
}
|
}
|
||||||
((ArrayNode) parent).set(index, objectMapper.valueToTree(value));
|
((ArrayNode) parent).set(index, objectMapper.valueToTree(value));
|
||||||
@@ -112,8 +141,8 @@ public class FlowableExcelMapper {
|
|||||||
// Take the existing ArrayNode as child
|
// Take the existing ArrayNode as child
|
||||||
child = node;
|
child = node;
|
||||||
}
|
}
|
||||||
// Create empty entries to parent ArrayNode
|
while (parent.size() <= index) {
|
||||||
for (int i = 0; parent.size() <= index; i++) {
|
// Create empty entries to parent ArrayNode
|
||||||
((ArrayNode) parent).add(objectMapper.createObjectNode());
|
((ArrayNode) parent).add(objectMapper.createObjectNode());
|
||||||
}
|
}
|
||||||
((ArrayNode) parent).set(index, addNode(child, newPath, value));
|
((ArrayNode) parent).set(index, addNode(child, newPath, value));
|
||||||
|
|||||||
@@ -9,62 +9,104 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class FlowableExcelParser {
|
public class FlowableExcelParser {
|
||||||
|
|
||||||
// resourcePath defines the location of the Excel file
|
// excelPath defines the location of the Excel file
|
||||||
// Return all cells in the 1st sheet which have values as objects (String, boolean or double)
|
// Return all cells in all sheets with the following restrictions:
|
||||||
// The 1st row defines the amount of cells per row
|
// - Max columns per sheet is defined in the first row
|
||||||
// Parsing the sheet stops after the 1st empty row
|
// - Max column count starts with the 1st cell and ends with the 1st empty cell
|
||||||
public ArrayList<ArrayList<Object>> parseExcel(String resourcePath) {
|
// - Parsing the sheet stops after the 1st empty row
|
||||||
ArrayList<ArrayList<Object>> rows = new ArrayList<>();
|
// All sheets are added to an ArrayList
|
||||||
try (FileInputStream fileInputStream = new FileInputStream(resourcePath)) {
|
// All rows are added to an ArrayList in the sheets ArrayList
|
||||||
Workbook workbook = new XSSFWorkbook(fileInputStream);
|
// All cell values are added to an ArrayList in the rows ArrayList
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
// Formulas in cells are evaluated
|
||||||
int maxCells = 0;
|
// Excel values can have only 3 types: String, boolean, double
|
||||||
for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
|
public ArrayList<ArrayList<ArrayList<Object>>> parseExcelBook(String excelPath) {
|
||||||
Row row = sheet.getRow(rowNum);
|
try (FileInputStream fileInputStream = new FileInputStream(excelPath)) {
|
||||||
if (row == null) {
|
Workbook workBook = new XSSFWorkbook(fileInputStream);
|
||||||
break;
|
return parseBook(workBook);
|
||||||
}
|
|
||||||
if (maxCells == 0) {
|
|
||||||
maxCells = row.getLastCellNum();
|
|
||||||
}
|
|
||||||
boolean allCellsNull = true;
|
|
||||||
ArrayList<Object> cells = new ArrayList<>();
|
|
||||||
for (int cellNum = 0; cellNum < maxCells; cellNum++) {
|
|
||||||
Cell cell = row.getCell(cellNum);
|
|
||||||
if(rowNum == 0) {
|
|
||||||
if (cell == null || cell.getCellType() == CellType.BLANK || cell.getCellType() == CellType._NONE) {
|
|
||||||
// Count cells of 1st row until the first empty cell
|
|
||||||
maxCells = cellNum;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CellValue cellValue = workbook.getCreationHelper().createFormulaEvaluator().evaluate(cell);
|
|
||||||
Object content = null;
|
|
||||||
if (cellValue != null) {
|
|
||||||
CellType cellType = cell.getCellType();
|
|
||||||
if (cellType != CellType.BLANK && cellType != CellType._NONE) {
|
|
||||||
switch (cellValue.getCellType()) {
|
|
||||||
case STRING : content = cellValue.getStringValue(); break;
|
|
||||||
case BOOLEAN : content = cellValue.getBooleanValue(); break;
|
|
||||||
case NUMERIC : content = cellValue.getNumberValue(); break;
|
|
||||||
}
|
|
||||||
allCellsNull = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cells.add(content);
|
|
||||||
}
|
|
||||||
if (allCellsNull) {
|
|
||||||
// Take all rows until the first empty row
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
rows.add(cells);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return rows;
|
}
|
||||||
|
|
||||||
|
protected ArrayList<ArrayList<ArrayList<Object>>> parseBook(Workbook workBook ) {
|
||||||
|
ArrayList<ArrayList<ArrayList<Object>>> book = new ArrayList<>();
|
||||||
|
FormulaEvaluator formulaEvaluator = workBook.getCreationHelper().createFormulaEvaluator();
|
||||||
|
for (Sheet workSheet : workBook) {
|
||||||
|
book.add(parseSheet(workSheet, formulaEvaluator));
|
||||||
|
}
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArrayList<ArrayList<Object>> parseSheet(Sheet workSheet, FormulaEvaluator formulaEvaluator) {
|
||||||
|
ArrayList<ArrayList<Object>> sheet = new ArrayList<>();
|
||||||
|
// Count columns of first row
|
||||||
|
int maxCols = getMaxCols(workSheet.getRow(0));
|
||||||
|
int lastRowNum = workSheet.getLastRowNum();
|
||||||
|
for (int rowIndex = 0; rowIndex < lastRowNum; rowIndex++) {
|
||||||
|
Row workRow = workSheet.getRow(rowIndex);
|
||||||
|
ArrayList<Object> row = parseRow(workRow, maxCols, formulaEvaluator);
|
||||||
|
if (row == null) {
|
||||||
|
// Take all rows until the first empty row
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
sheet.add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ArrayList<Object> parseRow(Row workRow, int maxCols, FormulaEvaluator formulaEvaluator) {
|
||||||
|
if (workRow == null) {
|
||||||
|
// Row is empty
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<Object> row = new ArrayList<>();
|
||||||
|
boolean allCellsNull = true;
|
||||||
|
for (int colIndex = 0; colIndex < maxCols; colIndex++) {
|
||||||
|
Object content = null;
|
||||||
|
Cell workCell = workRow.getCell(colIndex);
|
||||||
|
if (workCell != null) {
|
||||||
|
CellType workCellType = workCell.getCellType();
|
||||||
|
if (workCellType != CellType.BLANK && workCellType != CellType._NONE) {
|
||||||
|
allCellsNull = false;
|
||||||
|
switch (workCellType) {
|
||||||
|
case STRING : content = workCell.getStringCellValue(); break;
|
||||||
|
case BOOLEAN : content = workCell.getBooleanCellValue(); break;
|
||||||
|
case NUMERIC : content = workCell.getNumericCellValue(); break;
|
||||||
|
case FORMULA :
|
||||||
|
CellValue evaluatedValue = formulaEvaluator.evaluate(workCell);
|
||||||
|
switch (evaluatedValue.getCellType()) {
|
||||||
|
case STRING : content = evaluatedValue.getStringValue(); break;
|
||||||
|
case BOOLEAN : content = evaluatedValue.getBooleanValue(); break;
|
||||||
|
case NUMERIC : content = evaluatedValue.getNumberValue(); break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
row.add(content);
|
||||||
|
}
|
||||||
|
if (allCellsNull) {
|
||||||
|
// Row is empty
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getMaxCols(Row workRow) {
|
||||||
|
int maxCol = workRow.getLastCellNum();
|
||||||
|
for (int colIndex = 0; colIndex < maxCol; colIndex++) {
|
||||||
|
Cell workCell = workRow.getCell(colIndex);
|
||||||
|
if (workCell == null || workCell.getCellType() == CellType.BLANK || workCell.getCellType() == CellType._NONE) {
|
||||||
|
// Count cells until the first empty cell
|
||||||
|
return colIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxCol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ public class ParserApp {
|
|||||||
|
|
||||||
URL resourceUrl = ParserApp.class.getClassLoader().getResource("flowableExcelParserExampleData.xlsx");
|
URL resourceUrl = ParserApp.class.getClassLoader().getResource("flowableExcelParserExampleData.xlsx");
|
||||||
assert resourceUrl != null;
|
assert resourceUrl != null;
|
||||||
logger.info("parsed excel={}", flowableExcelParser.parseExcel(resourceUrl.getPath()));
|
logger.info("parsed excel={}", flowableExcelParser.parseExcelBook(resourceUrl.getPath()));
|
||||||
|
|
||||||
resourceUrl = ParserApp.class.getClassLoader().getResource("flowableExcelMapperExampleData.xlsx");
|
resourceUrl = ParserApp.class.getClassLoader().getResource("flowableExcelMapperExampleData.xlsx");
|
||||||
assert resourceUrl != null;
|
assert resourceUrl != null;
|
||||||
logger.info("mapped excel={}", flowableExcelMapper.excelToJsonNode(resourceUrl.getPath()));
|
logger.info("mapped excel={}", flowableExcelMapper.excelBookToJsonNode(resourceUrl.getPath()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.example.parser;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.assertj.core.api.Assertions;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
@@ -17,6 +16,7 @@ import java.net.URL;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class FlowableExcelMapperTest {
|
class FlowableExcelMapperTest {
|
||||||
@@ -34,25 +34,24 @@ class FlowableExcelMapperTest {
|
|||||||
return resourceUrl.getPath();
|
return resourceUrl.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
protected Stream<Arguments> getArgumentsFromExcel(String path) {
|
||||||
public void excelToJsonNodeTest() {
|
|
||||||
JsonNode node = flowableExcelMapper.excelToJsonNode(getResourcePath("flowableExcelMapperTestData.xlsx"));
|
|
||||||
logger.info("node2={}{}", System.lineSeparator(), node.toPrettyString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Stream<Arguments> excelToJsonNodeParametrizedTestData() {
|
|
||||||
ArrayList<Arguments> argumentList = new ArrayList<>();
|
ArrayList<Arguments> argumentList = new ArrayList<>();
|
||||||
JsonNode nodes = flowableExcelMapper.excelToJsonNode(getResourcePath("flowableExcelMapperTestData.xlsx"));
|
JsonNode book = flowableExcelMapper.excelBookToJsonNode(getResourcePath(path));
|
||||||
for (JsonNode node : nodes) {
|
for (JsonNode sheet : book) {
|
||||||
argumentList.add(Arguments.of(node));
|
for (JsonNode row : sheet) {
|
||||||
|
argumentList.add(Arguments.of(row));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return argumentList.stream();
|
return argumentList.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected Stream<Arguments> excelMapperTestData() {
|
||||||
|
return getArgumentsFromExcel("flowableExcelMapperTestData.xlsx");
|
||||||
|
}
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("excelToJsonNodeParametrizedTestData")
|
@MethodSource("excelMapperTestData")
|
||||||
public void excelToJsonNodeParametrizedTest(JsonNode node) {
|
public void excelMapperTest(JsonNode sheet) {
|
||||||
logger.info("node2={}{}", System.lineSeparator(), node.toPrettyString());
|
logger.info("node2={}{}", System.lineSeparator(), sheet.toPrettyString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.net.URL;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class FlowableExcelParserTest {
|
class FlowableExcelParserTest {
|
||||||
@@ -27,22 +28,23 @@ class FlowableExcelParserTest {
|
|||||||
return resourceUrl.getPath();
|
return resourceUrl.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Stream<Arguments> GetArgumentsFromExcel(String path) {
|
protected Stream<Arguments> getArgumentsFromExcel(String path) {
|
||||||
|
ArrayList<ArrayList<ArrayList<Object>>> book = flowableExcelParser.parseExcelBook(getResourcePath(path));
|
||||||
ArrayList<Arguments> argumentList = new ArrayList<>();
|
ArrayList<Arguments> argumentList = new ArrayList<>();
|
||||||
ArrayList<ArrayList<Object>> rowList = flowableExcelParser.parseExcel(getResourcePath(path));
|
for (ArrayList<ArrayList<Object>> sheet : book) {
|
||||||
for (ArrayList<Object> row : rowList) {
|
for (ArrayList<Object> row : sheet) {
|
||||||
argumentList.add(Arguments.of(row));
|
argumentList.add(Arguments.of(row));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return argumentList.stream();
|
return argumentList.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Stream<Arguments> booleanExcelParserTestDataProvider() {
|
protected Stream<Arguments> booleanExcelParserTestData() {
|
||||||
return GetArgumentsFromExcel("flowableExcelParserTestData1.xlsx");
|
return getArgumentsFromExcel("flowableExcelParserTestData1.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("booleanExcelParserTestDataProvider")
|
@MethodSource("booleanExcelParserTestData")
|
||||||
void booleanExcelParserTest(ArrayList<Object> row) {
|
void booleanExcelParserTest(ArrayList<Object> row) {
|
||||||
Boolean valOr = (Boolean) row.get(0) || (Boolean) row.get(1) || (Boolean) row.get(2);
|
Boolean valOr = (Boolean) row.get(0) || (Boolean) row.get(1) || (Boolean) row.get(2);
|
||||||
Assertions.assertThat(row.get(3)).isEqualTo(valOr);
|
Assertions.assertThat(row.get(3)).isEqualTo(valOr);
|
||||||
@@ -52,12 +54,11 @@ class FlowableExcelParserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Stream<Arguments> stringExcelParserTestDataProvider() {
|
protected Stream<Arguments> stringExcelParserTestData() {
|
||||||
return GetArgumentsFromExcel("flowableExcelParserTestData2.xlsx");
|
return getArgumentsFromExcel("flowableExcelParserTestData2.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("stringExcelParserTestDataProvider")
|
@MethodSource("stringExcelParserTestData")
|
||||||
void stringExcelParserTest(ArrayList<Object> row) {
|
void stringExcelParserTest(ArrayList<Object> row) {
|
||||||
String val12 = row.get(0).toString() + row.get(1).toString();
|
String val12 = row.get(0).toString() + row.get(1).toString();
|
||||||
Assertions.assertThat(row.get(3)).isEqualTo(val12);
|
Assertions.assertThat(row.get(3)).isEqualTo(val12);
|
||||||
@@ -70,12 +71,11 @@ class FlowableExcelParserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Stream<Arguments> numberExcelParserTestDataProvider() {
|
protected Stream<Arguments> numberExcelParserTestData() {
|
||||||
return GetArgumentsFromExcel("flowableExcelParserTestData3.xlsx");
|
return getArgumentsFromExcel("flowableExcelParserTestData3.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("numberExcelParserTestDataProvider")
|
@MethodSource("numberExcelParserTestData")
|
||||||
void numberExcelParserTest(ArrayList<Object> row) {
|
void numberExcelParserTest(ArrayList<Object> row) {
|
||||||
Double val12 = (Double) row.get(0) + (Double) row.get(1);
|
Double val12 = (Double) row.get(0) + (Double) row.get(1);
|
||||||
Assertions.assertThat(row.get(3)).isEqualTo(val12);
|
Assertions.assertThat(row.get(3)).isEqualTo(val12);
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user