Added property to skip array size assertion (#295)
with this fix you can pass set the Contract Verifier property 'assertJsonSize' to true / false in order to check / not check the array size of a JSON workaround to #293
This commit is contained in:
committed by
GitHub
parent
647e5f028e
commit
da801e52c7
@@ -32,6 +32,10 @@ WARNING: Spring Cloud Contract Verifier doesn't support XML properly. Please use
|
||||
|
||||
WARNING: Spring Cloud Contract Verifier supports equality check on text response. Regular expressions are not yet available.
|
||||
|
||||
WARNING: The support for the verification of size of JSON arrays is experimental. If you want to turn it on please provide
|
||||
the value of a system property `spring.cloud.contract.verifier.assert.size` equal to `turn`. By default this feature is
|
||||
`off`.
|
||||
|
||||
=== HTTP Top-Level Elements
|
||||
|
||||
Following methods can be called in the top-level closure of a contract definition. Request and response are mandatory, priority is optional.
|
||||
|
||||
@@ -20,10 +20,11 @@ import groovy.json.StringEscapeUtils
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.Input
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -43,8 +44,8 @@ import static org.springframework.cloud.contract.verifier.config.TestFramework.J
|
||||
@TypeChecked
|
||||
class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
|
||||
JUnitMessagingMethodBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
JUnitMessagingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,10 +20,11 @@ import groovy.json.StringEscapeUtils
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -45,8 +46,8 @@ import static org.springframework.cloud.contract.verifier.util.ContentUtils.getJ
|
||||
@PackageScope
|
||||
abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder {
|
||||
|
||||
JUnitMethodBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
JUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameter
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameters
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -42,8 +43,8 @@ import static org.springframework.cloud.contract.verifier.config.TestFramework.J
|
||||
@PackageScope
|
||||
class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
|
||||
JaxRsClientJUnitMethodBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
JaxRsClientJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameter
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameters
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -39,8 +40,8 @@ import java.util.regex.Pattern
|
||||
@TypeChecked
|
||||
class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestProcessingBodyBuilder {
|
||||
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
JaxRsClientSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Input
|
||||
import org.springframework.cloud.contract.spec.internal.OutputMessage
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType
|
||||
|
||||
import static org.springframework.cloud.contract.verifier.util.ContentUtils.recognizeContentTypeFromContent
|
||||
@@ -43,7 +44,8 @@ abstract class MessagingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
protected final Input inputMessage
|
||||
protected final OutputMessage outputMessage
|
||||
|
||||
MessagingMethodBodyBuilder(Contract stubDefinition) {
|
||||
MessagingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(configProperties)
|
||||
this.inputMessage = stubDefinition.input
|
||||
this.outputMessage = stubDefinition.outputMessage
|
||||
}
|
||||
|
||||
@@ -18,16 +18,12 @@ package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameter
|
||||
import org.springframework.cloud.contract.spec.internal.*
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType
|
||||
import org.springframework.cloud.contract.verifier.util.JsonPaths
|
||||
import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -46,6 +42,12 @@ import static org.springframework.cloud.contract.verifier.util.ContentUtils.extr
|
||||
@PackageScope
|
||||
abstract class MethodBodyBuilder {
|
||||
|
||||
protected final ContractVerifierConfigProperties configProperties
|
||||
|
||||
protected MethodBodyBuilder(ContractVerifierConfigProperties configProperties) {
|
||||
this.configProperties = configProperties
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the response body validation code block
|
||||
*/
|
||||
@@ -245,7 +247,7 @@ abstract class MethodBodyBuilder {
|
||||
}
|
||||
if (contentType == ContentType.JSON) {
|
||||
appendJsonPath(bb, getResponseAsString())
|
||||
JsonPaths jsonPaths = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(responseBody)
|
||||
JsonPaths jsonPaths = new JsonToJsonPathsConverter(configProperties).transformToJsonPathWithTestsSideValues(responseBody)
|
||||
jsonPaths.each {
|
||||
String method = it.method()
|
||||
String postProcessedMethod = postProcessJsonPathCall(method)
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.contract.verifier.builder
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.PackageScope
|
||||
import groovy.util.logging.Slf4j
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.config.TestFramework
|
||||
import org.springframework.cloud.contract.verifier.util.NamesUtil
|
||||
@@ -38,11 +39,11 @@ import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
class MethodBuilder {
|
||||
|
||||
private final String methodName
|
||||
private final org.springframework.cloud.contract.spec.Contract stubContent
|
||||
private final Contract stubContent
|
||||
private final ContractVerifierConfigProperties configProperties
|
||||
private final boolean ignored
|
||||
|
||||
private MethodBuilder(String methodName, org.springframework.cloud.contract.spec.Contract stubContent, ContractVerifierConfigProperties configProperties, boolean ignored) {
|
||||
private MethodBuilder(String methodName, Contract stubContent, ContractVerifierConfigProperties configProperties, boolean ignored) {
|
||||
this.ignored = ignored
|
||||
this.stubContent = stubContent
|
||||
this.methodName = methodName
|
||||
@@ -52,7 +53,7 @@ class MethodBuilder {
|
||||
/**
|
||||
* A factory method that creates a {@link MethodBuilder} for the given arguments
|
||||
*/
|
||||
static MethodBuilder createTestMethod(ContractMetadata contract, File stubsFile, org.springframework.cloud.contract.spec.Contract stubContent, ContractVerifierConfigProperties configProperties) {
|
||||
static MethodBuilder createTestMethod(ContractMetadata contract, File stubsFile, Contract stubContent, ContractVerifierConfigProperties configProperties) {
|
||||
log.debug("Stub content Groovy DSL [$stubContent]")
|
||||
String methodName = NamesUtil.camelCase(NamesUtil.toLastDot(NamesUtil.afterLast(stubsFile.path, File.separator)))
|
||||
return new MethodBuilder(methodName, stubContent, configProperties, contract.ignored)
|
||||
@@ -76,20 +77,20 @@ class MethodBuilder {
|
||||
private MethodBodyBuilder getMethodBodyBuilder() {
|
||||
if (stubContent.input || stubContent.outputMessage) {
|
||||
if (configProperties.targetFramework == TestFramework.JUNIT){
|
||||
return new JUnitMessagingMethodBodyBuilder(stubContent)
|
||||
return new JUnitMessagingMethodBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
return new SpockMessagingMethodBodyBuilder(stubContent)
|
||||
return new SpockMessagingMethodBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
if (configProperties.testMode == TestMode.MOCKMVC && configProperties.targetFramework == TestFramework.JUNIT){
|
||||
return new MockMvcJUnitMethodBodyBuilder(stubContent)
|
||||
return new MockMvcJUnitMethodBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
if (configProperties.testMode == TestMode.JAXRSCLIENT) {
|
||||
if (configProperties.targetFramework == TestFramework.JUNIT){
|
||||
return new JaxRsClientJUnitMethodBodyBuilder(stubContent)
|
||||
return new JaxRsClientJUnitMethodBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
return new JaxRsClientSpockMethodRequestProcessingBodyBuilder(stubContent)
|
||||
return new JaxRsClientSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
return new MockMvcSpockMethodRequestProcessingBodyBuilder(stubContent)
|
||||
return new MockMvcSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -35,8 +36,8 @@ import java.util.regex.Pattern
|
||||
@PackageScope
|
||||
class MockMvcJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
|
||||
MockMvcJUnitMethodBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
MockMvcJUnitMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import groovy.transform.TypeChecked
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -33,8 +34,8 @@ import java.util.regex.Pattern
|
||||
@TypeChecked
|
||||
class MockMvcSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequestProcessingBodyBuilder {
|
||||
|
||||
MockMvcSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
MockMvcSpockMethodRequestProcessingBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameter
|
||||
import org.springframework.cloud.contract.spec.internal.Response
|
||||
import org.springframework.cloud.contract.spec.internal.Url
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.util.ContentType
|
||||
import org.springframework.cloud.contract.verifier.util.MapConverter
|
||||
|
||||
@@ -50,7 +51,8 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
|
||||
protected final Request request
|
||||
protected final Response response
|
||||
|
||||
RequestProcessingMethodBodyBuilder(Contract stubDefinition) {
|
||||
RequestProcessingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(configProperties)
|
||||
this.request = stubDefinition.request
|
||||
this.response = stubDefinition.response
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.Input
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
/**
|
||||
@@ -33,8 +34,8 @@ import java.util.regex.Pattern
|
||||
@TypeChecked
|
||||
class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
|
||||
SpockMessagingMethodBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
SpockMessagingMethodBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.cloud.contract.spec.internal.Header
|
||||
import org.springframework.cloud.contract.spec.internal.NamedProperty
|
||||
import org.springframework.cloud.contract.spec.internal.Request
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -40,8 +41,8 @@ import static org.springframework.cloud.contract.verifier.util.ContentUtils.getG
|
||||
@TypeChecked
|
||||
abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessingMethodBodyBuilder {
|
||||
|
||||
SpockMethodRequestProcessingBodyBuilder(Contract stubDefinition) {
|
||||
super(stubDefinition)
|
||||
SpockMethodRequestProcessingBodyBuilder(Contract stubDefinition, ContractVerifierConfigProperties configProperties) {
|
||||
super(stubDefinition, configProperties)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -96,4 +96,10 @@ class ContractVerifierConfigProperties {
|
||||
*/
|
||||
String stubsSuffix = 'stubs'
|
||||
|
||||
/**
|
||||
* Incubating feature. You can check the size of JSON arrays. If not turned on
|
||||
* explicitly will be disabled.
|
||||
*/
|
||||
Boolean assertJsonSize
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@ package org.springframework.cloud.contract.verifier.util
|
||||
import com.toomuchcoding.jsonassert.JsonAssertion
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
import groovy.util.logging.Slf4j
|
||||
import org.springframework.cloud.contract.spec.internal.OptionalProperty
|
||||
import org.springframework.cloud.contract.spec.internal.ExecutionProperty
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -31,6 +33,7 @@ import java.util.regex.Pattern
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@Slf4j
|
||||
class JsonToJsonPathsConverter {
|
||||
|
||||
/**
|
||||
@@ -42,15 +45,25 @@ class JsonToJsonPathsConverter {
|
||||
private static final Boolean SERVER_SIDE = false
|
||||
private static final Boolean CLIENT_SIDE = true
|
||||
|
||||
private final ContractVerifierConfigProperties configProperties
|
||||
|
||||
JsonToJsonPathsConverter(ContractVerifierConfigProperties configProperties) {
|
||||
this.configProperties = configProperties
|
||||
}
|
||||
|
||||
JsonToJsonPathsConverter() {
|
||||
this.configProperties = new ContractVerifierConfigProperties()
|
||||
}
|
||||
|
||||
public static JsonPaths transformToJsonPathWithTestsSideValues(def json) {
|
||||
return transformToJsonPathWithValues(json, SERVER_SIDE)
|
||||
return new JsonToJsonPathsConverter().transformToJsonPathWithValues(json, SERVER_SIDE)
|
||||
}
|
||||
|
||||
public static JsonPaths transformToJsonPathWithStubsSideValues(def json) {
|
||||
return transformToJsonPathWithValues(json, CLIENT_SIDE)
|
||||
return new JsonToJsonPathsConverter().transformToJsonPathWithValues(json, CLIENT_SIDE)
|
||||
}
|
||||
|
||||
private static JsonPaths transformToJsonPathWithValues(def json, boolean clientSide) {
|
||||
private JsonPaths transformToJsonPathWithValues(def json, boolean clientSide) {
|
||||
if(!json) {
|
||||
return new JsonPaths()
|
||||
}
|
||||
@@ -69,7 +82,7 @@ class JsonToJsonPathsConverter {
|
||||
return pathsAndValues
|
||||
}
|
||||
|
||||
protected static def traverseRecursively(Class parentType, MethodBufferingJsonVerifiable key, def value, Closure closure) {
|
||||
protected def traverseRecursively(Class parentType, MethodBufferingJsonVerifiable key, def value, Closure closure) {
|
||||
value = ContentUtils.returnParsedObject(value)
|
||||
if (value instanceof String && value) {
|
||||
try {
|
||||
@@ -120,10 +133,16 @@ class JsonToJsonPathsConverter {
|
||||
}
|
||||
|
||||
// Size verification: https://github.com/Codearte/accurest/issues/279
|
||||
private static void addSizeVerificationForListWithPrimitives(MethodBufferingJsonVerifiable key, Closure closure, List value) {
|
||||
if (System.getProperty(SIZE_ASSERTION_SYSTEM_PROP, "true") == "false") {
|
||||
private void addSizeVerificationForListWithPrimitives(MethodBufferingJsonVerifiable key, Closure closure, List value) {
|
||||
Boolean systemPropValue = Boolean.parseBoolean(System.getProperty(SIZE_ASSERTION_SYSTEM_PROP, "false"))
|
||||
Boolean configPropValue = configProperties.assertJsonSize
|
||||
boolean configPropSet = configPropValue != null
|
||||
if (configPropSet && !configPropValue) {
|
||||
return
|
||||
} else if (!configPropSet && systemPropValue) {
|
||||
return
|
||||
}
|
||||
log.debug("WARNING: Turning on the incubating feature of JSON array check")
|
||||
if (isRootElement(key) || key.assertsConcreteValue()) {
|
||||
if (value.size() > 0) {
|
||||
closure(key.hasSize(value.size()), value)
|
||||
@@ -131,12 +150,12 @@ class JsonToJsonPathsConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isRootElement(MethodBufferingJsonVerifiable key) {
|
||||
private boolean isRootElement(MethodBufferingJsonVerifiable key) {
|
||||
return key.jsonPath() == '$'
|
||||
}
|
||||
|
||||
// If you have a list of not-only primitives it can contain different sets of elements (maps, lists, primitives)
|
||||
private static MethodBufferingJsonVerifiable createAsserterFromList(MethodBufferingJsonVerifiable key, List value) {
|
||||
private MethodBufferingJsonVerifiable createAsserterFromList(MethodBufferingJsonVerifiable key, List value) {
|
||||
if (key.isIteratingOverNamelessArray()) {
|
||||
return key.array()
|
||||
} else if (key.isIteratingOverArray() && isAnEntryWithLists(value)) {
|
||||
@@ -151,7 +170,7 @@ class JsonToJsonPathsConverter {
|
||||
return key
|
||||
}
|
||||
|
||||
private static MethodBufferingJsonVerifiable createAsserterFromListElement(MethodBufferingJsonVerifiable jsonPathVerifiable, def element) {
|
||||
private MethodBufferingJsonVerifiable createAsserterFromListElement(MethodBufferingJsonVerifiable jsonPathVerifiable, def element) {
|
||||
if (jsonPathVerifiable.isAssertingAValueInArray()) {
|
||||
def object = ContentUtils.returnParsedObject(element)
|
||||
if (object instanceof Pattern) {
|
||||
@@ -162,14 +181,14 @@ class JsonToJsonPathsConverter {
|
||||
return jsonPathVerifiable
|
||||
}
|
||||
|
||||
private static def runClosure(Closure closure, MethodBufferingJsonVerifiable key, def value) {
|
||||
private def runClosure(Closure closure, MethodBufferingJsonVerifiable key, def value) {
|
||||
if (key.isAssertingAValueInArray() && !(value instanceof List || value instanceof Map)) {
|
||||
return closure(valueToAsserter(key, value), value)
|
||||
}
|
||||
return closure(key, value)
|
||||
}
|
||||
|
||||
private static boolean isAnEntryWithNonCollectionLikeValue(def value) {
|
||||
private boolean isAnEntryWithNonCollectionLikeValue(def value) {
|
||||
if (!(value instanceof Map)) {
|
||||
return false
|
||||
}
|
||||
@@ -182,7 +201,7 @@ class JsonToJsonPathsConverter {
|
||||
return !(valueOfEntry instanceof Map || valueOfEntry instanceof List)
|
||||
}
|
||||
|
||||
private static boolean isAnEntryWithoutNestedStructures(def value) {
|
||||
private boolean isAnEntryWithoutNestedStructures(def value) {
|
||||
if (!(value instanceof Map)) {
|
||||
return false
|
||||
}
|
||||
@@ -192,14 +211,14 @@ class JsonToJsonPathsConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean listContainsOnlyPrimitives(List list) {
|
||||
private boolean listContainsOnlyPrimitives(List list) {
|
||||
return list.every { def element ->
|
||||
[String, Number, Boolean].any {
|
||||
it.isAssignableFrom(element.getClass())
|
||||
}
|
||||
}
|
||||
}
|
||||
private static boolean isAnEntryWithLists(def value) {
|
||||
private boolean isAnEntryWithLists(def value) {
|
||||
if (!(value instanceof Iterable)) {
|
||||
return false
|
||||
}
|
||||
@@ -208,7 +227,7 @@ class JsonToJsonPathsConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map convertWithKey(Class parentType, MethodBufferingJsonVerifiable parentKey, Map map, Closure closureToExecute) {
|
||||
private Map convertWithKey(Class parentType, MethodBufferingJsonVerifiable parentKey, Map map, Closure closureToExecute) {
|
||||
return map.collectEntries {
|
||||
Object entrykey, value ->
|
||||
def convertedValue = ContentUtils.returnParsedObject(value)
|
||||
@@ -222,11 +241,11 @@ class JsonToJsonPathsConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private static void traverseRecursivelyForKey(def json, MethodBufferingJsonVerifiable rootKey, Closure closure) {
|
||||
private void traverseRecursivelyForKey(def json, MethodBufferingJsonVerifiable rootKey, Closure closure) {
|
||||
traverseRecursively(Map, rootKey, json, closure)
|
||||
}
|
||||
|
||||
protected static MethodBufferingJsonVerifiable valueToAsserter(MethodBufferingJsonVerifiable key, Object value) {
|
||||
protected MethodBufferingJsonVerifiable valueToAsserter(MethodBufferingJsonVerifiable key, Object value) {
|
||||
def convertedValue = ContentUtils.returnParsedObject(value)
|
||||
if (key instanceof FinishedDelegatingJsonVerifiable) {
|
||||
return key
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
/**
|
||||
@@ -25,6 +27,8 @@ import spock.lang.Specification
|
||||
*/
|
||||
class ContractHttpDocsSpec extends Specification {
|
||||
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
|
||||
|
||||
org.springframework.cloud.contract.spec.Contract httpDsl =
|
||||
// tag::http_dsl[]
|
||||
org.springframework.cloud.contract.spec.Contract.make {
|
||||
@@ -257,7 +261,7 @@ class ContractHttpDocsSpec extends Specification {
|
||||
def 'should convert dsl with optionals to proper Spock test'() {
|
||||
given:
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
new MockMvcSpockMethodRequestProcessingBodyBuilder(optionals).appendTo(blockBuilder)
|
||||
new MockMvcSpockMethodRequestProcessingBodyBuilder(optionals, properties).appendTo(blockBuilder)
|
||||
expect:
|
||||
String expectedTest =
|
||||
// tag::optionals_test[]
|
||||
|
||||
@@ -16,14 +16,18 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.dsl.WireMockStubVerifier
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
|
||||
|
||||
def "should generate assertions for simple response body with #methodBuilderName"() {
|
||||
given:
|
||||
org.springframework.cloud.contract.spec.Contract contractDsl = org.springframework.cloud.contract.spec.Contract.make {
|
||||
@@ -50,8 +54,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue("#187")
|
||||
@@ -83,8 +87,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
@@ -119,8 +123,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), contractDsl).toWireMockClientStub())
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue("#82")
|
||||
@@ -148,8 +152,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | """entity('{\"items\":[\"HOP\"]}', 'application/json')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("{\\"items\\":[\\"HOP\\"]}", "application/json")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """entity('{\"items\":[\"HOP\"]}', 'application/json')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'entity("{\\"items\\":[\\"HOP\\"]}", "application/json")'
|
||||
}
|
||||
|
||||
@Issue("#88")
|
||||
@@ -177,8 +181,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | """entity('property1=VAL1', 'application/octet-stream')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("\\"property1=VAL1\\"", "application/octet-stream")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """entity('property1=VAL1', 'application/octet-stream')"""
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'entity("\\"property1=VAL1\\"", "application/octet-stream")'
|
||||
}
|
||||
|
||||
def "should generate assertions for array in response body with #methodBuilderName"() {
|
||||
@@ -210,8 +214,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate assertions for array inside response body element with #methodBuilderName"() {
|
||||
@@ -242,8 +246,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate assertions for nested objects in response body with #methodBuilderName"() {
|
||||
@@ -274,8 +278,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for map objects in response body with #methodBodyName"() {
|
||||
@@ -312,8 +316,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for string objects in response body with #methodBuilderName"() {
|
||||
@@ -344,8 +348,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should ignore 'Accept' header and use 'request' method with #methodBuilderName"() {
|
||||
@@ -372,8 +376,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "request('text/plain')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'request("text/plain")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | "request('text/plain')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'request("text/plain")'
|
||||
}
|
||||
|
||||
def "should ignore 'Content-Type' header and use 'entity' method with #methodBuilderName"() {
|
||||
@@ -405,8 +409,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""entity('', 'text/plain')""", """header('Timer', '123')"""]
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | ['entity("\\"\\"", "text/plain")', 'header("Timer", "123")']
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ["""entity('', 'text/plain')""", """header('Timer', '123')"""]
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | ['entity("\\"\\"", "text/plain")', 'header("Timer", "123")']
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters with #methodBuilderName"() {
|
||||
@@ -459,8 +463,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | modifyStringIfRequired
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -514,8 +518,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | modifyStringIfRequired
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | { String paramString -> paramString }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String paramString -> paramString.replace("'", "\"") }
|
||||
}
|
||||
|
||||
def "should generate test for empty body with #methodBuilderName"() {
|
||||
@@ -542,8 +546,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "entity('', 'application/octet-stream')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'entity("\\"\\"", "application/octet-stream"'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | "entity('', 'application/octet-stream')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'entity("\\"\\"", "application/octet-stream"'
|
||||
}
|
||||
|
||||
def "should generate test for String in response body with #methodBodyName"() {
|
||||
@@ -570,8 +574,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | "String responseAsString = response.readEntity(String)" | 'responseBody == "test"'
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (responseAsString);' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | "String responseAsString = response.readEntity(String)" | 'responseBody == "test"'
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'Object responseBody = (responseAsString);' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
}
|
||||
|
||||
@Issue('#171')
|
||||
@@ -603,8 +607,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | methodString
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl) } | ".method('GET')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl) } | 'method("GET")'
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ".method('GET')"
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { org.springframework.cloud.contract.spec.Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | 'method("GET")'
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters with JUnit - we'll put it into docs"() {
|
||||
@@ -636,7 +640,7 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
"""
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
|
||||
@@ -17,12 +17,16 @@
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class MessagingMethodBodyBuilderSpec extends Specification {
|
||||
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
|
||||
|
||||
def "should work for triggered based messaging with Spock"() {
|
||||
given:
|
||||
// tag::trigger_method_dsl[]
|
||||
@@ -40,7 +44,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
// end::trigger_method_dsl[]
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -80,7 +84,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -129,7 +133,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
// end::trigger_message_dsl[]
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -182,7 +186,7 @@ and:
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -229,7 +233,7 @@ def contractDsl = Contract.make {
|
||||
}
|
||||
}
|
||||
// end::trigger_no_output_dsl[]
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -270,7 +274,7 @@ then:
|
||||
assertThat('bookWasDeleted()')
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -315,7 +319,7 @@ then:
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -361,7 +365,7 @@ then:
|
||||
])
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new SpockMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -414,7 +418,7 @@ Contract.make {
|
||||
}
|
||||
}
|
||||
// end::consumer_producer[]
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new JUnitMessagingMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.dsl.WireMockStubVerifier
|
||||
import spock.lang.Issue
|
||||
import spock.lang.Shared
|
||||
@@ -28,6 +29,8 @@ import java.util.regex.Pattern
|
||||
*/
|
||||
class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStubVerifier {
|
||||
|
||||
@Shared ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(assertJsonSize: true)
|
||||
|
||||
@Shared
|
||||
Contract dslWithOptionalsInString = Contract.make {
|
||||
priority 1
|
||||
@@ -118,8 +121,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue("#187")
|
||||
@@ -151,8 +154,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue("#79")
|
||||
@@ -187,8 +190,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue("#82")
|
||||
@@ -216,8 +219,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''{\"items\":[\"HOP\"]}''')"""
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """.body('''{\"items\":[\"HOP\"]}''')"""
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("{\\"items\\":[\\"HOP\\"]}")'
|
||||
}
|
||||
|
||||
@Issue("#88")
|
||||
@@ -245,8 +248,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """.body('''property1=VAL1''')"""
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.body("\\"property1=VAL1\\"")'
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """.body('''property1=VAL1''')"""
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.body("\\"property1=VAL1\\"")'
|
||||
}
|
||||
|
||||
@Issue("185")
|
||||
@@ -278,8 +281,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate assertions for array in response body with #methodBuilderName"() {
|
||||
@@ -311,8 +314,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate assertions for array inside response body element with #methodBuilderName"() {
|
||||
@@ -343,8 +346,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate assertions for nested objects in response body with #methodBuilderName"() {
|
||||
@@ -375,8 +378,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for map objects in response body with #methodBuilderName"() {
|
||||
@@ -411,8 +414,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate regex assertions for string objects in response body with #methodBuilderName"() {
|
||||
@@ -443,8 +446,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue(["#126", "#143"])
|
||||
@@ -475,8 +478,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate a call with an url path and query parameters with #methodBuilderName"() {
|
||||
@@ -522,8 +525,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('#169')
|
||||
@@ -570,8 +573,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should generate test for empty body with #methodBuilderName"() {
|
||||
@@ -597,8 +600,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ".body('''''')"
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ".body(\"\\\"\\\"\")"
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ".body('''''')"
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ".body(\"\\\"\\\"\")"
|
||||
}
|
||||
|
||||
def "should generate test for String in response body with #methodBuilderName"() {
|
||||
@@ -625,8 +628,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString | bodyEvaluationString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'Object responseBody = (response.getBody().asString());' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | 'def responseBody = (response.body.asString())' | 'responseBody == "test"'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'Object responseBody = (response.getBody().asString());' | 'assertThat(responseBody).isEqualTo("test");'
|
||||
}
|
||||
|
||||
@Issue('113')
|
||||
@@ -664,8 +667,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | headerEvaluationString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')'''
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("http://localhost/partners/[0-9]+/users/[0-9]+");'
|
||||
}
|
||||
|
||||
@Issue('115')
|
||||
@@ -703,8 +706,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | headerEvaluationString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')'''
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | 'assertThat(response.header("Location")).matches("^((http[s]?|ftp):/)/?([^:/s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+");'
|
||||
}
|
||||
|
||||
def "should work with more complex stuff and jsonpaths with #methodBuilderName"() {
|
||||
@@ -744,8 +747,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should work properly with GString url with #methodBuilderName"() {
|
||||
@@ -777,8 +780,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
def "should resolve properties in GString with regular expression with #methodBuilderName"() {
|
||||
@@ -816,14 +819,14 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
test.contains("""assertThatJson(parsedJson).field("message").matches("User not found by email = \\\\\\\\[[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\\\\\.[a-zA-Z]{2,4}\\\\\\\\]")""")
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('42')
|
||||
def "should not omit the optional field in the test creation with MockMvcSpockMethodBodyBuilder"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -841,7 +844,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
@Issue('42')
|
||||
def "should not omit the optional field in the test creation with MockMvcJUnitMethodBodyBuilder"() {
|
||||
given:
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -905,8 +908,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | assertionStrings
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''', '''assertThatLocationIsNull(response.header('Location'))''']
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''', '''assertThatLocationIsNull(response.header('Location'))''']
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''', '''assertThatLocationIsNull(response.header("Location"))''']
|
||||
}
|
||||
|
||||
def "should support inner map and list definitions with #methodBuilderName"() {
|
||||
@@ -972,8 +975,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
!test.contains("cursor")
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '"street":"Light Street"'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"street\\":\\"Light Street\\"'
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '"street":"Light Street"'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '\\"street\\":\\"Light Street\\"'
|
||||
|
||||
}
|
||||
|
||||
@@ -1011,8 +1014,8 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
!test.contains("\\u041f")
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('177')
|
||||
@@ -1038,9 +1041,9 @@ World.''')
|
||||
test.contains(bodyString)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | """'''hello,
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | """'''hello,
|
||||
World.'''"""
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '\\"hello,\\nWorld.\\"'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '\\"hello,\\nWorld.\\"'
|
||||
}
|
||||
|
||||
@Issue('180')
|
||||
@@ -1074,11 +1077,11 @@ World.'''"""
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | requestStrings
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | ["""'content-type', 'multipart/form-data;boundary=AaB03x'""",
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ["""'content-type', 'multipart/form-data;boundary=AaB03x'""",
|
||||
""".param('formParameter', '"formParameterValue"'""",
|
||||
""".param('someBooleanParameter', 'true')""",
|
||||
""".multiPart('file', 'filename.csv', 'file content'.bytes)"""]
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | ['"content-type", "multipart/form-data;boundary=AaB03x"',
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | ['"content-type", "multipart/form-data;boundary=AaB03x"',
|
||||
'.param("formParameter", "\\"formParameterValue\\"")',
|
||||
'.param("someBooleanParameter", "true")',
|
||||
'.multiPart("file", "filename.csv", "file content".getBytes());']
|
||||
@@ -1112,8 +1115,8 @@ World.'''"""
|
||||
test.contains('.multiPart')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('#216')
|
||||
@@ -1141,7 +1144,7 @@ World.'''"""
|
||||
)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1175,7 +1178,7 @@ World.'''"""
|
||||
)
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
@@ -1210,8 +1213,8 @@ World.'''"""
|
||||
test.contains('''assertThatRejectionReasonIsNull(''')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('262')
|
||||
@@ -1236,7 +1239,7 @@ World.'''"""
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
@@ -1275,8 +1278,8 @@ World.'''"""
|
||||
test.contains('assertThatJson(parsedJson).arrayField().contains("SpringBoot").value()')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('266')
|
||||
@@ -1308,8 +1311,8 @@ World.'''"""
|
||||
test.contains('assertThatJson(parsedJson).array().arrayField().isEqualTo("Boot").value()')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('47')
|
||||
@@ -1336,8 +1339,8 @@ World.'''"""
|
||||
stubMappingIsValidWireMockStub(contractDsl)
|
||||
where:
|
||||
methodBuilderName | methodBuilder | bodyDefinitionString
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) } | '.when().async()'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) } | '.when().async()'
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | '.when().async()'
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) } | '.when().async()'
|
||||
}
|
||||
|
||||
def "should generate proper test code with array of primitives using #methodBuilderName"() {
|
||||
@@ -1369,8 +1372,8 @@ World.'''"""
|
||||
test.contains('assertThatJson(parsedJson).array("partners").array("payment_methods").arrayField().isEqualTo("CASH").value()')
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl) }
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('#273')
|
||||
@@ -1386,7 +1389,7 @@ World.'''"""
|
||||
body( code: 9, message: $(client('Wrong credentials'), server(regex('^(?!\\s*$).+'))) )
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl)
|
||||
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDsl, properties)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.then(blockBuilder)
|
||||
|
||||
@@ -32,7 +32,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
|
||||
def 'should convert a json with list as root to a map of path to value'() {
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("some").field("nested").field("json").isEqualTo("with value")""" &&
|
||||
@@ -125,7 +125,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("some").field("nested").field("json").isEqualTo("with value")""" &&
|
||||
@@ -155,7 +155,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array("items").arrayField().isEqualTo("HOP").value()""" &&
|
||||
@@ -174,7 +174,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("property1").isNull()""" &&
|
||||
@@ -193,7 +193,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("extensions").field("7").isEqualTo(28)""" &&
|
||||
@@ -222,7 +222,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
}
|
||||
'''
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array("errors").contains("property").isEqualTo("email")""" &&
|
||||
@@ -273,7 +273,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
]
|
||||
]
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(json)
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(json)
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("some").field("nested").field("json").isEqualTo("with value")""" &&
|
||||
@@ -309,7 +309,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
"property2": "b"
|
||||
}"""
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("property1").isEqualTo("a")""" &&
|
||||
@@ -331,7 +331,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
"property3": false
|
||||
}"""
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("property1").isEqualTo("true")""" &&
|
||||
@@ -359,7 +359,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
]
|
||||
]
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(json)
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(json)
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("property1").isEqualTo("a")""" &&
|
||||
@@ -390,7 +390,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
]
|
||||
]
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(json)
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(json)
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("property").field(7).isEqualTo(0.0)""" &&
|
||||
@@ -414,7 +414,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
"property2": "b"
|
||||
}]"""
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().contains("property1").isEqualTo("a")""" &&
|
||||
@@ -441,7 +441,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
]
|
||||
}"""
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("property1").contains("property2").isEqualTo("test1")""" &&
|
||||
@@ -466,7 +466,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
"property2": {"property3": "b"}
|
||||
}"""
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("property2").field("property3").isEqualTo("b")""" &&
|
||||
@@ -487,7 +487,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
property2: Pattern.compile('[0-9]{3}')
|
||||
]
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(json)
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(json)
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("property2").matches("[0-9]{3}")""" &&
|
||||
@@ -507,7 +507,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
property2: Pattern.compile('\\d+')
|
||||
]
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(json)
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(json)
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("property2").matches("\\\\d+")""" &&
|
||||
@@ -527,7 +527,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
]
|
||||
]
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(json)
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(json)
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("errors").contains("property").isEqualTo("bank_account_number")""" &&
|
||||
@@ -563,7 +563,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
}]
|
||||
'''
|
||||
when:
|
||||
JsonPaths pathAndValues = JsonToJsonPathsConverter.transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
JsonPaths pathAndValues = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(new JsonSlurper().parseText(json))
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("place").field("bounding_box").array("coordinates").array().arrayField().isEqualTo(38.995548)""" &&
|
||||
|
||||
Reference in New Issue
Block a user