Added support fot dots in keys
without this change it's impossible to work with jsons that have dots in keys
with this change that's possible again
fixes #269
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.example.loan.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class FraudServiceRequest {
|
||||
|
||||
@JsonProperty("client.id")
|
||||
private String clientId;
|
||||
|
||||
private BigDecimal loanAmount;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.example.loan.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class FraudServiceResponse {
|
||||
|
||||
private FraudCheckStatus fraudCheckStatus;
|
||||
|
||||
@JsonProperty("rejection.reason")
|
||||
private String rejectionReason;
|
||||
|
||||
public FraudServiceResponse() {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.example.fraud.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class FraudCheck {
|
||||
|
||||
@JsonProperty("client.id")
|
||||
private String clientId;
|
||||
|
||||
private BigDecimal loanAmount;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.example.fraud.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class FraudCheckResult {
|
||||
|
||||
private FraudCheckStatus fraudCheckStatus;
|
||||
|
||||
@JsonProperty("rejection.reason")
|
||||
private String rejectionReason;
|
||||
|
||||
public FraudCheckResult() {
|
||||
|
||||
@@ -5,7 +5,7 @@ org.springframework.cloud.contract.spec.Contract.make {
|
||||
method 'PUT' // (2)
|
||||
url '/fraudcheck' // (3)
|
||||
body([ // (4)
|
||||
clientId: $(regex('[0-9]{10}')),
|
||||
"client.id": $(regex('[0-9]{10}')),
|
||||
loanAmount: 99999
|
||||
])
|
||||
headers { // (5)
|
||||
@@ -16,7 +16,7 @@ org.springframework.cloud.contract.spec.Contract.make {
|
||||
status 200 // (7)
|
||||
body([ // (8)
|
||||
fraudCheckStatus: "FRAUD",
|
||||
rejectionReason: "Amount too high"
|
||||
"rejection.reason": "Amount too high"
|
||||
])
|
||||
headers { // (9)
|
||||
contentType('application/vnd.fraud.v1+json')
|
||||
|
||||
@@ -6,7 +6,7 @@ org.springframework.cloud.contract.spec.Contract.make {
|
||||
url '/fraudcheck'
|
||||
body("""
|
||||
{
|
||||
"clientId":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}",
|
||||
"client.id":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
@@ -20,7 +20,7 @@ org.springframework.cloud.contract.spec.Contract.make {
|
||||
status 200
|
||||
body(
|
||||
fraudCheckStatus: "OK",
|
||||
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))
|
||||
"rejection.reason": $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': value(
|
||||
|
||||
@@ -170,37 +170,37 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
"url" : "/api/12",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -77.119759)]"
|
||||
"matchesJsonPath" : "$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == -77.119759)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.text == 'Gonna see you at Warsaw')]"
|
||||
"matchesJsonPath" : "$[*][?(@.['text'] == 'Gonna see you at Warsaw')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.place_type == 'city')]"
|
||||
"matchesJsonPath" : "$[*].['place'][?(@.['place_type'] == 'city')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.id == 492967299297845248)]"
|
||||
"matchesJsonPath" : "$[*][?(@.['id'] == 492967299297845248)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.791645)]"
|
||||
"matchesJsonPath" : "$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == 38.791645)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.country == 'United States')]"
|
||||
"matchesJsonPath" : "$[*].['place'][?(@.['country'] == 'United States')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.id_str == '492967299297845248')]"
|
||||
"matchesJsonPath" : "$[*][?(@.['id_str'] == '492967299297845248')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -76.909393)]"
|
||||
"matchesJsonPath" : "$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == -76.909393)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.name == 'Washington')]"
|
||||
"matchesJsonPath" : "$[*].['place'][?(@.['name'] == 'Washington')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box[?(@.type == 'Polygon')]"
|
||||
"matchesJsonPath" : "$[*].['place'].['bounding_box'][?(@.['type'] == 'Polygon')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.url == 'http://api.twitter.com/1/geo/id/01fbe706f872cb32.json')]"
|
||||
"matchesJsonPath" : "$[*].['place'][?(@.['url'] == 'http://api.twitter.com/1/geo/id/01fbe706f872cb32.json')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.995548)]"
|
||||
"matchesJsonPath" : "$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == 38.995548)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.country_code == 'US')]"
|
||||
"matchesJsonPath" : "$[*].['place'][?(@.['country_code'] == 'US')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.full_name == 'Washington, DC')]"
|
||||
"matchesJsonPath" : "$[*].['place'][?(@.['full_name'] == 'Washington, DC')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.created_at == 'Sat Jul 26 09:38:57 +0000 2014')]"
|
||||
"matchesJsonPath" : "$[*][?(@.['created_at'] == 'Sat Jul 26 09:38:57 +0000 2014')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.id == '01fbe706f872cb32')]"
|
||||
"matchesJsonPath" : "$[*].['place'][?(@.['id'] == '01fbe706f872cb32')]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
@@ -372,9 +372,9 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
"url" : "/users/password",
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.email =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4})?/)]"
|
||||
"matchesJsonPath" : "$[?(@.['email'] =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4})?/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.callback_url =~ /((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?/)]"
|
||||
"matchesJsonPath" : "$[?(@.['callback_url'] =~ /((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?/)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
@@ -531,15 +531,15 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
}
|
||||
},
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.valueWithoutAMatcher == 'foo')]"
|
||||
"matchesJsonPath" : "$[?(@.['valueWithoutAMatcher'] == 'foo')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.valueWithTypeMatch == 'string')]"
|
||||
"matchesJsonPath" : "$[?(@.['valueWithTypeMatch'] == 'string')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.list.some.nested[?(@.anothervalue == 4)]"
|
||||
"matchesJsonPath" : "$.['list'].['some'].['nested'][?(@.['anothervalue'] == 4)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.list.someother.nested[?(@.anothervalue == 4)]"
|
||||
"matchesJsonPath" : "$.['list'].['someother'].['nested'][?(@.['anothervalue'] == 4)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.list.someother.nested[?(@.json == 'with value')]"
|
||||
"matchesJsonPath" : "$.['list'].['someother'].['nested'][?(@.['json'] == 'with value')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.duck =~ /([0-9]{3})/)]"
|
||||
}, {
|
||||
@@ -649,8 +649,8 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
callback_url: 'http://partners.com'
|
||||
)
|
||||
stubMatchers {
|
||||
jsonPath('$.email', byRegex(email()))
|
||||
jsonPath('$.callback_url', byRegex(hostname()))
|
||||
jsonPath('$.[\\'email\\']', byRegex(email()))
|
||||
jsonPath('$.[\\'callback_url\\']', byRegex(hostname()))
|
||||
}
|
||||
}
|
||||
response {
|
||||
@@ -679,9 +679,9 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
"url" : "/users/password2",
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.email =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4})/)]"
|
||||
"matchesJsonPath" : "$[?(@.['email'] =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4})/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.callback_url =~ /(((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?)/)]"
|
||||
"matchesJsonPath" : "$[?(@.['callback_url'] =~ /(((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?)/)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
|
||||
@@ -83,7 +83,7 @@ class JUnitMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
|
||||
@Override
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, Map.Entry entry) {
|
||||
processBodyElement(blockBuilder, property + "." + entry.key, entry.value)
|
||||
processBodyElement(blockBuilder, property, property + "." + entry.key, entry.value)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -103,7 +103,7 @@ abstract class JUnitMethodBodyBuilder extends RequestProcessingMethodBodyBuilder
|
||||
|
||||
@Override
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, Map.Entry entry) {
|
||||
processBodyElement(blockBuilder, getMapKeyReferenceString(property, entry), entry.value)
|
||||
processBodyElement(blockBuilder, property, getMapKeyReferenceString(property, entry), entry.value)
|
||||
}
|
||||
|
||||
private String getMapKeyReferenceString(String property, Map.Entry entry) {
|
||||
|
||||
@@ -38,6 +38,7 @@ 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 org.springframework.util.SerializationUtils
|
||||
import org.springframework.util.StringUtils
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
@@ -331,7 +332,7 @@ abstract class MethodBodyBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
processBodyElement(bb, "", convertedResponseBody)
|
||||
processBodyElement(bb, "", "", convertedResponseBody)
|
||||
}
|
||||
|
||||
protected void methodForEqualityCheck(BodyMatcher bodyMatcher, BlockBuilder bb, Object copiedBody) {
|
||||
@@ -398,7 +399,7 @@ abstract class MethodBodyBuilder {
|
||||
|
||||
// Doing a clone doesn't work for nested lists...
|
||||
private Object cloneBody(Object object) {
|
||||
if (object instanceof List) {
|
||||
if (object instanceof List || object instanceof Map) {
|
||||
byte[] serializedObject = SerializationUtils.serialize(object)
|
||||
return SerializationUtils.deserialize(serializedObject)
|
||||
}
|
||||
@@ -458,6 +459,21 @@ abstract class MethodBodyBuilder {
|
||||
return '"' + StringEscapeUtils.escapeJava(string) + '"'
|
||||
}
|
||||
|
||||
protected String trailingKey(String key) {
|
||||
if (key.startsWith(".")) {
|
||||
return key.substring(1)
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
private String wrappedWithBracketsForDottedProp(String key) {
|
||||
String remindingKey = trailingKey(key)
|
||||
if (remindingKey.contains(".")) {
|
||||
return "['${remindingKey}']"
|
||||
}
|
||||
return remindingKey
|
||||
}
|
||||
|
||||
/**
|
||||
* Post processing of each JSON path entry
|
||||
*/
|
||||
@@ -477,8 +493,8 @@ abstract class MethodBodyBuilder {
|
||||
* Appends to {@link BlockBuilder} processing of the given String value.
|
||||
*/
|
||||
protected void processText(BlockBuilder blockBuilder, String property, Object value) {
|
||||
if (value instanceof String && value.startsWith('$')) {
|
||||
String newValue = stripFirstChar(value).replaceAll('\\$value', "responseBody$property")
|
||||
if (value instanceof String && (value as String).startsWith('$')) {
|
||||
String newValue = stripFirstChar((value as String)).replaceAll('\\$value', "responseBody$property")
|
||||
blockBuilder.addLine(newValue)
|
||||
addColonIfRequired(blockBuilder)
|
||||
} else {
|
||||
@@ -502,6 +518,16 @@ abstract class MethodBodyBuilder {
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, Object value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends to the {@link BlockBuilder} the assertion for the given body element
|
||||
*/
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String oldProp, String property, Object value) {
|
||||
String propDiff = property - oldProp
|
||||
String prop = wrappedWithBracketsForDottedProp(propDiff)
|
||||
String mergedProp = StringUtils.hasText(property) ? "${oldProp}.${prop}" : ""
|
||||
processBodyElement(blockBuilder, mergedProp, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes unnecessary quotes
|
||||
*/
|
||||
@@ -589,7 +615,7 @@ abstract class MethodBodyBuilder {
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, List list) {
|
||||
list.eachWithIndex { listElement, listIndex ->
|
||||
String prop = getPropertyInListString(property, listIndex as Integer)
|
||||
processBodyElement(blockBuilder, prop, listElement)
|
||||
processBodyElement(blockBuilder, property, prop, listElement)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class RestAssuredJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
|
||||
protected void processHeaderElement(BlockBuilder blockBuilder, String property, Object value) {
|
||||
if (value instanceof NotToEscapePattern) {
|
||||
blockBuilder.addLine("assertThat(response.header(\"$property\"))." +
|
||||
"${createMatchesMethod(value.serverValue.pattern().replace("\\", "\\\\"))};")
|
||||
"${createMatchesMethod((value as NotToEscapePattern).serverValue.pattern().replace("\\", "\\\\"))};")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class SpockMessagingMethodBodyBuilder extends MessagingMethodBodyBuilder {
|
||||
|
||||
@Override
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, Map.Entry entry) {
|
||||
processBodyElement(blockBuilder, property + "." + entry.key, entry.value)
|
||||
processBodyElement(blockBuilder, property, property + "." + entry.key, entry.value)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,12 +68,12 @@ abstract class SpockMethodRequestProcessingBodyBuilder extends RequestProcessing
|
||||
|
||||
@Override
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, ExecutionProperty exec) {
|
||||
blockBuilder.addLine("${exec.insertValue("parsedJson.read('\$$property')")}")
|
||||
blockBuilder.addLine("${exec.insertValue("parsedJson.read('''\$$property''')")}")
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processBodyElement(BlockBuilder blockBuilder, String property, Map.Entry entry) {
|
||||
processBodyElement(blockBuilder, property + "." + entry.key, entry.value)
|
||||
processBodyElement(blockBuilder, property, property + "." + entry.key, entry.value)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -82,11 +82,12 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable {
|
||||
@Override
|
||||
public MethodBufferingJsonVerifiable field(Object value) {
|
||||
Object valueToPut = value instanceof ShouldTraverse ? ((ShouldTraverse) value).value : value;
|
||||
DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(this.delegate.field(valueToPut), this.methodsBuffer);
|
||||
Object wrappedValue = wrapInBrackets(valueToPut);
|
||||
DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(this.delegate.field(wrappedValue), this.methodsBuffer);
|
||||
if (this.delegate.isIteratingOverArray() && !(value instanceof ShouldTraverse)) {
|
||||
verifiable.appendMethodWithQuotedValue("contains", wrapInBrackets(valueToPut));
|
||||
verifiable.appendMethodWithQuotedValue("contains", wrappedValue);
|
||||
} else {
|
||||
verifiable.appendMethodWithQuotedValue("field", wrapInBrackets(valueToPut));
|
||||
verifiable.appendMethodWithQuotedValue("field", wrappedValue);
|
||||
}
|
||||
return verifiable;
|
||||
}
|
||||
@@ -102,15 +103,17 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable {
|
||||
|
||||
@Override
|
||||
public MethodBufferingJsonVerifiable array(Object value) {
|
||||
DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(this.delegate.array(value), this.methodsBuffer);
|
||||
verifiable.appendMethodWithQuotedValue("array", wrapInBrackets(value));
|
||||
Object valueToPut = wrapInBrackets(value);
|
||||
DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(this.delegate.array(valueToPut), this.methodsBuffer);
|
||||
verifiable.appendMethodWithQuotedValue("array", valueToPut);
|
||||
return verifiable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodBufferingJsonVerifiable arrayField(Object value) {
|
||||
DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(this.delegate.field(value).arrayField(), this.methodsBuffer);
|
||||
verifiable.appendMethodWithQuotedValue("array", wrapInBrackets(value));
|
||||
Object valueToPut = wrapInBrackets(value);
|
||||
DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(this.delegate.field(valueToPut).arrayField(), this.methodsBuffer);
|
||||
verifiable.appendMethodWithQuotedValue("array", valueToPut);
|
||||
return verifiable;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,13 +113,25 @@ class JsonToJsonPathsConverter {
|
||||
if (value == null && bodyMatcher.matchingType() != MatchingType.EQUALITY) {
|
||||
return path
|
||||
}
|
||||
int lastIndexOfDot = path.lastIndexOf(".")
|
||||
int lastIndexOfDot = lastIndexOfDot(path)
|
||||
String toLastDot = path.substring(0, lastIndexOfDot)
|
||||
String fromLastDot = path.substring(lastIndexOfDot + 1)
|
||||
String comparison = createComparison(bodyMatcher, value, body)
|
||||
return "${toLastDot}[?(@.${fromLastDot} ${comparison})]"
|
||||
}
|
||||
|
||||
private static int lastIndexOfDot(String path) {
|
||||
if (pathContainsDotSeparatedKey(path)) {
|
||||
int lastIndexOfBracket = path.lastIndexOf("['")
|
||||
return path.substring(0, lastIndexOfBracket).lastIndexOf(".")
|
||||
}
|
||||
return path.lastIndexOf(".")
|
||||
}
|
||||
|
||||
private static boolean pathContainsDotSeparatedKey(String path) {
|
||||
return path.contains("['")
|
||||
}
|
||||
|
||||
private static String createComparison(BodyMatcher bodyMatcher, Object value, def body) {
|
||||
if (bodyMatcher.matchingType() == MatchingType.EQUALITY) {
|
||||
if (!body) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext
|
||||
import com.jayway.jsonpath.JsonPath
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.dsl.WireMockStubVerifier
|
||||
@@ -780,6 +782,20 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
test.contains('assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason.title"));')
|
||||
}
|
||||
|
||||
String sampleJson = '''
|
||||
|
||||
[
|
||||
{
|
||||
"name" : "iPhone",
|
||||
"number": "0123-4567-8888"
|
||||
},
|
||||
{
|
||||
"name" : "home",
|
||||
"number": "0123-4567-8910"
|
||||
}
|
||||
]
|
||||
'''
|
||||
|
||||
@Issue('#85')
|
||||
def "should execute custom method for more complex structures on the response side when using Spock"() {
|
||||
given:
|
||||
@@ -806,8 +822,11 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$[0].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$[1].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$.[0].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$.[1].name")''')
|
||||
and:
|
||||
DocumentContext context = JsonPath.parse(sampleJson)
|
||||
context.read('$.[0].name') == 'iPhone'
|
||||
}
|
||||
|
||||
@Issue('#85')
|
||||
@@ -836,8 +855,8 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
|
||||
builder.then(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$[0].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$[1].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$.[0].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$.[1].name")''')
|
||||
}
|
||||
|
||||
@Issue('#150')
|
||||
|
||||
@@ -83,7 +83,7 @@ class MethodBodyBuilderSpec extends Specification implements WireMockStubVerifie
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('$.myArray[0].anotherArrayNeededForBug[0].optionalNotEmpty')
|
||||
test.contains('$.myArray.[0].anotherArrayNeededForBug.[0].optionalNotEmpty')
|
||||
!test.contains('cursor')
|
||||
!test.contains('REGEXP>>')
|
||||
and:
|
||||
@@ -106,4 +106,51 @@ DocumentContext parsedJson = JsonPath.parse(json);
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
@Issue('#269')
|
||||
def "should work with execute and keys with dots [#methodBuilderName]"() {
|
||||
given:
|
||||
Contract contractDsl = Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
urlPath '/foo'
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body (
|
||||
foo: ["my.dotted.response" : $(c('foo'), p(execute('"foo".equals($it)')))]
|
||||
)
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
}
|
||||
}
|
||||
}
|
||||
MethodBodyBuilder builder = methodBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('''$.foo.['my.dotted.response']''')
|
||||
!test.contains('cursor')
|
||||
!test.contains('REGEXP>>')
|
||||
and:
|
||||
SyntaxChecker.tryToCompile(methodBuilderName, blockBuilder.toString())
|
||||
and:
|
||||
String jsonSample = '''\
|
||||
String json = "{\\"foo\\":{\\"my.dotted.response\\":\\"foo\\"}}";
|
||||
DocumentContext parsedJson = JsonPath.parse(json);
|
||||
'''
|
||||
and:
|
||||
LinkedList<String> lines = [] as LinkedList<String>
|
||||
test.eachLine { if (it.contains('"foo".equals')) lines << it else it }
|
||||
lines.addFirst(jsonSample)
|
||||
SyntaxChecker.tryToRun(methodBuilderName, lines.join("\n"))
|
||||
where:
|
||||
methodBuilderName | methodBuilder
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
|
||||
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1022,7 +1022,7 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
|
||||
}
|
||||
where:
|
||||
methodBuilderName | methodBuilder | assertionStrings
|
||||
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) } | ['''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"))''']
|
||||
}
|
||||
|
||||
@@ -1690,7 +1690,7 @@ World.'''"""
|
||||
builder.then(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('assertThatRejectionReasonIsNull(parsedJson.read(\'$.rejectionReason.title\'))')
|
||||
test.contains('assertThatRejectionReasonIsNull(parsedJson.read(\'\'\'$.rejectionReason.title\'\'\'))')
|
||||
when:
|
||||
SyntaxChecker.tryToCompileGroovy(blockBuilder.toString())
|
||||
then:
|
||||
@@ -1724,8 +1724,8 @@ World.'''"""
|
||||
builder.then(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read('$[0].name')''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read('$[1].name')''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read(\'\'\'$.[0].name\'\'\')''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read(\'\'\'$.[1].name\'\'\')''')
|
||||
}
|
||||
|
||||
@Issue('#85')
|
||||
@@ -1754,8 +1754,8 @@ World.'''"""
|
||||
builder.then(blockBuilder)
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$[0].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$[1].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$.[0].name")''')
|
||||
test.contains('''assertThatUserNameIsNotNull(parsedJson.read("$.[1].name")''')
|
||||
}
|
||||
|
||||
@Issue('#111')
|
||||
|
||||
@@ -51,7 +51,10 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
dateTime: "2017-01-01T01:23:45",
|
||||
time: "01:02:34",
|
||||
valueWithoutAMatcher: "foo",
|
||||
valueWithTypeMatch: "string"
|
||||
valueWithTypeMatch: "string",
|
||||
key: [
|
||||
'complex.key' : 'foo'
|
||||
]
|
||||
])
|
||||
stubMatchers {
|
||||
jsonPath('$.duck', byRegex("[0-9]{3}"))
|
||||
@@ -63,6 +66,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
jsonPath('$.date', byDate())
|
||||
jsonPath('$.dateTime', byTimestamp())
|
||||
jsonPath('$.time', byTime())
|
||||
jsonPath("\$.['key'].['complex.key']", byEquality())
|
||||
}
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
@@ -91,6 +95,9 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
],
|
||||
valueWithMinEmpty: [],
|
||||
valueWithMaxEmpty: [],
|
||||
key: [
|
||||
'complex.key' : 'foo'
|
||||
]
|
||||
])
|
||||
testMatchers {
|
||||
// asserts the jsonpath value against manual regex
|
||||
@@ -131,6 +138,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
})
|
||||
// will execute a method `assertThatValueIsANumber`
|
||||
jsonPath('$.duck', byCommand('assertThatValueIsANumber($it)'))
|
||||
jsonPath("\$.['key'].['complex.key']", byEquality())
|
||||
}
|
||||
headers {
|
||||
contentType(applicationJson())
|
||||
@@ -165,6 +173,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
test.contains('assertThat((Object) parsedJson.read("' + rootElement + '.valueWithMaxEmpty")).isInstanceOf(java.util.List.class)')
|
||||
test.contains('assertThat(parsedJson.read("' + rootElement + '.valueWithMaxEmpty", java.util.Collection.class).size()).isLessThanOrEqualTo(0)')
|
||||
test.contains('assertThatValueIsANumber(parsedJson.read("' + rootElement + '.duck")')
|
||||
test.contains('assertThat(parsedJson.read("' + rootElement + '''.['key'].['complex.key']", String.class)).isEqualTo("foo")''')
|
||||
!test.contains('cursor')
|
||||
and:
|
||||
try {
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.cloud.contract.verifier.dsl
|
||||
|
||||
import groovy.json.JsonBuilder
|
||||
import groovy.json.JsonSlurper
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy
|
||||
import org.springframework.cloud.contract.verifier.file.ContractMetadata
|
||||
import org.springframework.cloud.contract.verifier.util.AssertionUtil
|
||||
@@ -257,7 +258,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
"matchesJsonPath" : "$[?(@.['name'] == 'Jan')]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
@@ -305,13 +306,13 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.created == '2014-02-02 12:23:43')]"
|
||||
"matchesJsonPath" : "$[?(@.['created'] == '2014-02-02 12:23:43')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.surname =~ /[a-zA-Z]+/)]"
|
||||
"matchesJsonPath" : "$[?(@.['surname'] =~ /[a-zA-Z]+/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
"matchesJsonPath" : "$[?(@.['name'] == 'Jan')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.id =~ /[0-9]+/)]"
|
||||
"matchesJsonPath" : "$[?(@.['id'] =~ /[0-9]+/)]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
@@ -351,7 +352,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"url" : "/users",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
"matchesJsonPath" : "$[?(@.['name'] == 'Jan')]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
@@ -589,7 +590,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.personalId =~ /^[0-9]{11}$/)]"
|
||||
"matchesJsonPath" : "$[?(@.['personalId'] =~ /^[0-9]{11}$/)]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
@@ -644,9 +645,9 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"url" : "/fraudcheck",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.loanAmount == 123.123)]"
|
||||
"matchesJsonPath" : "$[?(@.['loanAmount'] == 123.123)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.clientPesel =~ /[0-9]{10}/)]"
|
||||
"matchesJsonPath" : "$[?(@.['clientPesel'] =~ /[0-9]{10}/)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
@@ -1032,17 +1033,17 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.propertyName =~ /[0-9]{2}/)]"
|
||||
"matchesJsonPath" : "$.['errors'][*][?(@.['propertyName'] =~ /[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.providerValue == 'Test')]"
|
||||
"matchesJsonPath" : "$.['errors'][*][?(@.['providerValue'] == 'Test')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.lastName =~ /.*/)]"
|
||||
"matchesJsonPath" : "$[?(@.['lastName'] =~ /.*/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.firstName =~ /.*/)]"
|
||||
"matchesJsonPath" : "$[?(@.['firstName'] =~ /.*/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.birthDate =~ /[0-9]{4}-[0-9]{2}-[0-9]{2}/)]"
|
||||
"matchesJsonPath" : "$[?(@.['birthDate'] =~ /[0-9]{4}-[0-9]{2}-[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.personalId =~ /[0-9]{11}/)]"
|
||||
"matchesJsonPath" : "$[?(@.['personalId'] =~ /[0-9]{11}/)]"
|
||||
}]
|
||||
},
|
||||
"response" : {
|
||||
@@ -1092,17 +1093,17 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"url" : "/reissue-payment-order",
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.loanNumber == '999997001')]"
|
||||
"matchesJsonPath" : "$[?(@.['loanNumber'] == '999997001')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.username =~ /.*/)]"
|
||||
"matchesJsonPath" : "$[?(@.['username'] =~ /.*/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.amount =~ /[0-9.]+/)]"
|
||||
"matchesJsonPath" : "$[?(@.['amount'] =~ /[0-9.]+/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.cardId == 1)]"
|
||||
"matchesJsonPath" : "$[?(@.['cardId'] == 1)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.currency == 'DKK')]"
|
||||
"matchesJsonPath" : "$[?(@.['currency'] == 'DKK')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.applicationName =~ /.*/)]"
|
||||
"matchesJsonPath" : "$[?(@.['applicationName'] =~ /.*/)]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
@@ -1201,7 +1202,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"request" : {
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.property == 'value')]"
|
||||
"matchesJsonPath" : "$[?(@.['property'] == 'value')]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
@@ -1285,9 +1286,9 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"url" : "/users/password",
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.callback_url =~ /((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?/)]"
|
||||
"matchesJsonPath" : "$[?(@.['callback_url'] =~ /((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.email =~ /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4}/)]"
|
||||
"matchesJsonPath" : "$[?(@.['email'] =~ /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4}/)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
@@ -1336,7 +1337,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"urlPattern" : "/partners/^[0-9]*$/agents/11/customers/09665703Z",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.first_name == 'Josef')]"
|
||||
"matchesJsonPath" : "$[?(@.['first_name'] == 'Josef')]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
@@ -1364,9 +1365,9 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"url" : "/users/password",
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.callback_url =~ /((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?/)]"
|
||||
"matchesJsonPath" : "$[?(@.['callback_url'] =~ /((http[s]?|ftp):\\\\/)\\\\/?([^:\\\\/\\\\s]+)(:[0-9]{1,5})?/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.email =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4})?/)]"
|
||||
"matchesJsonPath" : "$[?(@.['email'] =~ /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,4})?/)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
@@ -1632,4 +1633,53 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
then:
|
||||
json == ''
|
||||
}
|
||||
|
||||
@Issue('#269')
|
||||
def "should create a stub for dot separated keys"() {
|
||||
given:
|
||||
Contract groovyDsl = org.springframework.cloud.contract.spec.Contract.make {
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/fraudcheck'
|
||||
body([ // (4)
|
||||
"client.id": $(regex('[0-9]{10}')),
|
||||
loanAmount: 99999
|
||||
])
|
||||
headers {
|
||||
contentType('application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null), groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
AssertionUtil.assertThatJsonsAreEqual('''
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/fraudcheck",
|
||||
"method" : "PUT",
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"matches" : "application/vnd\\\\.fraud\\\\.v1\\\\+json.*"
|
||||
}
|
||||
},
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.['loanAmount'] == 99999)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.['client.id'] =~ /[0-9]{10}/)]"
|
||||
} ]
|
||||
}
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,23 +39,23 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").field("['json']").isEqualTo("with value")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested[?(@.json == 'with value')]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'][?(@.['json'] == 'with value')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").field("['anothervalue']").isEqualTo(4)""" &&
|
||||
it.jsonPath() == '''$[*].some.nested[?(@.anothervalue == 4)]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'][?(@.['anothervalue'] == 4)]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").array("['withlist']").contains("['name']").isEqualTo("name1")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested.withlist[*][?(@.name == 'name1')]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'].['withlist'][*][?(@.['name'] == 'name1')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").array("['withlist']").contains("['name']").isEqualTo("name2")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested.withlist[*][?(@.name == 'name2')]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'].['withlist'][*][?(@.['name'] == 'name2')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").array("['withlist']").field("['anothernested']").field("['name']").isEqualTo("name3")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested.withlist[*].anothernested[?(@.name == 'name3')]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'].['withlist'][*].['anothernested'][?(@.['name'] == 'name3')]'''
|
||||
}
|
||||
and:
|
||||
assertThatJsonPathsInMapAreValid(json, pathAndValues)
|
||||
@@ -132,19 +132,19 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['some']").field("['nested']").field("['json']").isEqualTo("with value")""" &&
|
||||
it.jsonPath() == '''$.some.nested[?(@.json == 'with value')]'''
|
||||
it.jsonPath() == '''$.['some'].['nested'][?(@.['json'] == 'with value')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['some']").field("['nested']").field("['anothervalue']").isEqualTo(4)""" &&
|
||||
it.jsonPath() == '''$.some.nested[?(@.anothervalue == 4)]'''
|
||||
it.jsonPath() == '''$.['some'].['nested'][?(@.['anothervalue'] == 4)]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['some']").field("['nested']").array("['withlist']").contains("['name']").isEqualTo("name1")""" &&
|
||||
it.jsonPath() == '''$.some.nested.withlist[*][?(@.name == 'name1')]'''
|
||||
it.jsonPath() == '''$.['some'].['nested'].['withlist'][*][?(@.['name'] == 'name1')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['some']").field("['nested']").array("['withlist']").contains("['name']").isEqualTo("name2")""" &&
|
||||
it.jsonPath() == '''$.some.nested.withlist[*][?(@.name == 'name2')]'''
|
||||
it.jsonPath() == '''$.['some'].['nested'].['withlist'][*][?(@.['name'] == 'name2')]'''
|
||||
}
|
||||
and:
|
||||
assertThatJsonPathsInMapAreValid(json, pathAndValues)
|
||||
@@ -162,7 +162,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array("['items']").arrayField().isEqualTo("HOP").value()""" &&
|
||||
it.jsonPath() == '''$.items[?(@ == 'HOP')]'''
|
||||
it.jsonPath() == '''$.['items'][?(@ == 'HOP')]'''
|
||||
}
|
||||
and:
|
||||
assertThatJsonPathsInMapAreValid(json, pathAndValues)
|
||||
@@ -181,11 +181,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['property1']").isNull()""" &&
|
||||
it.jsonPath() == '''$[?(@.property1 == null)]'''
|
||||
it.jsonPath() == '''$[?(@.['property1'] == null)]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['property2']").isEqualTo(true)""" &&
|
||||
it.jsonPath() == '''$[?(@.property2 == true)]'''
|
||||
it.jsonPath() == '''$[?(@.['property2'] == true)]'''
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,15 +200,15 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['extensions']").field("['7']").isEqualTo(28.00)""" &&
|
||||
it.jsonPath() == '''$.extensions[?(@.7 == 28.00)]'''
|
||||
it.jsonPath() == '''$.['extensions'][?(@.['7'] == 28.00)]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['extensions']").field("['14']").isEqualTo(41.00)""" &&
|
||||
it.jsonPath() == '''$.extensions[?(@.14 == 41.00)]'''
|
||||
it.jsonPath() == '''$.['extensions'][?(@.['14'] == 41.00)]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.field("['extensions']").field("['30']").isEqualTo(60.00)""" &&
|
||||
it.jsonPath() == '''$.extensions[?(@.30 == 60.00)]'''
|
||||
it.jsonPath() == '''$.['extensions'][?(@.['30'] == 60.00)]'''
|
||||
}
|
||||
and:
|
||||
assertThatJsonPathsInMapAreValid(json, pathAndValues)
|
||||
@@ -229,15 +229,15 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array("['errors']").contains("['property']").isEqualTo("email")""" &&
|
||||
it.jsonPath() == '''$.errors[*][?(@.property == 'email')]'''
|
||||
it.jsonPath() == '''$.['errors'][*][?(@.['property'] == 'email')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array("['errors']").contains("['message']").isEqualTo("inconsistent value")""" &&
|
||||
it.jsonPath() == '''$.errors[*][?(@.message == 'inconsistent value')]'''
|
||||
it.jsonPath() == '''$.['errors'][*][?(@.['message'] == 'inconsistent value')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array("['errors']").contains("['message']").isEqualTo("inconsistent value2")""" &&
|
||||
it.jsonPath() == '''$.errors[*][?(@.message == 'inconsistent value2')]'''
|
||||
it.jsonPath() == '''$.['errors'][*][?(@.['message'] == 'inconsistent value2')]'''
|
||||
}
|
||||
and:
|
||||
assertThatJsonPathsInMapAreValid(json, pathAndValues)
|
||||
@@ -280,30 +280,30 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").field("['json']").isEqualTo("with value")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested[?(@.json == 'with value')]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'][?(@.['json'] == 'with value')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").field("['anothervalue']").isEqualTo(4)""" &&
|
||||
it.jsonPath() == '''$[*].some.nested[?(@.anothervalue == 4)]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'][?(@.['anothervalue'] == 4)]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").array("['withlist']").contains("['name']").isEqualTo("name1")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested.withlist[*][?(@.name == 'name1')]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'].['withlist'][*][?(@.['name'] == 'name1')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").array("['withlist']").contains("['name']").isEqualTo("name2")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested.withlist[*][?(@.name == 'name2')]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'].['withlist'][*][?(@.['name'] == 'name2')]'''
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method() == """.array().field("['some']").field("['nested']").array("['withlist']").field("['anothernested']").field("['name']").matches("[a-zA-Z]+")""" &&
|
||||
it.jsonPath() == '''$[*].some.nested.withlist[*].anothernested[?(@.name =~ /[a-zA-Z]+/)]'''
|
||||
it.jsonPath() == '''$[*].['some'].['nested'].['withlist'][*].['anothernested'][?(@.['name'] =~ /[a-zA-Z]+/)]'''
|
||||
}
|
||||
when:
|
||||
json.some.nested.withlist[0][2].anothernested.name = "Kowalski"
|
||||
then:
|
||||
assertThatJsonPathsInMapAreValid(JsonOutput.prettyPrint(JsonOutput.toJson(json)), pathAndValues)
|
||||
}
|
||||
|
||||
|
||||
|
||||
def "should generate assertions for simple response body"() {
|
||||
given:
|
||||
@@ -316,11 +316,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property1']").isEqualTo("a")""" &&
|
||||
it.jsonPath() == """\$[?(@.property1 == 'a')]"""
|
||||
it.jsonPath() == """\$[?(@.['property1'] == 'a')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property2']").isEqualTo("b")""" &&
|
||||
it.jsonPath() == """\$[?(@.property2 == 'b')]"""
|
||||
it.jsonPath() == """\$[?(@.['property2'] == 'b')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 2
|
||||
@@ -338,15 +338,15 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property1']").isEqualTo("true")""" &&
|
||||
it.jsonPath() == """\$[?(@.property1 == 'true')]"""
|
||||
it.jsonPath() == """\$[?(@.['property1'] == 'true')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property2']").isNull()""" &&
|
||||
it.jsonPath() == """\$[?(@.property2 == null)]"""
|
||||
it.jsonPath() == """\$[?(@.['property2'] == null)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property3']").isEqualTo(false)""" &&
|
||||
it.jsonPath() == """\$[?(@.property3 == false)]"""
|
||||
it.jsonPath() == """\$[?(@.['property3'] == false)]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 3
|
||||
@@ -366,15 +366,15 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property1']").isEqualTo("a")""" &&
|
||||
it.jsonPath() == """\$[?(@.property1 == 'a')]"""
|
||||
it.jsonPath() == """\$[?(@.['property1'] == 'a')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property2']").contains("['a']").isEqualTo("sth")""" &&
|
||||
it.jsonPath() == """\$.property2[*][?(@.a == 'sth')]"""
|
||||
it.jsonPath() == """\$.['property2'][*][?(@.['a'] == 'sth')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property2']").contains("['b']").isEqualTo("sthElse")""" &&
|
||||
it.jsonPath() == """\$.property2[*][?(@.b == 'sthElse')]"""
|
||||
it.jsonPath() == """\$.['property2'][*][?(@.['b'] == 'sthElse')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 3
|
||||
@@ -396,19 +396,19 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property1']").isEqualTo("a")""" &&
|
||||
it.jsonPath() == """\$[?(@.property1 == 'a')]"""
|
||||
it.jsonPath() == """\$[?(@.['property1'] == 'a')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property2']").contains("['a']").isEqualTo("sth")""" &&
|
||||
it.jsonPath() == """\$.property2[*][?(@.a == 'sth')]"""
|
||||
it.jsonPath() == """\$.['property2'][*][?(@.['a'] == 'sth')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property2']").hasSize(2)""" &&
|
||||
it.jsonPath() == """\$.property2[*]"""
|
||||
it.jsonPath() == """\$.['property2'][*]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property2']").contains("['b']").isEqualTo("sthElse")""" &&
|
||||
it.jsonPath() == """\$.property2[*][?(@.b == 'sthElse')]"""
|
||||
it.jsonPath() == """\$.['property2'][*][?(@.['b'] == 'sthElse')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 4
|
||||
@@ -427,11 +427,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property']").field(7).isEqualTo(0.0)""" &&
|
||||
it.jsonPath() == """\$.property[?(@.7 == 0.0)]"""
|
||||
it.jsonPath() == """\$.['property'][?(@.7 == 0.0)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property']").field(14).isEqualTo(0.0)""" &&
|
||||
it.jsonPath() == """\$.property[?(@.14 == 0.0)]"""
|
||||
it.jsonPath() == """\$.['property'][?(@.14 == 0.0)]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 2
|
||||
@@ -451,11 +451,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().contains("['property1']").isEqualTo("a")""" &&
|
||||
it.jsonPath() == """\$[*][?(@.property1 == 'a')]"""
|
||||
it.jsonPath() == """\$[*][?(@.['property1'] == 'a')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().contains("['property2']").isEqualTo("b")""" &&
|
||||
it.jsonPath() == """\$[*][?(@.property2 == 'b')]"""
|
||||
it.jsonPath() == """\$[*][?(@.['property2'] == 'b')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 2
|
||||
@@ -477,11 +477,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().contains("['property1']").isEqualTo("a")""" &&
|
||||
it.jsonPath() == """\$[*][?(@.property1 == 'a')]"""
|
||||
it.jsonPath() == """\$[*][?(@.['property1'] == 'a')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().contains("['property2']").isEqualTo("b")""" &&
|
||||
it.jsonPath() == """\$[*][?(@.property2 == 'b')]"""
|
||||
it.jsonPath() == """\$[*][?(@.['property2'] == 'b')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.hasSize(2)""" &&
|
||||
@@ -504,11 +504,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property1']").contains("['property2']").isEqualTo("test1")""" &&
|
||||
it.jsonPath() == """\$.property1[*][?(@.property2 == 'test1')]"""
|
||||
it.jsonPath() == """\$.['property1'][*][?(@.['property2'] == 'test1')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property1']").contains("['property3']").isEqualTo("test2")""" &&
|
||||
it.jsonPath() == """\$.property1[*][?(@.property3 == 'test2')]"""
|
||||
it.jsonPath() == """\$.['property1'][*][?(@.['property3'] == 'test2')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 2
|
||||
@@ -529,15 +529,15 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property1']").contains("['property2']").isEqualTo("test1")""" &&
|
||||
it.jsonPath() == """\$.property1[*][?(@.property2 == 'test1')]"""
|
||||
it.jsonPath() == """\$.['property1'][*][?(@.['property2'] == 'test1')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property1']").contains("['property3']").isEqualTo("test2")""" &&
|
||||
it.jsonPath() == """\$.property1[*][?(@.property3 == 'test2')]"""
|
||||
it.jsonPath() == """\$.['property1'][*][?(@.['property3'] == 'test2')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['property1']").hasSize(2)""" &&
|
||||
it.jsonPath() == """\$.property1[*]"""
|
||||
it.jsonPath() == """\$.['property1'][*]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 3
|
||||
@@ -554,11 +554,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property2']").field("['property3']").isEqualTo("b")""" &&
|
||||
it.jsonPath() == """\$.property2[?(@.property3 == 'b')]"""
|
||||
it.jsonPath() == """\$.['property2'][?(@.['property3'] == 'b')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property1']").isEqualTo("a")""" &&
|
||||
it.jsonPath() == """\$[?(@.property1 == 'a')]"""
|
||||
it.jsonPath() == """\$[?(@.['property1'] == 'a')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 2
|
||||
@@ -575,11 +575,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property2']").matches("[0-9]{3}")""" &&
|
||||
it.jsonPath() == """\$[?(@.property2 =~ /[0-9]{3}/)]"""
|
||||
it.jsonPath() == """\$[?(@.['property2'] =~ /[0-9]{3}/)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property1']").isEqualTo("a")""" &&
|
||||
it.jsonPath() == """\$[?(@.property1 == 'a')]"""
|
||||
it.jsonPath() == """\$[?(@.['property1'] == 'a')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 2
|
||||
@@ -595,7 +595,7 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.field("['property2']").matches("\\\\d+")""" &&
|
||||
it.jsonPath() == """\$[?(@.property2 =~ /\\d+/)]"""
|
||||
it.jsonPath() == """\$[?(@.['property2'] =~ /\\d+/)]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 1
|
||||
@@ -614,11 +614,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['errors']").contains("['property']").isEqualTo("bank_account_number")""" &&
|
||||
it.jsonPath() == """\$.errors[*][?(@.property == 'bank_account_number')]"""
|
||||
it.jsonPath() == """\$.['errors'][*][?(@.['property'] == 'bank_account_number')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['errors']").contains("['message']").isEqualTo("incorrect_format")""" &&
|
||||
it.jsonPath() == """\$.errors[*][?(@.message == 'incorrect_format')]"""
|
||||
it.jsonPath() == """\$.['errors'][*][?(@.['message'] == 'incorrect_format')]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 2
|
||||
@@ -639,15 +639,15 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['errors']").contains("['property']").isEqualTo("bank_account_number")""" &&
|
||||
it.jsonPath() == """\$.errors[*][?(@.property == 'bank_account_number')]"""
|
||||
it.jsonPath() == """\$.['errors'][*][?(@.['property'] == 'bank_account_number')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['errors']").contains("['message']").isEqualTo("incorrect_format")""" &&
|
||||
it.jsonPath() == """\$.errors[*][?(@.message == 'incorrect_format')]"""
|
||||
it.jsonPath() == """\$.['errors'][*][?(@.['message'] == 'incorrect_format')]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array("['errors']").hasSize(1)""" &&
|
||||
it.jsonPath() == """\$.errors[*]"""
|
||||
it.jsonPath() == """\$.['errors'][*]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 3
|
||||
@@ -675,19 +675,19 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(38.995548)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == 38.995548)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == 38.995548)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(-77.119759)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == -77.119759)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == -77.119759)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(-76.909393)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == -76.909393)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == -76.909393)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(38.791645)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == 38.791645)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == 38.791645)]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 4
|
||||
@@ -721,19 +721,19 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
then:
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(38.995548)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == 38.995548)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == 38.995548)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(-77.119759)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == -77.119759)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == -77.119759)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(-76.909393)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == -76.909393)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == -76.909393)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().arrayField().isEqualTo(38.791645)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*][?(@ == 38.791645)]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*][?(@ == 38.791645)]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.hasSize(1)""" &&
|
||||
@@ -741,11 +741,11 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").array().hasSize(2)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*][*]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*][*]"""
|
||||
}
|
||||
pathAndValues.find {
|
||||
it.method()== """.array().field("['place']").field("['bounding_box']").array("['coordinates']").hasSize(1)""" &&
|
||||
it.jsonPath() == """\$[*].place.bounding_box.coordinates[*]"""
|
||||
it.jsonPath() == """\$[*].['place'].['bounding_box'].['coordinates'][*]"""
|
||||
}
|
||||
and:
|
||||
pathAndValues.size() == 7
|
||||
@@ -780,6 +780,15 @@ class JsonToJsonPathsConverterSpec extends Specification {
|
||||
'$.a.b.c[?(@.d == 1234)]' == JsonToJsonPathsConverter.convertJsonPathAndRegexToAJsonPath(matcher(MatchingType.EQUALITY, jsonPath, null), body)
|
||||
}
|
||||
|
||||
def "should convert a json path with value to a equality checking for a key with dots"() {
|
||||
given:
|
||||
String jsonPath = '$.a.b.c.[\'d.e\']'
|
||||
and:
|
||||
def body = [ a: [ b: [ c: [ "d.e" : 1234 ] ] ] ]
|
||||
expect:
|
||||
'$.a.b.c[?(@.[\'d.e\'] == 1234)]' == JsonToJsonPathsConverter.convertJsonPathAndRegexToAJsonPath(matcher(MatchingType.EQUALITY, jsonPath, null), body)
|
||||
}
|
||||
|
||||
def "should convert a json path with value to a equality checking json path with quotes for strings"() {
|
||||
given:
|
||||
String jsonPath = '$.a.b.c.d'
|
||||
|
||||
Reference in New Issue
Block a user