Generates random boolean request value for aBoolean() (#1581)

Fixes gh-1410
This commit is contained in:
bono007
2020-12-10 17:25:35 -06:00
committed by GitHub
parent 346ecc48a8
commit ec909350e9
2 changed files with 44 additions and 1 deletions

View File

@@ -101,7 +101,8 @@ abstract class PatternValueDslProperty<T extends DslProperty>
@Override
public T aBoolean() {
return createAndValidateProperty(RegexPatterns.TRUE_OR_FALSE);
return createAndValidateProperty(RegexPatterns.TRUE_OR_FALSE,
this.random.nextBoolean());
}
@Override

View File

@@ -2434,6 +2434,48 @@ DocumentContext parsedJson = JsonPath.parse(json);
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT } | '$'
}
@Issue('#1410')
def 'should generate random boolean input in generated test'() {
given:
Contract contractDsl = Contract.make {
request {
method 'GET'
urlPath '/get'
body([
"someBooleanInputParam" : aBoolean()
])
headers {
contentType applicationJson()
}
}
response {
status OK()
body([
"someBooleanOutputParam" : $(aBoolean())
])
headers {
contentType(applicationJson())
}
}
}
methodBuilder()
when:
String test = singleTestGenerator(contractDsl)
then:
// The input body string looks like one of the following:
// .body("{\"someBooleanInputParam\":true|false}");
// .body('''{"someBooleanInputParam":true|false}''')
test.findAll(~'\\.body\\((\'{3}|")\\{("|\\\\")someBooleanInputParam("|\\\\"):(true|false)\\}(\'{3}|")\\)').size().equals(1)
and:
SyntaxChecker.tryToCompile(methodBuilderName, test)
where:
methodBuilderName | methodBuilder
"spock" | { properties.testFramework = TestFramework.SPOCK }
"testng" | { properties.testFramework = TestFramework.TESTNG }
"mockmvc" | { properties.testMode = TestMode.MOCKMVC }
"webclient" | { properties.testMode = TestMode.WEBTESTCLIENT }
}
@Issue('#162')
def 'should escape regex properly for content type'() {
given: