in src/main/java/platform/qa/base/utils/ValueUtils.java [37:54]
public static String replaceValueFragmentWithValueFromRequest(String businessKey, TestContext testContext) {
var context = convertToRequestsContext(testContext.getScenarioContext().getContext(API_RESULTS));
final AtomicReference<String> processedBusinessKey = new AtomicReference<>(businessKey);
Pattern pattern = Pattern.compile(".*?\\{([\\w]+)}.*?", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(businessKey);
while (matcher.find()) {
String valueKey = matcher.group(1);
var lastRequest = context.stream()
.filter(request -> request.isResultContainsKey(valueKey))
.max(Request::compareTo);
lastRequest.ifPresent(request -> {
String newValue = businessKey.replace(String.format("{%s}", valueKey), request.getResultValueByKey(valueKey));
log.debug("The value {} is replaced with {}", businessKey, newValue);
processedBusinessKey.set(newValue);
});
}
return processedBusinessKey.get();
}