gh-245: Created new DslProperty creation methods (#247)
Added: - iso8601WithOffset which handles iso8601 date time with timezone date validation - nonBlankString which handles string that aren't "" and also just whitespace - nonEmptyString which handles "" strings - anyOf(String...) which handles enumerated style attributes for validation fixes #245 changed the name of iso8601DatetimeWithTimezone to anyIso8601WithOffset per code review suggestions
This commit is contained in:
committed by
Marcin Grzejszczak
parent
77f42a6f98
commit
ebf09dfda3
@@ -997,7 +997,11 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
uuid: $(anyUuid()),
|
||||
date: $(anyDate()),
|
||||
dateTime: $(anyDateTime()),
|
||||
time: $(anyTime())
|
||||
time: $(anyTime()),
|
||||
iso8601WithOffset: $(anyIso8601WithOffset()),
|
||||
nonBlankString: $(anyNonBlankString()),
|
||||
nonEmptyString: $(anyNonEmptyString()),
|
||||
anyOf: $(anyOf('foo', 'bar'))
|
||||
])
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
@@ -1016,7 +1020,11 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
uuid: $(anyUuid()),
|
||||
date: $(anyDate()),
|
||||
dateTime: $(anyDateTime()),
|
||||
time: $(anyTime())
|
||||
time: $(anyTime()),
|
||||
iso8601WithOffset: $(anyIso8601WithOffset()),
|
||||
nonBlankString: $(anyNonBlankString()),
|
||||
nonEmptyString: $(anyNonEmptyString()),
|
||||
anyOf: $(anyOf('foo', 'bar'))
|
||||
])
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
@@ -1040,13 +1048,17 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
test.contains('assertThatJson(parsedJson).field("date").matches("(\\\\d\\\\d\\\\d\\\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])")')
|
||||
test.contains('assertThatJson(parsedJson).field("dateTime").matches("([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])")')
|
||||
test.contains('assertThatJson(parsedJson).field("time").matches("(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])")')
|
||||
test.contains('assertThatJson(parsedJson).field("iso8601WithOffset").matches("([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\\\.\\\\d{3})?(Z|[+-][01]\\\\d:[0-5]\\\\d)")')
|
||||
test.contains('assertThatJson(parsedJson).field("nonBlankString").matches(".*(\\\\S+|\\\\R).*|!^\\\\R*' + endOfLineRegexSymbol + '")')
|
||||
test.contains('assertThatJson(parsedJson).field("nonEmptyString").matches(".+")')
|
||||
test.contains('assertThatJson(parsedJson).field("anyOf").matches("^foo' + endOfLineRegexSymbol + '|^bar' + endOfLineRegexSymbol + '")')
|
||||
!test.contains('cursor')
|
||||
and:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
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) }
|
||||
methodBuilderName | methodBuilder | endOfLineRegexSymbol
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder"| { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
}
|
||||
|
||||
private String stripped(String string) {
|
||||
|
||||
@@ -1898,7 +1898,11 @@ World.'''"""
|
||||
uuid: $(anyUuid()),
|
||||
date: $(anyDate()),
|
||||
dateTime: $(anyDateTime()),
|
||||
time: $(anyTime())
|
||||
time: $(anyTime()),
|
||||
iso8601WithOffset: $(anyIso8601WithOffset()),
|
||||
nonBlankString: $(anyNonBlankString()),
|
||||
nonEmptyString: $(anyNonEmptyString()),
|
||||
anyOf: $(anyOf('foo', 'bar'))
|
||||
])
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
@@ -1917,7 +1921,11 @@ World.'''"""
|
||||
uuid: $(anyUuid()),
|
||||
date: $(anyDate()),
|
||||
dateTime: $(anyDateTime()),
|
||||
time: $(anyTime())
|
||||
time: $(anyTime()),
|
||||
iso8601WithOffset: $(anyIso8601WithOffset()),
|
||||
nonBlankString: $(anyNonBlankString()),
|
||||
nonEmptyString: $(anyNonEmptyString()),
|
||||
anyOf: $(anyOf('foo', 'bar'))
|
||||
])
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
@@ -1941,13 +1949,17 @@ World.'''"""
|
||||
test.contains('assertThatJson(parsedJson).field("date").matches("(\\\\d\\\\d\\\\d\\\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])')
|
||||
test.contains('assertThatJson(parsedJson).field("dateTime").matches("([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])')
|
||||
test.contains('assertThatJson(parsedJson).field("time").matches("(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])")')
|
||||
test.contains('assertThatJson(parsedJson).field("iso8601WithOffset").matches("([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\\\.\\\\d{3})?(Z|[+-][01]\\\\d:[0-5]\\\\d)")')
|
||||
test.contains('assertThatJson(parsedJson).field("nonBlankString").matches(".*(\\\\S+|\\\\R).*|!^\\\\R*' + endOfLineRegExSymbol + '")')
|
||||
test.contains('assertThatJson(parsedJson).field("nonEmptyString").matches(".+")')
|
||||
test.contains('assertThatJson(parsedJson).field("anyOf").matches("^foo' + endOfLineRegExSymbol + '|^bar' + endOfLineRegExSymbol + '")')
|
||||
!test.contains('cursor')
|
||||
and:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
methodBuilderName | methodBuilder | endOfLineRegExSymbol
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '\\$'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '$'
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user