removed warnings
This commit is contained in:
@@ -44,7 +44,7 @@ public class JsonUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> convertJsonNodeToMap(JsonNode jsonNode) {
|
public Map<String, Object> convertJsonNodeToMap(JsonNode jsonNode) {
|
||||||
return objectMapper.convertValue(jsonNode, new TypeReference<Map<String, Object>>() {});
|
return objectMapper.convertValue(jsonNode, new TypeReference<>() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> flatten(Object payload) {
|
public Map<String, Object> flatten(Object payload) {
|
||||||
@@ -57,7 +57,7 @@ public class JsonUtils {
|
|||||||
|
|
||||||
public Map<String, Object> unflatten(Map<String, Object> flatVars) {
|
public Map<String, Object> unflatten(Map<String, Object> flatVars) {
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(JsonUnflattener.unflatten(flatVars), Map.class);
|
return objectMapper.readValue(JsonUnflattener.unflatten(flatVars), new TypeReference<>() {});
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ public class JsonUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> convertObjectNodeToMap(ObjectNode objectNode) {
|
public Map<String, Object> convertObjectNodeToMap(ObjectNode objectNode) {
|
||||||
return objectMapper.convertValue(objectNode, new TypeReference<Map<String, Object>>() {});
|
return objectMapper.convertValue(objectNode, new TypeReference<>() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectNode getEmptyObjectNode() {
|
public ObjectNode getEmptyObjectNode() {
|
||||||
|
|||||||
@@ -2,48 +2,5 @@ package com.customer.work.model;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EmailDto {
|
public record EmailDto(String subject, List<String> receiverList, String content, Object contentRaw) {
|
||||||
private String subject;
|
|
||||||
private List<String> receiverList;
|
|
||||||
private String content;
|
|
||||||
private Object contentRaw;
|
|
||||||
|
|
||||||
public EmailDto(String subject, List<String> receiverList, String content, Object contentRaw) {
|
|
||||||
this.subject = subject;
|
|
||||||
this.receiverList = receiverList;
|
|
||||||
this.content = content;
|
|
||||||
this.contentRaw = contentRaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSubject() {
|
|
||||||
return subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubject(String subject) {
|
|
||||||
this.subject = subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getReceiverList() {
|
|
||||||
return receiverList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReceiverList(List<String> receiverList) {
|
|
||||||
this.receiverList = receiverList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(String content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getContentRaw() {
|
|
||||||
return contentRaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContentRaw(Object contentRaw) {
|
|
||||||
this.contentRaw = contentRaw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.customer.work.model;
|
package com.customer.work.model;
|
||||||
|
|
||||||
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.SerializationFeature;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
@@ -95,25 +94,23 @@ public class FlowableExcelMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Object parseCellValue(String type, String cellValue) {
|
protected Object parseCellValue(String type, String cellValue) {
|
||||||
switch (cellValue) {
|
return switch (cellValue) {
|
||||||
case "__NULL": return null;
|
case "__NULL" -> null;
|
||||||
case "__N_A": return "__N_A";
|
case "__N_A" -> "__N_A";
|
||||||
}
|
default -> switch (type) {
|
||||||
switch (type) {
|
case "String" -> switch (cellValue) {
|
||||||
case "String":
|
case "__EMPTY" -> "";
|
||||||
switch (cellValue) {
|
case "__BLANK" -> " ";
|
||||||
case "__EMPTY": return "";
|
default -> cellValue;
|
||||||
case "__BLANK": return " ";
|
};
|
||||||
default: return cellValue;
|
case "Boolean" -> Boolean.parseBoolean(cellValue);
|
||||||
}
|
case "Integer" -> Integer.parseInt(cellValue);
|
||||||
case "Boolean": return Boolean.parseBoolean(cellValue);
|
case "Long" -> Long.parseLong(cellValue);
|
||||||
case "Integer": return Integer.parseInt(cellValue);
|
case "Double" -> Double.parseDouble(cellValue);
|
||||||
case "Long": return Long.parseLong(cellValue);
|
case "Date" -> parseDate(cellValue);
|
||||||
case "Double": return Double.parseDouble(cellValue);
|
default -> throw new IllegalArgumentException("Variable type not supported: " + type);
|
||||||
case "Date": return parseDate(cellValue);
|
};
|
||||||
default:
|
};
|
||||||
throw new IllegalArgumentException("Variable type not supported: " + type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Instant parseDate(String cellValue) {
|
protected Instant parseDate(String cellValue) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.customer.work.model;
|
package com.customer.work.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
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.SerializationFeature;
|
||||||
@@ -9,16 +8,18 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts plain Java test data (maps, lists, scalars) into the variable types
|
||||||
|
* used by Flowable models. Maps and lists become JsonNodes by default; an inner
|
||||||
|
* map of the form {"__TYPE": "...", "__VALUE": ...} requests an explicit type.
|
||||||
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class FlowableJsonParser {
|
public class FlowableJsonParser {
|
||||||
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
private static final JavaTimeModule javaTimeModule = new JavaTimeModule();
|
|
||||||
|
|
||||||
public static final String BOOLEAN = "Boolean";
|
public static final String BOOLEAN = "Boolean";
|
||||||
public static final String STRING = "String";
|
public static final String STRING = "String";
|
||||||
public static final String INTEGER = "Integer";
|
public static final String INTEGER = "Integer";
|
||||||
@@ -30,28 +31,36 @@ public class FlowableJsonParser {
|
|||||||
public static final String MAP = "Map";
|
public static final String MAP = "Map";
|
||||||
public static final String ARRAY_LIST = "ArrayList";
|
public static final String ARRAY_LIST = "ArrayList";
|
||||||
|
|
||||||
|
protected final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
public FlowableJsonParser() {
|
public FlowableJsonParser() {
|
||||||
objectMapper.registerModule(javaTimeModule);
|
// Enable ObjectMapper for handling Instant as string
|
||||||
|
objectMapper.registerModule(new JavaTimeModule());
|
||||||
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> parseMap(Object map) throws JsonProcessingException, ClassCastException {
|
public Map<String, Object> parseMap(Object map) {
|
||||||
return (Map<String, Object>) parseObject(map);
|
Object parsed = parseObject(map);
|
||||||
|
if (!(parsed instanceof Map)) {
|
||||||
|
throw new IllegalArgumentException("Not a map: " + map);
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> result = (Map<String, Object>) parsed;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object parseObject(Object object) throws JsonProcessingException, ClassCastException {
|
public Object parseObject(Object object) {
|
||||||
if (object instanceof Map) {
|
if (object instanceof Map<?, ?> map) {
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>(Map.of());
|
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||||
for (Map.Entry<String, Object> mapEntry : ((Map<String, Object>) object).entrySet()) {
|
for (Map.Entry<?, ?> mapEntry : map.entrySet()) {
|
||||||
String key = mapEntry.getKey();
|
String key = String.valueOf(mapEntry.getKey());
|
||||||
resultMap.put(key, parseMapEntry(key, mapEntry.getValue()));
|
resultMap.put(key, parseMapEntry(key, mapEntry.getValue()));
|
||||||
}
|
}
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
if (object instanceof ArrayList) {
|
if (object instanceof List<?> list) {
|
||||||
ArrayList<Object> resultList = new ArrayList<>();
|
List<Object> resultList = new ArrayList<>();
|
||||||
for (Object arrayEntry : (ArrayList<Object>) object) {
|
for (Object arrayEntry : list) {
|
||||||
resultList.add(parseArrayEntry(arrayEntry));
|
resultList.add(parseArrayEntry(arrayEntry));
|
||||||
}
|
}
|
||||||
return resultList;
|
return resultList;
|
||||||
@@ -59,52 +68,51 @@ public class FlowableJsonParser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object parseMapEntry(String key, Object value) throws JsonProcessingException {
|
private Object parseMapEntry(String key, Object value) {
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map<?, ?> valueMap) {
|
||||||
Map<String, Object> valueMap = (Map<String, Object>) value;
|
if (valueMap.size() == 2 && valueMap.containsKey("__TYPE") && valueMap.containsKey("__VALUE")) {
|
||||||
if (valueMap.containsKey("__TYPE") && valueMap.containsKey("__VALUE") && valueMap.size() == 2) {
|
|
||||||
// if Map in Map, check if inner Map has explicit type (__TYPE and __VALUE)
|
// if Map in Map, check if inner Map has explicit type (__TYPE and __VALUE)
|
||||||
return convertObjectExplicit(valueMap.get("__VALUE"), (String) valueMap.get("__TYPE"));
|
return convertObjectExplicit(valueMap.get("__VALUE"), String.valueOf(valueMap.get("__TYPE")));
|
||||||
}
|
}
|
||||||
if (Arrays.asList("__IN", "__OUT").contains(key)) {
|
if (FlowableModelTestUtils.IN_PARAM.equals(key) || FlowableModelTestUtils.OUT_PARAM.equals(key)) {
|
||||||
// convert __IN and __OUT maps as Map
|
// convert __IN and __OUT maps as Map
|
||||||
return parseObject(value);
|
return parseObject(value);
|
||||||
}
|
}
|
||||||
// convert Map to JsonObjectNode (default in models)
|
// convert Map to JsonObjectNode (default in models)
|
||||||
return convertObjectExplicit(value, JSON_OBJECT_NODE);
|
return convertObjectExplicit(value, JSON_OBJECT_NODE);
|
||||||
}
|
}
|
||||||
if (value instanceof ArrayList) {
|
if (value instanceof List) {
|
||||||
// convert ArrayList to JsonArrayNode (default in models)
|
// convert List to JsonArrayNode (default in models)
|
||||||
return convertObjectExplicit(value, JSON_ARRAY_NODE);
|
return convertObjectExplicit(value, JSON_ARRAY_NODE);
|
||||||
}
|
}
|
||||||
// take json supported type (Boolean, String, Integer, Double)
|
// take json supported type (Boolean, String, Integer, Double)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object parseArrayEntry(Object value) throws JsonProcessingException {
|
private Object parseArrayEntry(Object value) {
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map) {
|
||||||
// convert Map to JsonObjectNode (default in models)
|
// convert Map to JsonObjectNode (default in models)
|
||||||
return convertObjectExplicit(value, JSON_OBJECT_NODE);
|
return convertObjectExplicit(value, JSON_OBJECT_NODE);
|
||||||
}
|
}
|
||||||
if (value instanceof ArrayList) {
|
if (value instanceof List) {
|
||||||
// convert ArrayList to JsonArrayNode (default in models)
|
// convert List to JsonArrayNode (default in models)
|
||||||
return convertObjectExplicit(value, JSON_ARRAY_NODE);
|
return convertObjectExplicit(value, JSON_ARRAY_NODE);
|
||||||
}
|
}
|
||||||
// take json supported type (Boolean, String, Integer, Double)
|
// take json supported type (Boolean, String, Integer, Double)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object convertObjectExplicit(Object value, String explicitType) throws JsonProcessingException {
|
private Object convertObjectExplicit(Object value, String explicitType) {
|
||||||
switch (explicitType) {
|
return switch (explicitType) {
|
||||||
case BOOLEAN: return Boolean.parseBoolean(value.toString());
|
case BOOLEAN -> Boolean.parseBoolean(value.toString());
|
||||||
case STRING: return value.toString();
|
case STRING -> value.toString();
|
||||||
case INTEGER: return Integer.parseInt(value.toString());
|
case INTEGER -> Integer.parseInt(value.toString());
|
||||||
case DOUBLE: return Double.parseDouble(value.toString());
|
case DOUBLE -> Double.parseDouble(value.toString());
|
||||||
case LONG: return Long.parseLong(value.toString());
|
case LONG -> Long.parseLong(value.toString());
|
||||||
case INSTANT: return Instant.parse(value.toString());
|
case INSTANT -> Instant.parse(value.toString());
|
||||||
case MAP: case ARRAY_LIST: return parseObject(value);
|
case MAP, ARRAY_LIST -> parseObject(value);
|
||||||
case JSON_OBJECT_NODE: case JSON_ARRAY_NODE: return objectMapper.convertValue(parseObject(value), JsonNode.class);
|
case JSON_OBJECT_NODE, JSON_ARRAY_NODE -> objectMapper.convertValue(parseObject(value), JsonNode.class);
|
||||||
default: return value;
|
default -> value;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,8 +122,8 @@ public class FlowableModelTestUtils {
|
|||||||
Assertions.assertThat(emails.size()).as("%s: invalid email number %s", hint, emailNumber).isGreaterThanOrEqualTo(emailNumber);
|
Assertions.assertThat(emails.size()).as("%s: invalid email number %s", hint, emailNumber).isGreaterThanOrEqualTo(emailNumber);
|
||||||
|
|
||||||
EmailDto email = emails.get(emailNumber - 1);
|
EmailDto email = emails.get(emailNumber - 1);
|
||||||
Assertions.assertThat(email.getSubject()).as("%s: invalid subject %s", hint, email.getSubject()).endsWith(subject);
|
Assertions.assertThat(email.subject()).as("%s: invalid subject %s", hint, email.subject()).endsWith(subject);
|
||||||
Assertions.assertThat(email.getReceiverList()).as("%s: invalid email receivers", hint)
|
Assertions.assertThat(email.receiverList()).as("%s: invalid email receivers", hint)
|
||||||
.containsExactlyInAnyOrder(receivers.split("[,\\s]+"));
|
.containsExactlyInAnyOrder(receivers.split("[,\\s]+"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,14 +227,11 @@ public class FlowableModelTestUtils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// If test is an object node, check if all fields in test exist in root
|
// If test is an object node, check if all fields in test exist in root
|
||||||
if (test.isObject()){
|
if (test.isObject()) {
|
||||||
for (Iterator<String> iterator = test.fieldNames(); iterator.hasNext(); ) {
|
for (Map.Entry<String, JsonNode> testField : test.properties()) {
|
||||||
String fieldName = iterator.next();
|
String fieldName = testField.getKey();
|
||||||
JsonNode testValue = test.get(fieldName);
|
JsonNode testValue = testField.getValue();
|
||||||
JsonNode rootValue = null;
|
JsonNode rootValue = root != null ? root.get(fieldName) : null;
|
||||||
if (root != null) {
|
|
||||||
rootValue = root.get(fieldName);
|
|
||||||
}
|
|
||||||
if (testValue.isTextual() && "__N_A".equals(testValue.asText())) {
|
if (testValue.isTextual() && "__N_A".equals(testValue.asText())) {
|
||||||
if (root != null && root.has(fieldName)) {
|
if (root != null && root.has(fieldName)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -276,12 +273,8 @@ public class FlowableModelTestUtils {
|
|||||||
ObjectNode vars = jsonUtils.getEmptyObjectNode();
|
ObjectNode vars = jsonUtils.getEmptyObjectNode();
|
||||||
JsonNode rootParam = row.get("root");
|
JsonNode rootParam = row.get("root");
|
||||||
if (rootParam != null) {
|
if (rootParam != null) {
|
||||||
Iterator<Map.Entry<String, JsonNode>> rootVars = rootParam.fields();
|
for (Map.Entry<String, JsonNode> rootVar : rootParam.properties()) {
|
||||||
while (rootVars.hasNext()) {
|
vars.set(rootVar.getKey(), rootVar.getValue());
|
||||||
Map.Entry<String, JsonNode> rootVar = rootVars.next();
|
|
||||||
String key = rootVar.getKey();
|
|
||||||
JsonNode value = rootVar.getValue();
|
|
||||||
vars.set(key, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JsonNode inParam = row.get("in");
|
JsonNode inParam = row.get("in");
|
||||||
@@ -335,20 +328,20 @@ public class FlowableModelTestUtils {
|
|||||||
|
|
||||||
public Map<String, Object> testObjExcelRow(String path, Map<String, Object> row) {
|
public Map<String, Object> testObjExcelRow(String path, Map<String, Object> row) {
|
||||||
Map<String, Object> vars = new LinkedHashMap<>();
|
Map<String, Object> vars = new LinkedHashMap<>();
|
||||||
Map<String, Object> rootParam = (Map<String, Object>) row.get("root");
|
Map<String, Object> rootParam = getMapParam(row, "root", path);
|
||||||
if (rootParam != null) {
|
if (rootParam != null) {
|
||||||
vars.putAll(rootParam);
|
vars.putAll(rootParam);
|
||||||
}
|
}
|
||||||
Map<String, Object> inParam = (Map<String, Object>) row.get("in");
|
Map<String, Object> inParam = getMapParam(row, "in", path);
|
||||||
if (inParam != null) {
|
if (inParam != null) {
|
||||||
vars.put(IN_PARAM, inParam);
|
vars.put(IN_PARAM, inParam);
|
||||||
}
|
}
|
||||||
Map<String, Object> outParam = (Map<String, Object>) row.get("out");
|
Map<String, Object> outParam = getMapParam(row, "out", path);
|
||||||
if (outParam != null) {
|
if (outParam != null) {
|
||||||
vars.put(OUT_PARAM, outParam);
|
vars.put(OUT_PARAM, outParam);
|
||||||
}
|
}
|
||||||
String idParam = (String) row.get("id");
|
String idParam = (String) row.get("id");
|
||||||
Map<String, Object> test =(Map<String, Object>) row.get("test");
|
Map<String, Object> test = getMapParam(row, "test", path);
|
||||||
int timerCount = 0;
|
int timerCount = 0;
|
||||||
Object timerNode = row.get("timer");
|
Object timerNode = row.get("timer");
|
||||||
if (timerNode != null) timerCount = (Integer) timerNode;
|
if (timerNode != null) timerCount = (Integer) timerNode;
|
||||||
@@ -388,6 +381,16 @@ public class FlowableModelTestUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected Map<String, Object> getMapParam(Map<String, Object> row, String key, String path) {
|
||||||
|
Object value = row.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Assertions.assertThat(value).as("Parameter '%s' in %s must be an object", key, path).isInstanceOf(Map.class);
|
||||||
|
return (Map<String, Object>) value;
|
||||||
|
}
|
||||||
|
|
||||||
public void exportApp(String rootUrl, String workspaceKey, String appModelKey, String username, String password) {
|
public void exportApp(String rootUrl, String workspaceKey, String appModelKey, String username, String password) {
|
||||||
RestClient restClient = RestClient.builder()
|
RestClient restClient = RestClient.builder()
|
||||||
.baseUrl(rootUrl)
|
.baseUrl(rootUrl)
|
||||||
@@ -416,7 +419,9 @@ public class FlowableModelTestUtils {
|
|||||||
public ObjectNode loadObjectNodeFromResources(String path) {
|
public ObjectNode loadObjectNodeFromResources(String path) {
|
||||||
if (path == null || path.isEmpty()) return jsonUtils.getEmptyObjectNode();
|
if (path == null || path.isEmpty()) return jsonUtils.getEmptyObjectNode();
|
||||||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path)) {
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path)) {
|
||||||
Assertions.assertThat(inputStream).as("Resource not found: %s", path).isNotNull();
|
if (inputStream == null) {
|
||||||
|
throw new IllegalArgumentException("Resource not found: " + path);
|
||||||
|
}
|
||||||
JsonNode jsonNode = jsonUtils.convertJsonStringToJsonNode(new String(inputStream.readAllBytes(), StandardCharsets.UTF_8));
|
JsonNode jsonNode = jsonUtils.convertJsonStringToJsonNode(new String(inputStream.readAllBytes(), StandardCharsets.UTF_8));
|
||||||
Assertions.assertThat(jsonNode).as("Resource %s is not a JSON object", path).isInstanceOf(ObjectNode.class);
|
Assertions.assertThat(jsonNode).as("Resource %s is not a JSON object", path).isInstanceOf(ObjectNode.class);
|
||||||
return (ObjectNode) jsonNode;
|
return (ObjectNode) jsonNode;
|
||||||
@@ -433,27 +438,21 @@ public class FlowableModelTestUtils {
|
|||||||
public Map<String, Object> loadTestVarsFromResources(String path) {
|
public Map<String, Object> loadTestVarsFromResources(String path) {
|
||||||
ObjectNode node = loadObjectNodeFromResources(path);
|
ObjectNode node = loadObjectNodeFromResources(path);
|
||||||
Map<String, Object> vars = new LinkedHashMap<>();
|
Map<String, Object> vars = new LinkedHashMap<>();
|
||||||
for (Iterator<Map.Entry<String, JsonNode>> fields = node.fields(); fields.hasNext(); ) {
|
for (Map.Entry<String, JsonNode> field : node.properties()) {
|
||||||
Map.Entry<String, JsonNode> field = fields.next();
|
|
||||||
String key = field.getKey();
|
String key = field.getKey();
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case ROOT_PARAM:
|
case ROOT_PARAM -> {
|
||||||
Assertions.assertThat(field.getValue().isObject())
|
Assertions.assertThat(field.getValue().isObject())
|
||||||
.as("%s in %s must be a JSON object", ROOT_PARAM, path).isTrue();
|
.as("%s in %s must be a JSON object", ROOT_PARAM, path).isTrue();
|
||||||
for (Iterator<String> rootKeys = field.getValue().fieldNames(); rootKeys.hasNext(); ) {
|
for (Map.Entry<String, JsonNode> rootVar : field.getValue().properties()) {
|
||||||
String rootKey = rootKeys.next();
|
Assertions.assertThat(rootVar.getKey().startsWith("__"))
|
||||||
Assertions.assertThat(rootKey.startsWith("__"))
|
.as("Root parameter '%s' in %s must not start with '__'", rootVar.getKey(), path).isFalse();
|
||||||
.as("Root parameter '%s' in %s must not start with '__'", rootKey, path).isFalse();
|
|
||||||
}
|
}
|
||||||
vars.putAll(jsonUtils.convertJsonNodeToMap(field.getValue()));
|
vars.putAll(jsonUtils.convertJsonNodeToMap(field.getValue()));
|
||||||
break;
|
}
|
||||||
case IN_PARAM:
|
case IN_PARAM, OUT_PARAM -> vars.put(key, jsonUtils.convertJsonNodeToMap(field.getValue()));
|
||||||
case OUT_PARAM:
|
default -> throw new IllegalArgumentException("Implicit parameter '" + key + "' in " + path
|
||||||
vars.put(key, jsonUtils.convertJsonNodeToMap(field.getValue()));
|
+ ": parameters must be declared explicitly inside " + ROOT_PARAM + ", " + IN_PARAM + " or " + OUT_PARAM);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Implicit parameter '" + key + "' in " + path
|
|
||||||
+ ": parameters must be declared explicitly inside " + ROOT_PARAM + ", " + IN_PARAM + " or " + OUT_PARAM);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return vars;
|
return vars;
|
||||||
@@ -505,8 +504,8 @@ public class FlowableModelTestUtils {
|
|||||||
|
|
||||||
public void completeTask(String taskId, Map<String, Object> completionVariables, String outcome) {
|
public void completeTask(String taskId, Map<String, Object> completionVariables, String outcome) {
|
||||||
CompleteFormRepresentation form = new CompleteFormRepresentation();
|
CompleteFormRepresentation form = new CompleteFormRepresentation();
|
||||||
for (String key : completionVariables.keySet()) {
|
for (Map.Entry<String, Object> entry : completionVariables.entrySet()) {
|
||||||
form.setValues(key, completionVariables.get(key));
|
form.setValues(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
form.setOutcome(outcome);
|
form.setOutcome(outcome);
|
||||||
platformTaskService.completeTaskForm(taskId, form);
|
platformTaskService.completeTaskForm(taskId, form);
|
||||||
@@ -526,8 +525,8 @@ public class FlowableModelTestUtils {
|
|||||||
return convertHistVariableListToMap(historicVariableInstanceList);
|
return convertHistVariableListToMap(historicVariableInstanceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, Object> convertHistVariableListToMap(List<HistoricVariableInstance> historicVariableInstanceList) {
|
private Map<String, Object> convertHistVariableListToMap(List<HistoricVariableInstance> historicVariableInstanceList) {
|
||||||
HashMap<String, Object> variableMap = new HashMap<>();
|
Map<String, Object> variableMap = new HashMap<>();
|
||||||
for (HistoricVariableInstance historicVariableInstance : historicVariableInstanceList) {
|
for (HistoricVariableInstance historicVariableInstance : historicVariableInstanceList) {
|
||||||
variableMap.put(historicVariableInstance.getVariableName(), historicVariableInstance.getValue());
|
variableMap.put(historicVariableInstance.getVariableName(), historicVariableInstance.getValue());
|
||||||
}
|
}
|
||||||
@@ -584,11 +583,9 @@ public class FlowableModelTestUtils {
|
|||||||
CallActivity callActivity = new CallActivity();
|
CallActivity callActivity = new CallActivity();
|
||||||
callActivity.setId(testKey);
|
callActivity.setId(testKey);
|
||||||
callActivity.setCalledElement(testKey);
|
callActivity.setCalledElement(testKey);
|
||||||
JsonNode inNode = variables.get(IN_PARAM);
|
if (variables.get(IN_PARAM) instanceof ObjectNode inNode) {
|
||||||
if (inNode instanceof ObjectNode) {
|
List<IOParameter> inParameters = new ArrayList<>();
|
||||||
Map<String, Object> inMap = jsonUtils.convertObjectNodeToMap((ObjectNode) inNode);
|
for (Map.Entry<String, JsonNode> entry : inNode.properties()) {
|
||||||
ArrayList<IOParameter> inParameters = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, Object> entry : inMap.entrySet()) {
|
|
||||||
IOParameter ioParameter = new IOParameter();
|
IOParameter ioParameter = new IOParameter();
|
||||||
ioParameter.setSourceExpression("${" + IN_PARAM + "." + entry.getKey() + "}");
|
ioParameter.setSourceExpression("${" + IN_PARAM + "." + entry.getKey() + "}");
|
||||||
ioParameter.setTarget(entry.getKey());
|
ioParameter.setTarget(entry.getKey());
|
||||||
@@ -596,14 +593,12 @@ public class FlowableModelTestUtils {
|
|||||||
}
|
}
|
||||||
callActivity.setInParameters(inParameters);
|
callActivity.setInParameters(inParameters);
|
||||||
}
|
}
|
||||||
JsonNode outNode = variables.get(OUT_PARAM);
|
if (variables.get(OUT_PARAM) instanceof ObjectNode outNode) {
|
||||||
if (outNode instanceof ObjectNode) {
|
List<IOParameter> outParameters = new ArrayList<>();
|
||||||
Map<String, String> outMap = (Map) jsonUtils.convertJsonNodeToMap(variables).get(OUT_PARAM);
|
for (Map.Entry<String, JsonNode> entry : outNode.properties()) {
|
||||||
ArrayList<IOParameter> outParameters = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, String> entry : outMap.entrySet()) {
|
|
||||||
IOParameter ioParameter = new IOParameter();
|
IOParameter ioParameter = new IOParameter();
|
||||||
ioParameter.setSource(entry.getKey());
|
ioParameter.setSource(entry.getKey());
|
||||||
ioParameter.setTarget(entry.getValue());
|
ioParameter.setTarget(entry.getValue().asText());
|
||||||
outParameters.add(ioParameter);
|
outParameters.add(ioParameter);
|
||||||
}
|
}
|
||||||
callActivity.setOutParameters(outParameters);
|
callActivity.setOutParameters(outParameters);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ flowable.async-executor-activate=false
|
|||||||
flowable.async-history-executor-activate=false
|
flowable.async-history-executor-activate=false
|
||||||
flowable.indexing.enabled=false
|
flowable.indexing.enabled=false
|
||||||
management.health.elasticsearch.enabled=false
|
management.health.elasticsearch.enabled=false
|
||||||
management.metrics.export.elastic.enabled=false
|
management.elastic.metrics.export.enabled=false
|
||||||
|
|
||||||
# Set debug level in tests
|
# Set debug level in tests
|
||||||
logging.level.com.flowable=INFO
|
logging.level.com.flowable=INFO
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user