[#49] Surrounded with different quotes

This commit is contained in:
Marcin Grzejszczak
2015-05-12 16:20:42 +02:00
parent b62a5553e9
commit f84f11611b
2 changed files with 14 additions and 2 deletions

View File

@@ -36,8 +36,8 @@ class WiremockToDslConverter {
}
""" : ""
}
${bodyPatterns?.equalTo?.every { it } ? "body('''${bodyPatterns.equalTo[0]}''')" : ''}
${bodyPatterns?.equalToJson?.every { it } ? "body('''${bodyPatterns.equalToJson[0]}''')" : ''}
${bodyPatterns?.equalTo?.every { it } ? "body(\"\"\"${bodyPatterns.equalTo[0]}\"\"\")" : ''}
${bodyPatterns?.equalToJson?.every { it } ? "body(\"\"\"${bodyPatterns.equalToJson[0]}\"\"\")" : ''}
${bodyPatterns?.matches?.every { it } ? "body \$(client(regex('${escapeJava(bodyPatterns.matches[0])}')), server(''))" : ""}
}
response {

View File

@@ -42,6 +42,18 @@ class Body extends DslProperty {
super(bodyAsValue.clientValue, bodyAsValue.serverValue)
}
/**
* Due to the fact that we allow users to have a body with GString and different values inside
* we need to be prepared that they pass regexps around both on client and server side.
*
* In order to preserve the original JSON structure we need to convert the passed Regex patterns
* to a temporary string, then convert all to a legitimate JSON structure and then finally
* convert it back from string to a pattern.
*
* @param bodyAsValue - GString with passed values
* @param valueProvider - provider of values either for server or client side
* @return JSON structure with replaced client / server side parts
*/
private static Object extractValue(GString bodyAsValue, Closure valueProvider) {
GString gString = new GStringImpl(bodyAsValue.values.clone(), bodyAsValue.strings.clone())
Object[] values = bodyAsValue.values.collect { it instanceof DslProperty ? valueProvider(it) : it } as Object[]