From 81f2bb10805bd6d9a3c3e8fffb699e203054ad1a Mon Sep 17 00:00:00 2001 From: Aurelien Bourdon Date: Tue, 16 Jan 2024 21:24:28 +0100 Subject: [PATCH] feat(DataLib): set datalib null value with default non-matched subdata's one Prefer use of default value from non-matched subdata datalib configuration instead of the original PropertyService.NULL_VALUE. Only if non-matched subdata configuration is on Relates #2491 --- .../core/engine/gwt/impl/PropertyService.java | 11 ++++++++++- .../cerberus/core/service/sql/impl/SQLService.java | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/src/main/java/org/cerberus/core/engine/gwt/impl/PropertyService.java b/source/src/main/java/org/cerberus/core/engine/gwt/impl/PropertyService.java index a568582e4..4b1546407 100644 --- a/source/src/main/java/org/cerberus/core/engine/gwt/impl/PropertyService.java +++ b/source/src/main/java/org/cerberus/core/engine/gwt/impl/PropertyService.java @@ -21,6 +21,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.jayway.jsonpath.InvalidPathException; + +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.cerberus.core.crud.entity.AppService; @@ -1693,7 +1695,14 @@ private TestCaseExecutionData property_getFromDataLib(TestCaseExecutionData test // Value of testCaseExecutionData object takes the master subdata entry "". String value = result.get(0).get(""); if (value == null) { - testCaseExecutionData.setValue(VALUE_NULL); + final boolean ignoreNonMatchedSubdata = parameterService.getParameterBooleanByKey("cerberus_testdatalib_ignoreNonMatchedSubdata", StringUtils.EMPTY, false); + if (ignoreNonMatchedSubdata) { + final String defaultSubdataValue = ignoreNonMatchedSubdata ? parameterService.getParameterStringByKey("cerberus_testdatalib_subdataDefaultValue", StringUtils.EMPTY, StringUtils.EMPTY) : StringUtils.EMPTY; + LOG.debug("Unmatched columns parsing enabled: Null answer received from service call of datalib '{}' with default value", () -> testDataLib.getName()); + testCaseExecutionData.setValue(defaultSubdataValue); + } else { + testCaseExecutionData.setValue(VALUE_NULL); + } } else { testCaseExecutionData.setValue(value); // Converting HashMap to json. diff --git a/source/src/main/java/org/cerberus/core/service/sql/impl/SQLService.java b/source/src/main/java/org/cerberus/core/service/sql/impl/SQLService.java index aa198b7dc..b9ffcf69c 100644 --- a/source/src/main/java/org/cerberus/core/service/sql/impl/SQLService.java +++ b/source/src/main/java/org/cerberus/core/service/sql/impl/SQLService.java @@ -443,7 +443,12 @@ public AnswerList> queryDatabaseNColumns(String connecti try { String valueSQL = resultSet.getString(column); if (valueSQL == null) { // If data is null from the database, we convert it to the static string . - valueSQL = PropertyService.VALUE_NULL; + if (ignoreNoMatchColumns) { + LOG.debug("Unmatched columns parsing enabled: Fill null value for column '{}' with default value", () -> name); + valueSQL = defaultNoMatchColumnValue; + } else { + valueSQL = PropertyService.VALUE_NULL; + } } if (columnsToHide.contains(name)) { execution.appendSecret(valueSQL);