@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -41,6 +42,7 @@ import org.springframework.cloud.contract.verifier.template.TemplateProcessor;
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @author Stessy Delcroix
|
||||
* @author Ravil Galeyev
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public class MapConverter {
|
||||
@@ -123,8 +125,8 @@ public class MapConverter {
|
||||
else if (value instanceof Map) {
|
||||
return convert((Map) value, function, parsingFunction);
|
||||
}
|
||||
else if (value instanceof List) {
|
||||
return ((List) value).stream().map((v) -> transformValues(v, function, parsingFunction))
|
||||
else if (value instanceof Collection) {
|
||||
return ((Collection) value).stream().map((v) -> transformValues(v, function, parsingFunction))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return transformValue(function, value, parsingFunction);
|
||||
|
||||
@@ -1934,6 +1934,41 @@ World.'''"""
|
||||
"webclient" | { configProperties.testMode = TestMode.WEBTESTCLIENT }
|
||||
}
|
||||
|
||||
@Issue('1630')
|
||||
def 'should generate proper test code with top level map of sets using #methodBuilderName'() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
description('get map')
|
||||
name('assert map response')
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath '/some-path'
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
body(["key": ["value1", "value2"] as Set])
|
||||
headers {
|
||||
header('Content-Type': 'application/json;charset=UTF-8')
|
||||
}
|
||||
}
|
||||
}
|
||||
methodBuilder()
|
||||
when:
|
||||
String test = singleTestGenerator(contractDsl)
|
||||
then:
|
||||
test.contains("""assertThatJson(parsedJson).array("['key']").hasSize(2)""")
|
||||
test.contains("""assertThatJson(parsedJson).array("['key']").arrayField().isEqualTo("value1").value()""")
|
||||
test.contains("""assertThatJson(parsedJson).array("['key']").arrayField().isEqualTo("value2").value()""")
|
||||
and:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, test)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"spock" | { configProperties.testFramework = TestFramework.SPOCK }
|
||||
"testng" | { configProperties.testFramework = TestFramework.TESTNG }
|
||||
"mockmvc" | { configProperties.testMode = TestMode.MOCKMVC }
|
||||
"webclient" | { configProperties.testMode = TestMode.WEBTESTCLIENT }
|
||||
}
|
||||
|
||||
@Issue('47')
|
||||
def 'should generate async body when async flag set in response'() {
|
||||
given:
|
||||
|
||||
Reference in New Issue
Block a user