use of org.springframework.cloud.contract.verifier.file.SingleContractMetadata in project spring-cloud-contract by spring-cloud.
the class BodyParser method requestBodyAsString.
@SuppressWarnings("unchecked")
default String requestBodyAsString(SingleContractMetadata metadata) {
ContentType contentType = metadata.getInputTestContentType();
DslProperty body = requestBody(metadata);
Object bodyValue = extractServerValueFromBody(contentType, body.getServerValue());
if (contentType == ContentType.FORM) {
if (bodyValue instanceof Map) {
// [a:3, b:4] == "a=3&b=4"
return ((Map) bodyValue).entrySet().stream().map(o -> {
Map.Entry entry = (Map.Entry) o;
return convertUnicodeEscapesIfRequired(entry.getKey().toString() + "=" + MapConverter.getTestSideValuesForText(entry.getValue()));
}).collect(Collectors.joining("&")).toString();
} else if (bodyValue instanceof List) {
// ["a=3", "b=4"] == "a=3&b=4"
return ((List) bodyValue).stream().map(o -> convertUnicodeEscapesIfRequired(MapConverter.getTestSideValuesForText(o).toString())).collect(Collectors.joining("&")).toString();
}
} else {
return convertToJsonString(bodyValue);
}
return "";
}
use of org.springframework.cloud.contract.verifier.file.SingleContractMetadata in project spring-cloud-contract by spring-cloud.
the class NameProvider method generateMethodName.
private String generateMethodName(SingleContractMetadata singleContractMetadata) {
ContractMetadata contractMetadata = singleContractMetadata.getContractMetadata();
File stubsFile = contractMetadata.getPath().toFile();
Contract stubContent = singleContractMetadata.getContract();
if (StringUtils.hasText(stubContent.getName())) {
String name = NamesUtil.camelCase(NamesUtil.convertIllegalPackageChars(stubContent.getName()));
if (log.isDebugEnabled()) {
log.debug("Overriding the default test name with [" + name + "]");
}
return name;
} else if (contractMetadata.getConvertedContract().size() > 1) {
int index = findIndexOf(contractMetadata.getConvertedContract(), stubContent);
String name = camelCasedMethodFromFileName(stubsFile) + "_" + index;
if (log.isTraceEnabled()) {
log.trace("Scenario found. The method name will be [" + name + "]");
}
return name;
}
String name = camelCasedMethodFromFileName(stubsFile);
if (StringUtils.hasText(name) && log.isTraceEnabled()) {
log.trace("The method name will be [" + name + "]");
}
return name;
}
Aggregations