Fixed invalid OptionalProperty conversion
without this change a toString was executed on an optional property due to a missing method that parses those kind of props. with this change we've added a missing method and also we've made optional property toString return the proper pattern fixes #173
This commit is contained in:
@@ -45,6 +45,6 @@ class ExecutionProperty {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return executionCommand;
|
||||
return executionCommand
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,10 @@ class OptionalProperty {
|
||||
String optionalPattern() {
|
||||
return "($value)?"
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return optionalPattern()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,6 +365,13 @@ abstract class MethodBodyBuilder {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the query parameter DSL Property until a concrete value is reached
|
||||
*/
|
||||
protected String resolveParamValue(OptionalProperty value) {
|
||||
return resolveParamValue(value.optionalPattern())
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the query parameter value into String
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Unroll
|
||||
import spock.util.environment.RestoreSystemProperties
|
||||
|
||||
class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
@@ -870,7 +871,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
}
|
||||
|
||||
@Issue('#149')
|
||||
def "should allow easier way of providing dynamic values"() {
|
||||
@Unroll
|
||||
def "should allow easier way of providing dynamic values for [#methodBuilderName]"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
@@ -931,4 +933,40 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
private String stripped(String string) {
|
||||
return string.stripMargin().stripIndent().replace('\t', '').replace('\n', '').replace(' ','')
|
||||
}
|
||||
|
||||
@Issue('#173')
|
||||
@Unroll
|
||||
def "should resolve Optional object when used in query parameters for [#methodBuilderName]"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath('/blacklist') {
|
||||
queryParameters {
|
||||
parameter 'isActive': value(consumer(optional(regex('(true|false)'))))
|
||||
parameter 'limit': value(consumer(optional(regex('([0-9]{1,10})'))))
|
||||
parameter 'offset': value(consumer(optional(regex('([0-9]{1,10})'))))
|
||||
}
|
||||
}
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
response {
|
||||
status(200)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
!test.contains('org.springframework.cloud.contract.spec.internal.OptionalProperty')
|
||||
test.contains('(([0-9]{1,10}))?')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ import java.util.regex.Pattern
|
||||
*/
|
||||
class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
assertJsonSize: true
|
||||
)
|
||||
|
||||
|
||||
@Shared
|
||||
// tag::contract_with_regex[]
|
||||
@@ -1803,4 +1806,39 @@ World.'''"""
|
||||
methodBuilder << [{ Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties)},
|
||||
{ Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties)}]
|
||||
}
|
||||
|
||||
@Issue('#173')
|
||||
@Unroll
|
||||
def "should resolve Optional object when used in query parameters"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath('/blacklist') {
|
||||
queryParameters {
|
||||
parameter 'isActive': value(consumer(optional(regex('(true|false)'))))
|
||||
parameter 'limit': value(consumer(optional(regex('([0-9]{1,10})'))))
|
||||
parameter 'offset': value(consumer(optional(regex('([0-9]{1,10})'))))
|
||||
}
|
||||
}
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
response {
|
||||
status(200)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
!test.contains('org.springframework.cloud.contract.spec.internal.OptionalProperty')
|
||||
test.contains('(([0-9]{1,10}))?')
|
||||
where:
|
||||
methodBuilder << [{ Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties)},
|
||||
{ Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties)}]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user