Added parametrized test for FlowableExcelMapper
This commit is contained in:
@@ -26,21 +26,21 @@ public class FlowableExcelMapper {
|
||||
}
|
||||
|
||||
public ArrayNode excelToJsonNode(String excelPath) {
|
||||
ArrayList<ArrayList<Object>> rawList = flowableExcelParser.parseExcel(excelPath);
|
||||
ArrayList<ArrayList<Object>> rows = flowableExcelParser.parseExcel(excelPath);
|
||||
ArrayList<Object> paths = new ArrayList<>();
|
||||
ArrayList<Object> types = new ArrayList<>();
|
||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||
for (int rowNum = 0; rowNum < rawList.size(); rowNum++) {
|
||||
for (int rowNum = 0; rowNum < rows.size(); rowNum++) {
|
||||
if (rowNum == 0) {
|
||||
// The 1st row contains the paths
|
||||
paths.addAll(rawList.get(rowNum));
|
||||
paths.addAll(rows.get(rowNum));
|
||||
} else if (rowNum == 1) {
|
||||
// The 1st row contains the types of the variables
|
||||
types.addAll(rawList.get(rowNum));
|
||||
types.addAll(rows.get(rowNum));
|
||||
} else {
|
||||
// All other rows contain the values of the variables
|
||||
JsonNode jsonNode = null;
|
||||
ArrayList<Object> row = rawList.get(rowNum);
|
||||
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();
|
||||
|
||||
@@ -2,14 +2,20 @@ package com.example.parser;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@SpringBootTest
|
||||
@@ -33,4 +39,20 @@ class FlowableExcelMapperTest {
|
||||
JsonNode node = flowableExcelMapper.excelToJsonNode(getResourcePath("flowableExcelMapperTestData.xlsx"));
|
||||
logger.info("node2={}{}", System.lineSeparator(), node.toPrettyString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Stream<Arguments> excelToJsonNodeParametrizedTestData() {
|
||||
ArrayList<Arguments> argumentList = new ArrayList<>();
|
||||
JsonNode nodes = flowableExcelMapper.excelToJsonNode(getResourcePath("flowableExcelMapperTestData.xlsx"));
|
||||
for (JsonNode node : nodes) {
|
||||
argumentList.add(Arguments.of(node));
|
||||
}
|
||||
return argumentList.stream();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("excelToJsonNodeParametrizedTestData")
|
||||
public void excelToJsonNodeParametrizedTest(JsonNode node) {
|
||||
logger.info("node2={}{}", System.lineSeparator(), node.toPrettyString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user