Added tabs instead of spaces
This commit is contained in:
@@ -10,15 +10,15 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
def converter = new DslToWireMockClientConverter()
|
||||
and:
|
||||
String dslBody = """
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method('PUT')
|
||||
url \$(client(~/\\/[0-9]{2}/), server('/12'))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method('PUT')
|
||||
url \$(client(~/\\/[0-9]{2}/), server('/12'))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
"""
|
||||
when:
|
||||
String json = converter.convertContent(dslBody)
|
||||
@@ -34,7 +34,7 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
def converter = new DslToWireMockClientConverter()
|
||||
and:
|
||||
String dslBody = """
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/api/12'
|
||||
@@ -84,57 +84,57 @@ class DslToWireMockClientConverterSpec extends Specification {
|
||||
JSONAssert.assertEquals('''
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/api/12",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.995548)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.country == 'United States')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -77.119759)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.name == 'Washington')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box[?(@.type == 'Polygon')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.id_str == '492967299297845248')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.country_code == 'US')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.id == 492967299297845248)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -76.909393)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.791645)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.id == '01fbe706f872cb32')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.url == 'http://api.twitter.com/1/geo/id/01fbe706f872cb32.json')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -77.119759)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -76.909393)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.995548)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.text == 'Gonna see you at Warsaw')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.place_type == 'city')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.created_at == 'Sat Jul 26 09:38:57 +0000 2014')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.full_name == 'Washington, DC')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.791645)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "application/vnd.com.ofg.twitter-places-analyzer.v1+json"
|
||||
}
|
||||
}
|
||||
"url" : "/api/12",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.995548)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.country == 'United States')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -77.119759)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.name == 'Washington')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box[?(@.type == 'Polygon')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.id_str == '492967299297845248')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.country_code == 'US')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.id == 492967299297845248)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -76.909393)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.791645)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.id == '01fbe706f872cb32')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.url == 'http://api.twitter.com/1/geo/id/01fbe706f872cb32.json')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -77.119759)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == -76.909393)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.995548)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.text == 'Gonna see you at Warsaw')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.place_type == 'city')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*][?(@.created_at == 'Sat Jul 26 09:38:57 +0000 2014')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place[?(@.full_name == 'Washington, DC')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[*].place.bounding_box.coordinates[*][*][?(@ == 38.791645)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "application/vnd.com.ofg.twitter-places-analyzer.v1+json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200
|
||||
"status" : 200
|
||||
}
|
||||
}
|
||||
''', json, false)
|
||||
|
||||
@@ -68,8 +68,8 @@ class TestGenerator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizePath(String path) {
|
||||
return FilenameUtils.separatorsToUnix(path)
|
||||
}
|
||||
|
||||
private String normalizePath(String path) {
|
||||
return FilenameUtils.separatorsToUnix(path)
|
||||
}
|
||||
}
|
||||
@@ -10,86 +10,86 @@ import io.codearte.accurest.dsl.internal.QueryParameter
|
||||
@TypeChecked
|
||||
class JaxRsClientSpockMethodBodyBuilder extends SpockMethodBodyBuilder {
|
||||
|
||||
JaxRsClientSpockMethodBodyBuilder(GroovyDsl stubDefinition) {
|
||||
super(stubDefinition)
|
||||
}
|
||||
JaxRsClientSpockMethodBodyBuilder(GroovyDsl stubDefinition) {
|
||||
super(stubDefinition)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void givenBlock(BlockBuilder bb) {
|
||||
}
|
||||
@Override
|
||||
protected void givenBlock(BlockBuilder bb) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void when(BlockBuilder bb) {
|
||||
bb.addLine("def response = webTarget")
|
||||
bb.indent()
|
||||
@Override
|
||||
protected void when(BlockBuilder bb) {
|
||||
bb.addLine("def response = webTarget")
|
||||
bb.indent()
|
||||
|
||||
appendUrlPathAndQueryParameters(bb)
|
||||
appendRequestWithRequiredResponseContentType(bb)
|
||||
appendHeaders(bb)
|
||||
appendMethodAndBody(bb)
|
||||
appendUrlPathAndQueryParameters(bb)
|
||||
appendRequestWithRequiredResponseContentType(bb)
|
||||
appendHeaders(bb)
|
||||
appendMethodAndBody(bb)
|
||||
|
||||
bb.unindent()
|
||||
bb.unindent()
|
||||
|
||||
bb.addEmptyLine()
|
||||
bb.addLine("String responseAsString = response.readEntity(String)")
|
||||
}
|
||||
bb.addEmptyLine()
|
||||
bb.addLine("String responseAsString = response.readEntity(String)")
|
||||
}
|
||||
|
||||
protected void appendRequestWithRequiredResponseContentType(BlockBuilder bb) {
|
||||
String acceptHeader = getHeader("Accept")
|
||||
if (acceptHeader) {
|
||||
bb.addLine(".request('$acceptHeader')")
|
||||
} else {
|
||||
bb.addLine(".request()")
|
||||
}
|
||||
}
|
||||
protected void appendRequestWithRequiredResponseContentType(BlockBuilder bb) {
|
||||
String acceptHeader = getHeader("Accept")
|
||||
if (acceptHeader) {
|
||||
bb.addLine(".request('$acceptHeader')")
|
||||
} else {
|
||||
bb.addLine(".request()")
|
||||
}
|
||||
}
|
||||
|
||||
protected void appendUrlPathAndQueryParameters(BlockBuilder bb) {
|
||||
if (request.url) {
|
||||
bb.addLine(".path('$request.url.serverValue')")
|
||||
} else if (request.urlPath) {
|
||||
bb.addLine(".path('$request.urlPath.serverValue')")
|
||||
request.urlPath.queryParameters?.parameters.findAll(this.&allowedQueryParameter).each { QueryParameter param ->
|
||||
bb.addLine(".queryParam('$param.name', '${resolveParamValue(param).toString()}')")
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void appendUrlPathAndQueryParameters(BlockBuilder bb) {
|
||||
if (request.url) {
|
||||
bb.addLine(".path('$request.url.serverValue')")
|
||||
} else if (request.urlPath) {
|
||||
bb.addLine(".path('$request.urlPath.serverValue')")
|
||||
request.urlPath.queryParameters?.parameters.findAll(this.&allowedQueryParameter).each { QueryParameter param ->
|
||||
bb.addLine(".queryParam('$param.name', '${resolveParamValue(param).toString()}')")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void appendMethodAndBody(BlockBuilder bb) {
|
||||
String method = request.method.serverValue.toString().toLowerCase()
|
||||
if (request.body) {
|
||||
String contentType = getHeader('Content-Type') ?: getRequestContentType().mimeType
|
||||
bb.addLine(".method('$method', entity('$bodyAsString', '$contentType'))")
|
||||
} else {
|
||||
bb.addLine(".method('$method')")
|
||||
}
|
||||
}
|
||||
protected void appendMethodAndBody(BlockBuilder bb) {
|
||||
String method = request.method.serverValue.toString().toLowerCase()
|
||||
if (request.body) {
|
||||
String contentType = getHeader('Content-Type') ?: getRequestContentType().mimeType
|
||||
bb.addLine(".method('$method', entity('$bodyAsString', '$contentType'))")
|
||||
} else {
|
||||
bb.addLine(".method('$method')")
|
||||
}
|
||||
}
|
||||
|
||||
protected appendHeaders(BlockBuilder bb) {
|
||||
request.headers?.collect { Header header ->
|
||||
if (header.name == 'Content-Type' || header.name == 'Accept') return // Particular headers are set via 'request' / 'entity' methods
|
||||
bb.addLine(".header('${header.name}', '${header.serverValue}')")
|
||||
}
|
||||
}
|
||||
protected appendHeaders(BlockBuilder bb) {
|
||||
request.headers?.collect { Header header ->
|
||||
if (header.name == 'Content-Type' || header.name == 'Accept') return // Particular headers are set via 'request' / 'entity' methods
|
||||
bb.addLine(".header('${header.name}', '${header.serverValue}')")
|
||||
}
|
||||
}
|
||||
|
||||
protected String getHeader(String name) {
|
||||
return request.headers?.entries.find { it.name == name }?.serverValue
|
||||
}
|
||||
protected String getHeader(String name) {
|
||||
return request.headers?.entries.find { it.name == name }?.serverValue
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateResponseCodeBlock(BlockBuilder bb) {
|
||||
bb.addLine("response.status == $response.status.serverValue")
|
||||
}
|
||||
@Override
|
||||
protected void validateResponseCodeBlock(BlockBuilder bb) {
|
||||
bb.addLine("response.status == $response.status.serverValue")
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateResponseHeadersBlock(BlockBuilder bb) {
|
||||
response.headers?.collect { Header header ->
|
||||
bb.addLine("response.getHeaderString('$header.name') == '$header.serverValue'")
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void validateResponseHeadersBlock(BlockBuilder bb) {
|
||||
response.headers?.collect { Header header ->
|
||||
bb.addLine("response.getHeaderString('$header.name') == '$header.serverValue'")
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseAsString() {
|
||||
return 'responseAsString'
|
||||
}
|
||||
@Override
|
||||
protected String getResponseAsString() {
|
||||
return 'responseAsString'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,73 +14,73 @@ import java.util.regex.Pattern
|
||||
@TypeChecked
|
||||
class MockMvcSpockMethodBodyBuilder extends SpockMethodBodyBuilder {
|
||||
|
||||
MockMvcSpockMethodBodyBuilder(GroovyDsl stubDefinition) {
|
||||
super(stubDefinition)
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder(GroovyDsl stubDefinition) {
|
||||
super(stubDefinition)
|
||||
}
|
||||
|
||||
protected void given(BlockBuilder bb) {
|
||||
bb.addLine('def request = given()')
|
||||
bb.indent()
|
||||
request.headers?.collect { Header header ->
|
||||
bb.addLine(".header('${getTestSideValue(header.name)}', '${getTestSideValue(header.serverValue)}')")
|
||||
}
|
||||
if (request.body) {
|
||||
bb.addLine(".body('$bodyAsString')")
|
||||
}
|
||||
bb.unindent()
|
||||
}
|
||||
protected void given(BlockBuilder bb) {
|
||||
bb.addLine('def request = given()')
|
||||
bb.indent()
|
||||
request.headers?.collect { Header header ->
|
||||
bb.addLine(".header('${getTestSideValue(header.name)}', '${getTestSideValue(header.serverValue)}')")
|
||||
}
|
||||
if (request.body) {
|
||||
bb.addLine(".body('$bodyAsString')")
|
||||
}
|
||||
bb.unindent()
|
||||
}
|
||||
|
||||
protected void when(BlockBuilder bb) {
|
||||
bb.addLine('def response = given().spec(request)')
|
||||
bb.indent()
|
||||
protected void when(BlockBuilder bb) {
|
||||
bb.addLine('def response = given().spec(request)')
|
||||
bb.indent()
|
||||
|
||||
String url = buildUrl(request)
|
||||
String method = request.method.serverValue.toString().toLowerCase()
|
||||
String url = buildUrl(request)
|
||||
String method = request.method.serverValue.toString().toLowerCase()
|
||||
|
||||
bb.addLine(/.${method}("$url")/)
|
||||
bb.unindent()
|
||||
}
|
||||
bb.addLine(/.${method}("$url")/)
|
||||
bb.unindent()
|
||||
}
|
||||
|
||||
protected void validateResponseCodeBlock(BlockBuilder bb) {
|
||||
bb.addLine("response.statusCode == $response.status.serverValue")
|
||||
}
|
||||
protected void validateResponseCodeBlock(BlockBuilder bb) {
|
||||
bb.addLine("response.statusCode == $response.status.serverValue")
|
||||
}
|
||||
|
||||
protected void validateResponseHeadersBlock(BlockBuilder bb) {
|
||||
response.headers?.collect { Header header ->
|
||||
bb.addLine("response.header('$header.name') ${convertHeaderComparison(header.serverValue)}")
|
||||
}
|
||||
}
|
||||
protected void validateResponseHeadersBlock(BlockBuilder bb) {
|
||||
response.headers?.collect { Header header ->
|
||||
bb.addLine("response.header('$header.name') ${convertHeaderComparison(header.serverValue)}")
|
||||
}
|
||||
}
|
||||
|
||||
private String convertHeaderComparison(Object headerValue) {
|
||||
return " == '$headerValue'"
|
||||
}
|
||||
private String convertHeaderComparison(Object headerValue) {
|
||||
return " == '$headerValue'"
|
||||
}
|
||||
|
||||
private String convertHeaderComparison(Pattern headerValue) {
|
||||
return "==~ java.util.regex.Pattern.compile('$headerValue')"
|
||||
}
|
||||
private String convertHeaderComparison(Pattern headerValue) {
|
||||
return "==~ java.util.regex.Pattern.compile('$headerValue')"
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResponseAsString() {
|
||||
return 'response.body.asString()'
|
||||
}
|
||||
@Override
|
||||
protected String getResponseAsString() {
|
||||
return 'response.body.asString()'
|
||||
}
|
||||
|
||||
protected String buildUrl(Request request) {
|
||||
if (request.url)
|
||||
return getTestSideValue(request.url.serverValue)
|
||||
if (request.urlPath)
|
||||
return getTestSideValue(buildUrlFromUrlPath(request.urlPath))
|
||||
throw new IllegalStateException("URL is not set!")
|
||||
}
|
||||
protected String buildUrl(Request request) {
|
||||
if (request.url)
|
||||
return getTestSideValue(request.url.serverValue)
|
||||
if (request.urlPath)
|
||||
return getTestSideValue(buildUrlFromUrlPath(request.urlPath))
|
||||
throw new IllegalStateException("URL is not set!")
|
||||
}
|
||||
|
||||
@TypeChecked(TypeCheckingMode.SKIP)
|
||||
protected String buildUrlFromUrlPath(UrlPath urlPath) {
|
||||
String params = urlPath.queryParameters.parameters
|
||||
.findAll(this.&allowedQueryParameter)
|
||||
.inject([] as List<String>) { List<String> result, QueryParameter param ->
|
||||
result << "${param.name}=${resolveParamValue(param).toString()}"
|
||||
}
|
||||
.join('&')
|
||||
return "$urlPath.serverValue?$params"
|
||||
}
|
||||
@TypeChecked(TypeCheckingMode.SKIP)
|
||||
protected String buildUrlFromUrlPath(UrlPath urlPath) {
|
||||
String params = urlPath.queryParameters.parameters
|
||||
.findAll(this.&allowedQueryParameter)
|
||||
.inject([] as List<String>) { List<String> result, QueryParameter param ->
|
||||
result << "${param.name}=${resolveParamValue(param).toString()}"
|
||||
}
|
||||
.join('&')
|
||||
return "$urlPath.serverValue?$params"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@ import groovy.transform.CompileStatic
|
||||
@CompileStatic
|
||||
class ExecutionProperty {
|
||||
|
||||
private static final String PLACEHOLDER_VALUE = '\\$it'
|
||||
private static final String PLACEHOLDER_VALUE = '\\$it'
|
||||
|
||||
final String executionCommand
|
||||
final String executionCommand
|
||||
|
||||
ExecutionProperty(String executionCommand) {
|
||||
this.executionCommand = executionCommand
|
||||
}
|
||||
ExecutionProperty(String executionCommand) {
|
||||
this.executionCommand = executionCommand
|
||||
}
|
||||
|
||||
String insertValue(String valueToInsert) {
|
||||
return executionCommand.replaceAll(PLACEHOLDER_VALUE, valueToInsert)
|
||||
}
|
||||
String insertValue(String valueToInsert) {
|
||||
return executionCommand.replaceAll(PLACEHOLDER_VALUE, valueToInsert)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ import groovy.transform.ToString
|
||||
@CompileStatic
|
||||
class Header extends DslProperty {
|
||||
|
||||
String name
|
||||
String name
|
||||
|
||||
Header(String name, DslProperty dslProperty) {
|
||||
super(dslProperty.clientValue, dslProperty.serverValue)
|
||||
this.name = name
|
||||
}
|
||||
Header(String name, DslProperty dslProperty) {
|
||||
super(dslProperty.clientValue, dslProperty.serverValue)
|
||||
this.name = name
|
||||
}
|
||||
|
||||
Header(String name, Object value) {
|
||||
super(value)
|
||||
this.name = name
|
||||
}
|
||||
Header(String name, Object value) {
|
||||
super(value)
|
||||
this.name = name
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,24 +11,24 @@ import static io.codearte.accurest.util.ValidateUtils.validateServerValueIsAvail
|
||||
@CompileStatic
|
||||
class QueryParameter extends DslProperty {
|
||||
|
||||
String name
|
||||
String name
|
||||
|
||||
QueryParameter(String name, DslProperty dslProperty) {
|
||||
super(dslProperty.clientValue, dslProperty.serverValue)
|
||||
validateServerValueIsAvailable(dslProperty.serverValue, "Query parameter '$name'")
|
||||
this.name = name
|
||||
}
|
||||
QueryParameter(String name, DslProperty dslProperty) {
|
||||
super(dslProperty.clientValue, dslProperty.serverValue)
|
||||
validateServerValueIsAvailable(dslProperty.serverValue, "Query parameter '$name'")
|
||||
this.name = name
|
||||
}
|
||||
|
||||
QueryParameter(String name, MatchingStrategy matchingStrategy) {
|
||||
super(matchingStrategy)
|
||||
validateServerValueIsAvailable(matchingStrategy, "Query parameter '$name'")
|
||||
this.name = name
|
||||
}
|
||||
QueryParameter(String name, MatchingStrategy matchingStrategy) {
|
||||
super(matchingStrategy)
|
||||
validateServerValueIsAvailable(matchingStrategy, "Query parameter '$name'")
|
||||
this.name = name
|
||||
}
|
||||
|
||||
QueryParameter(String name, Object value) {
|
||||
super(value)
|
||||
validateServerValueIsAvailable(value, "Query parameter '$name'")
|
||||
this.name = name
|
||||
}
|
||||
QueryParameter(String name, Object value) {
|
||||
super(value)
|
||||
validateServerValueIsAvailable(value, "Query parameter '$name'")
|
||||
this.name = name
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@ import groovy.transform.TypeChecked
|
||||
@TypeChecked
|
||||
class QueryParameters {
|
||||
|
||||
List<QueryParameter> parameters = []
|
||||
List<QueryParameter> parameters = []
|
||||
|
||||
void parameter(Map<String, Object> singleParameter) {
|
||||
Map.Entry<String, Object> first = singleParameter.entrySet().first()
|
||||
parameters << new QueryParameter(first?.key, first?.value)
|
||||
}
|
||||
void parameter(Map<String, Object> singleParameter) {
|
||||
Map.Entry<String, Object> first = singleParameter.entrySet().first()
|
||||
parameters << new QueryParameter(first?.key, first?.value)
|
||||
}
|
||||
|
||||
void parameter(String parameterName, Object parameterValue) {
|
||||
parameters << new QueryParameter(parameterName, parameterValue)
|
||||
}
|
||||
void parameter(String parameterName, Object parameterValue) {
|
||||
parameters << new QueryParameter(parameterName, parameterValue)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ import groovy.transform.ToString;
|
||||
@CompileStatic
|
||||
class UrlPath extends Url {
|
||||
|
||||
UrlPath(String path) {
|
||||
super(path)
|
||||
}
|
||||
UrlPath(String path) {
|
||||
super(path)
|
||||
}
|
||||
|
||||
UrlPath(DslProperty path) {
|
||||
super(path)
|
||||
}
|
||||
UrlPath(DslProperty path) {
|
||||
super(path)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package io.codearte.accurest.util
|
||||
|
||||
enum ContentType {
|
||||
|
||||
JSON("application/json"),
|
||||
XML("application/xml"),
|
||||
UNKNOWN("application/octet-stream")
|
||||
JSON("application/json"),
|
||||
XML("application/xml"),
|
||||
UNKNOWN("application/octet-stream")
|
||||
|
||||
final String mimeType
|
||||
final String mimeType
|
||||
|
||||
ContentType(String mimeType) {
|
||||
this.mimeType = mimeType
|
||||
}
|
||||
ContentType(String mimeType) {
|
||||
this.mimeType = mimeType
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,35 +12,35 @@ import static io.codearte.accurest.dsl.internal.MatchingStrategy.Type.EQUAL_TO
|
||||
@TypeChecked
|
||||
class ValidateUtils {
|
||||
|
||||
static Object validateServerValueIsAvailable(Object value) {
|
||||
validateServerValueIsAvailable(value, "Server value")
|
||||
return value
|
||||
}
|
||||
static Object validateServerValueIsAvailable(Object value) {
|
||||
validateServerValueIsAvailable(value, "Server value")
|
||||
return value
|
||||
}
|
||||
|
||||
static Object validateServerValueIsAvailable(Object value, String msg) {
|
||||
validateServerValue(value, msg)
|
||||
return value
|
||||
}
|
||||
static Object validateServerValueIsAvailable(Object value, String msg) {
|
||||
validateServerValue(value, msg)
|
||||
return value
|
||||
}
|
||||
|
||||
static void validateServerValue(Pattern pattern, String msg) {
|
||||
throw new IllegalStateException("$msg can't be a pattern for the server side")
|
||||
}
|
||||
static void validateServerValue(Pattern pattern, String msg) {
|
||||
throw new IllegalStateException("$msg can't be a pattern for the server side")
|
||||
}
|
||||
|
||||
static List ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE = [EQUAL_TO, ABSENT]
|
||||
static List ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE = [EQUAL_TO, ABSENT]
|
||||
|
||||
static void validateServerValue(MatchingStrategy matchingStrategy, String msg) {
|
||||
if (!ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE.contains(matchingStrategy.type)) {
|
||||
throw new IllegalStateException("$msg can't be of a matching type: $matchingStrategy.type for the server side")
|
||||
}
|
||||
validateServerValue(matchingStrategy.serverValue, msg)
|
||||
}
|
||||
static void validateServerValue(MatchingStrategy matchingStrategy, String msg) {
|
||||
if (!ALLOWED_MATCHING_TYPES_ON_SERVER_SIDE.contains(matchingStrategy.type)) {
|
||||
throw new IllegalStateException("$msg can't be of a matching type: $matchingStrategy.type for the server side")
|
||||
}
|
||||
validateServerValue(matchingStrategy.serverValue, msg)
|
||||
}
|
||||
|
||||
static void validateServerValue(DslProperty value, String msg) {
|
||||
validateServerValue(value.serverValue, msg)
|
||||
}
|
||||
static void validateServerValue(DslProperty value, String msg) {
|
||||
validateServerValue(value.serverValue, msg)
|
||||
}
|
||||
|
||||
static void validateServerValue(Object value, String msg) {
|
||||
// OK
|
||||
}
|
||||
static void validateServerValue(Object value, String msg) {
|
||||
// OK
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc
|
||||
response {
|
||||
status 200
|
||||
body """{
|
||||
"property1": "a",
|
||||
"property2": "b"
|
||||
"property1": "a",
|
||||
"property2": "b"
|
||||
}"""
|
||||
}
|
||||
}
|
||||
@@ -126,10 +126,10 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc
|
||||
status 200
|
||||
body """[
|
||||
{
|
||||
"property1": "a"
|
||||
"property1": "a"
|
||||
},
|
||||
{
|
||||
"property2": "b"
|
||||
"property2": "b"
|
||||
}]"""
|
||||
}
|
||||
}
|
||||
@@ -154,10 +154,10 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc
|
||||
response {
|
||||
status 200
|
||||
body """{
|
||||
"property1": [
|
||||
{ "property2": "test1"},
|
||||
{ "property3": "test2"}
|
||||
]
|
||||
"property1": [
|
||||
{ "property2": "test1"},
|
||||
{ "property3": "test2"}
|
||||
]
|
||||
}"""
|
||||
}
|
||||
}
|
||||
@@ -183,8 +183,8 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc
|
||||
status 200
|
||||
body '''\
|
||||
{
|
||||
"property1": "a",
|
||||
"property2": {"property3": "b"}
|
||||
"property1": "a",
|
||||
"property2": {"property3": "b"}
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
response {
|
||||
status 200
|
||||
body """{
|
||||
"property1": "a",
|
||||
"property2": "b"
|
||||
"property1": "a",
|
||||
"property2": "b"
|
||||
}"""
|
||||
}
|
||||
}
|
||||
@@ -129,10 +129,10 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
status 200
|
||||
body """[
|
||||
{
|
||||
"property1": "a"
|
||||
"property1": "a"
|
||||
},
|
||||
{
|
||||
"property2": "b"
|
||||
"property2": "b"
|
||||
}]"""
|
||||
}
|
||||
}
|
||||
@@ -157,10 +157,10 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
response {
|
||||
status 200
|
||||
body """{
|
||||
"property1": [
|
||||
{ "property2": "test1"},
|
||||
{ "property3": "test2"}
|
||||
]
|
||||
"property1": [
|
||||
{ "property2": "test1"},
|
||||
{ "property3": "test2"}
|
||||
]
|
||||
}"""
|
||||
}
|
||||
}
|
||||
@@ -186,8 +186,8 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu
|
||||
status 200
|
||||
body '''\
|
||||
{
|
||||
"property1": "a",
|
||||
"property2": {"property3": "b"}
|
||||
"property1": "a",
|
||||
"property2": {"property3": "b"}
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
@@ -85,17 +85,17 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual('''
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/ingredients",
|
||||
"method" : "GET",
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "application/vnd.pl.devoxx.aggregatr.v1+json"
|
||||
}
|
||||
}
|
||||
"url" : "/ingredients",
|
||||
"method" : "GET",
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "application/vnd.pl.devoxx.aggregatr.v1+json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"ingredients\\":[{\\"type\\":\\"MALT\\",\\"quantity\\":100},{\\"type\\":\\"WATER\\",\\"quantity\\":200},{\\"type\\":\\"HOP\\",\\"quantity\\":300},{\\"type\\":\\"YIEST\\",\\"quantity\\":400}]}"
|
||||
"status" : 200,
|
||||
"body" : "{\\"ingredients\\":[{\\"type\\":\\"MALT\\",\\"quantity\\":100},{\\"type\\":\\"WATER\\",\\"quantity\\":200},{\\"type\\":\\"HOP\\",\\"quantity\\":300},{\\"type\\":\\"YIEST\\",\\"quantity\\":400}]}"
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
@@ -132,24 +132,24 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
then:
|
||||
AssertionUtil.assertThatJsonsAreEqual('''
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/x-www-form-urlencoded"
|
||||
}
|
||||
},
|
||||
"url": "/ws/payments",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "paymentType=INCOMING&transferType=BANK&amount=[0-9]{3}\\\\.[0-9]{2}&bookingDate=[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 204,
|
||||
"body": "{\\"paymentId\\":\\"4\\",\\"foundExistingPayment\\":false}"
|
||||
}
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/x-www-form-urlencoded"
|
||||
}
|
||||
},
|
||||
"url": "/ws/payments",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "paymentType=INCOMING&transferType=BANK&amount=[0-9]{3}\\\\.[0-9]{2}&bookingDate=[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 204,
|
||||
"body": "{\\"paymentId\\":\\"4\\",\\"foundExistingPayment\\":false}"
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
and:
|
||||
@@ -166,13 +166,13 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
response {
|
||||
status 200
|
||||
body("""\
|
||||
{
|
||||
"id": "${value(client('123'), server('321'))}",
|
||||
"surname": "${value(client('Kowalsky'), server('Lewandowski'))}",
|
||||
"name": "Jan",
|
||||
"created" : "${$(client('2014-02-02 12:23:43'), server('2999-09-09 01:23:45'))}"
|
||||
}
|
||||
"""
|
||||
{
|
||||
"id": "${value(client('123'), server('321'))}",
|
||||
"surname": "${value(client('Kowalsky'), server('Lewandowski'))}",
|
||||
"name": "Jan",
|
||||
"created" : "${$(client('2014-02-02 12:23:43'), server('2999-09-09 01:23:45'))}"
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header 'Content-Type': 'text/plain'
|
||||
@@ -185,15 +185,15 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET"
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET"
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"created\\":\\"2014-02-02 12:23:43\\",\\"id\\":\\"123\\",\\"name\\":\\"Jan\\",\\"surname\\":\\"Kowalsky\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
"status" : 200,
|
||||
"body" : "{\\"created\\":\\"2014-02-02 12:23:43\\",\\"id\\":\\"123\\",\\"name\\":\\"Jan\\",\\"surname\\":\\"Kowalsky\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -216,10 +216,10 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
response {
|
||||
status 200
|
||||
body("""\
|
||||
{
|
||||
"name": "Jan"
|
||||
}
|
||||
"""
|
||||
{
|
||||
"name": "Jan"
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header 'Content-Type': 'text/plain'
|
||||
@@ -232,18 +232,18 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual('''
|
||||
{
|
||||
"request" : {
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
} ]
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"name\\":\\"Jan\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
"status" : 200,
|
||||
"body" : "{\\"name\\":\\"Jan\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
}
|
||||
}
|
||||
''', wireMockStub)
|
||||
@@ -280,20 +280,20 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.created == '2014-02-02 12:23:43')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.surname == 'Kowalsky')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.id == '123')]"
|
||||
} ]
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.created == '2014-02-02 12:23:43')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.surname == 'Kowalsky')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.id == '123')]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200
|
||||
"status" : 200
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -326,19 +326,19 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/users",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "customtype/json"
|
||||
}
|
||||
}
|
||||
"url" : "/users",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.name == 'Jan')]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "customtype/json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200
|
||||
"status" : 200
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -548,10 +548,10 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
response {
|
||||
status 200
|
||||
body("""\
|
||||
{
|
||||
"name": "Jan"
|
||||
}
|
||||
"""
|
||||
{
|
||||
"name": "Jan"
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header 'Content-Type': 'text/plain'
|
||||
@@ -564,18 +564,18 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.personalId =~ /^[0-9]{11}$/)]"
|
||||
} ]
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.personalId =~ /^[0-9]{11}$/)]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"name\\":\\"Jan\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
"status" : 200,
|
||||
"body" : "{\\"name\\":\\"Jan\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -590,11 +590,11 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
method 'PUT'
|
||||
url '/fraudcheck'
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header('Content-Type', 'application/vnd.fraud.v1+json')
|
||||
@@ -619,25 +619,25 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/fraudcheck",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.loanAmount == 123.123)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.clientPesel =~ /[0-9]{10}/)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "application/vnd.fraud.v1+json"
|
||||
}
|
||||
}
|
||||
"url" : "/fraudcheck",
|
||||
"method" : "PUT",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.loanAmount == 123.123)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.clientPesel =~ /[0-9]{10}/)]"
|
||||
} ],
|
||||
"headers" : {
|
||||
"Content-Type" : {
|
||||
"equalTo" : "application/vnd.fraud.v1+json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"fraudCheckStatus\\":\\"OK\\",\\"rejectionReason\\":null}",
|
||||
"headers" : {
|
||||
"Content-Type" : "application/vnd.fraud.v1+json"
|
||||
}
|
||||
"status" : 200,
|
||||
"body" : "{\\"fraudCheckStatus\\":\\"OK\\",\\"rejectionReason\\":null}",
|
||||
"headers" : {
|
||||
"Content-Type" : "application/vnd.fraud.v1+json"
|
||||
}
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -686,20 +686,20 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
"equalTo": "email"
|
||||
},
|
||||
"sort": {
|
||||
"matches": "^[0-9]{10}$"
|
||||
},
|
||||
"search": {
|
||||
"doesNotMatch": "^/[0-9]{2}$"
|
||||
},
|
||||
"age": {
|
||||
"doesNotMatch": "^\\\\w*$"
|
||||
},
|
||||
"name": {
|
||||
"matches": "Denis.*"
|
||||
},
|
||||
"credit": {
|
||||
"absent": true
|
||||
}
|
||||
"matches": "^[0-9]{10}$"
|
||||
},
|
||||
"search": {
|
||||
"doesNotMatch": "^/[0-9]{2}$"
|
||||
},
|
||||
"age": {
|
||||
"doesNotMatch": "^\\\\w*$"
|
||||
},
|
||||
"name": {
|
||||
"matches": "Denis.*"
|
||||
},
|
||||
"credit": {
|
||||
"absent": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
@@ -967,32 +967,32 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.propertyName =~ /[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.providerValue == 'Test')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.providerValue == 'Test')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.lastName =~ /.*/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.propertyName =~ /[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.birthDate =~ /[0-9]{4}-[0-9]{2}-[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.personalId =~ /[0-9]{11}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.firstName =~ /.*/)]"
|
||||
} ]
|
||||
"urlPattern" : "/[0-9]{2}",
|
||||
"method" : "GET",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.propertyName =~ /[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.providerValue == 'Test')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.providerValue == 'Test')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.lastName =~ /.*/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$.errors[*][?(@.propertyName =~ /[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.birthDate =~ /[0-9]{4}-[0-9]{2}-[0-9]{2}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.personalId =~ /[0-9]{11}/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.firstName =~ /.*/)]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"name\\":\\"Jan\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
"status" : 200,
|
||||
"body" : "{\\"name\\":\\"Jan\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "text/plain"
|
||||
}
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
@@ -1031,28 +1031,28 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"url" : "/reissue-payment-order",
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.loanNumber == '999997001')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.username =~ /.*/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.amount =~ /[0-9.]+/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.cardId == 1)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.currency == 'DKK')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.applicationName =~ /.*/)]"
|
||||
} ]
|
||||
"url" : "/reissue-payment-order",
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.loanNumber == '999997001')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.username =~ /.*/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.amount =~ /[0-9.]+/)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.cardId == 1)]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.currency == 'DKK')]"
|
||||
}, {
|
||||
"matchesJsonPath" : "$[?(@.applicationName =~ /.*/)]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200,
|
||||
"body" : "{\\"status\\":\\"OK\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
}
|
||||
"status" : 200,
|
||||
"body" : "{\\"status\\":\\"OK\\"}",
|
||||
"headers" : {
|
||||
"Content-Type" : "application/json"
|
||||
}
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
@@ -1075,50 +1075,50 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
then:
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "test",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"equalTo": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 406
|
||||
}
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "test",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"equalTo": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 406
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
}
|
||||
|
||||
def "should generate stub with priority"() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
priority 9
|
||||
request {
|
||||
method('POST')
|
||||
url("test")
|
||||
}
|
||||
response {
|
||||
status 406
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
def "should generate stub with priority"() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
priority 9
|
||||
request {
|
||||
method('POST')
|
||||
url("test")
|
||||
}
|
||||
response {
|
||||
status 406
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"priority": 9,
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "test"
|
||||
},
|
||||
"response": {
|
||||
"status": 406
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
}
|
||||
{
|
||||
"priority": 9,
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "test"
|
||||
},
|
||||
"response": {
|
||||
"status": 406
|
||||
}
|
||||
}
|
||||
'''), json)
|
||||
}
|
||||
|
||||
@Issue("#127")
|
||||
def 'should use "test" as an alias for "server"'() {
|
||||
@@ -1140,16 +1140,16 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
|
||||
AssertionUtil.assertThatJsonsAreEqual(('''
|
||||
{
|
||||
"request" : {
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.property == 'value')]"
|
||||
} ]
|
||||
"method" : "POST",
|
||||
"bodyPatterns" : [ {
|
||||
"matchesJsonPath" : "$[?(@.property == 'value')]"
|
||||
} ]
|
||||
},
|
||||
"response" : {
|
||||
"status" : 200
|
||||
"status" : 200
|
||||
}
|
||||
}
|
||||
'''), wireMockStub)
|
||||
'''), wireMockStub)
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import java.util.regex.Pattern
|
||||
|
||||
trait WireMockStubVerifier {
|
||||
|
||||
void stubMappingIsValidWireMockStub(String mappingDefinition) {
|
||||
StubMapping stubMapping = StubMapping.buildFrom(mappingDefinition)
|
||||
stubMapping.request.bodyPatterns.findAll { it.matches }.every {
|
||||
Pattern.compile(it.matches)
|
||||
}
|
||||
assert !mappingDefinition.contains('DslProperty')
|
||||
}
|
||||
void stubMappingIsValidWireMockStub(String mappingDefinition) {
|
||||
StubMapping stubMapping = StubMapping.buildFrom(mappingDefinition)
|
||||
stubMapping.request.bodyPatterns.findAll { it.matches }.every {
|
||||
Pattern.compile(it.matches)
|
||||
}
|
||||
assert !mappingDefinition.contains('DslProperty')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,16 +4,16 @@ import spock.lang.Specification
|
||||
|
||||
class ExecutionPropertySpec extends Specification {
|
||||
|
||||
def 'should insert passed value in place of $it placeholder'() {
|
||||
given:
|
||||
String commandToExecute = 'commandToExecute($it)'
|
||||
ExecutionProperty executionProperty = new ExecutionProperty(commandToExecute)
|
||||
and:
|
||||
String valueToInsert = 'someObject.itsValue'
|
||||
when:
|
||||
String commandWithInsertedValue = executionProperty.insertValue(valueToInsert)
|
||||
then:
|
||||
'commandToExecute(someObject.itsValue)' == commandWithInsertedValue
|
||||
}
|
||||
def 'should insert passed value in place of $it placeholder'() {
|
||||
given:
|
||||
String commandToExecute = 'commandToExecute($it)'
|
||||
ExecutionProperty executionProperty = new ExecutionProperty(commandToExecute)
|
||||
and:
|
||||
String valueToInsert = 'someObject.itsValue'
|
||||
when:
|
||||
String commandWithInsertedValue = executionProperty.insertValue(valueToInsert)
|
||||
then:
|
||||
'commandToExecute(someObject.itsValue)' == commandWithInsertedValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,23 +5,23 @@ io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body("""\
|
||||
{
|
||||
"name": "Jan",
|
||||
"id": "${value(client('abc'), server('def'))}",
|
||||
}
|
||||
"""
|
||||
{
|
||||
"name": "Jan",
|
||||
"id": "${value(client('abc'), server('def'))}",
|
||||
}
|
||||
"""
|
||||
)
|
||||
url $(client('/[0-9]{2}'), server('/12'))
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body("""\
|
||||
{
|
||||
"name": "Jan",
|
||||
"id": "${value(client('123'), server('321'))}",
|
||||
{
|
||||
"name": "Jan",
|
||||
"id": "${value(client('123'), server('321'))}",
|
||||
"surname": "${value(client('Kowalsky'), server('$checkIfSurnameValid($value)'))}"
|
||||
}
|
||||
"""
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header 'Content-Type': 'text/plain'
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'groovy'
|
||||
apply plugin: 'accurest'
|
||||
|
||||
ext {
|
||||
contractsDir = file("${project.rootDir}/repository/mappings/com/ofg/twitter-places-analyzer")
|
||||
wireMockStubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/")
|
||||
wireMockStubsOutputDir = new File(wireMockStubsOutputDirRoot, 'repository/mappings/')
|
||||
contractsDir = file("${project.rootDir}/repository/mappings/com/ofg/twitter-places-analyzer")
|
||||
wireMockStubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/")
|
||||
wireMockStubsOutputDir = new File(wireMockStubsOutputDirRoot, 'repository/mappings/')
|
||||
}
|
||||
|
||||
configurations {
|
||||
all {
|
||||
resolutionStrategy {
|
||||
eachDependency { DependencyResolveDetails details ->
|
||||
// To prevent an accidental usage of groovy-all.jar and groovy.jar in different versions
|
||||
// all modularized Groovy jars are replaced with groovy-all.jar by default.
|
||||
if (details.requested.group == 'org.codehaus.groovy' && details.requested.name != "groovy-all") {
|
||||
details.useTarget("org.codehaus.groovy:groovy-all:${details.requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
all {
|
||||
resolutionStrategy {
|
||||
eachDependency { DependencyResolveDetails details ->
|
||||
// To prevent an accidental usage of groovy-all.jar and groovy.jar in different versions
|
||||
// all modularized Groovy jars are replaced with groovy-all.jar by default.
|
||||
if (details.requested.group == 'org.codehaus.groovy' && details.requested.name != "groovy-all") {
|
||||
details.useTarget("org.codehaus.groovy:groovy-all:${details.requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework:spring-web:$springVersion"
|
||||
compile "org.springframework:spring-context-support:$springVersion"
|
||||
compile "org.codehaus.groovy:groovy-all:2.4.1"
|
||||
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
|
||||
compile "org.codehaus.jackson:jackson-mapper-asl:$jacksonMapper"
|
||||
compile "org.codehaus.jackson:jackson-core-asl:$jacksonMapper"
|
||||
compile 'com.jayway.jsonpath:json-path-assert:1.2.0'
|
||||
compile "org.springframework:spring-web:$springVersion"
|
||||
compile "org.springframework:spring-context-support:$springVersion"
|
||||
compile "org.codehaus.groovy:groovy-all:2.4.1"
|
||||
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
|
||||
compile "org.codehaus.jackson:jackson-mapper-asl:$jacksonMapper"
|
||||
compile "org.codehaus.jackson:jackson-core-asl:$jacksonMapper"
|
||||
compile 'com.jayway.jsonpath:json-path-assert:1.2.0'
|
||||
|
||||
testCompile('com.github.tomakehurst:wiremock:1.53') {
|
||||
exclude group: 'org.mortbay.jetty', module: 'servlet-api'
|
||||
}
|
||||
testCompile "org.spockframework:spock-spring:0.7-groovy-2.0"
|
||||
testCompile "com.jayway.restassured:rest-assured:$restAssuredVersion"
|
||||
testCompile "com.jayway.restassured:spring-mock-mvc:$restAssuredVersion"
|
||||
testCompile "javax.servlet:javax.servlet-api:3.0.1" //provided
|
||||
testCompile "ch.qos.logback:logback-classic:1.1.2"
|
||||
testCompile('com.github.tomakehurst:wiremock:1.53') {
|
||||
exclude group: 'org.mortbay.jetty', module: 'servlet-api'
|
||||
}
|
||||
testCompile "org.spockframework:spock-spring:0.7-groovy-2.0"
|
||||
testCompile "com.jayway.restassured:rest-assured:$restAssuredVersion"
|
||||
testCompile "com.jayway.restassured:spring-mock-mvc:$restAssuredVersion"
|
||||
testCompile "javax.servlet:javax.servlet-api:3.0.1" //provided
|
||||
testCompile "ch.qos.logback:logback-classic:1.1.2"
|
||||
}
|
||||
|
||||
accurest {
|
||||
baseClassForTests = 'com.ofg.twitter.places.BaseMockMvcSpec'
|
||||
basePackageForTests = 'accurest'
|
||||
contractsDslDir = contractsDir
|
||||
// generatedTestSourcesDir = file("${project.rootDir}/src/test/groovy/")
|
||||
stubsOutputDir = wireMockStubsOutputDir
|
||||
baseClassForTests = 'com.ofg.twitter.places.BaseMockMvcSpec'
|
||||
basePackageForTests = 'accurest'
|
||||
contractsDslDir = contractsDir
|
||||
// generatedTestSourcesDir = file("${project.rootDir}/src/test/groovy/")
|
||||
stubsOutputDir = wireMockStubsOutputDir
|
||||
}
|
||||
|
||||
//TODO: Put it into the plugin
|
||||
task createWireMockStubsOutputDir << {
|
||||
wireMockStubsOutputDir.mkdirs()
|
||||
wireMockStubsOutputDir.mkdirs()
|
||||
}
|
||||
|
||||
generateWireMockClientStubs.dependsOn { createWireMockStubsOutputDir }
|
||||
generateAccurest.dependsOn generateWireMockClientStubs
|
||||
|
||||
wrapper {
|
||||
gradleVersion '2.2.1'
|
||||
gradleVersion '2.2.1'
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
priority 2
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/api/12'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body '''\
|
||||
[{
|
||||
"text": "Gonna see you at Warsaw"
|
||||
}]
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/api/12'
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body '''\
|
||||
[{
|
||||
"text": "Gonna see you at Warsaw"
|
||||
}]
|
||||
'''
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method 'PUT'
|
||||
url $(client(regex('^/api/[0-9]{2}$')), server('/api/12'))
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body '''\
|
||||
[{
|
||||
"text": "Gonna see you at Warsaw"
|
||||
}]
|
||||
request {
|
||||
method 'PUT'
|
||||
url $(client(regex('^/api/[0-9]{2}$')), server('/api/12'))
|
||||
headers {
|
||||
header 'Content-Type': 'application/json'
|
||||
}
|
||||
body '''\
|
||||
[{
|
||||
"text": "Gonna see you at Warsaw"
|
||||
}]
|
||||
'''
|
||||
}
|
||||
response {
|
||||
body (
|
||||
path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))),
|
||||
correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)')))
|
||||
)
|
||||
status 200
|
||||
}
|
||||
}
|
||||
response {
|
||||
body (
|
||||
path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))),
|
||||
correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)')))
|
||||
)
|
||||
status 200
|
||||
}
|
||||
}
|
||||
@@ -16,21 +16,21 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT
|
||||
@TypeChecked
|
||||
class PairIdController {
|
||||
|
||||
@RequestMapping(
|
||||
value = '{pairId}',
|
||||
method = PUT,
|
||||
consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
String getPlacesFromTweets(@PathVariable long pairId, @RequestBody List<com.ofg.twitter.place.Tweet> tweets) {
|
||||
log.info("Inside PairIdController, doing very important logic")
|
||||
if (tweets?.text != ["Gonna see you at Warsaw"]) {
|
||||
throw new IllegalArgumentException("Wrong text in tweet: ${tweets?.text}")
|
||||
}
|
||||
return """
|
||||
{
|
||||
"path" : "/api/$pairId",
|
||||
"correlationId" : 123456
|
||||
}
|
||||
"""
|
||||
}
|
||||
@RequestMapping(
|
||||
value = '{pairId}',
|
||||
method = PUT,
|
||||
consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
String getPlacesFromTweets(@PathVariable long pairId, @RequestBody List<com.ofg.twitter.place.Tweet> tweets) {
|
||||
log.info("Inside PairIdController, doing very important logic")
|
||||
if (tweets?.text != ["Gonna see you at Warsaw"]) {
|
||||
throw new IllegalArgumentException("Wrong text in tweet: ${tweets?.text}")
|
||||
}
|
||||
return """
|
||||
{
|
||||
"path" : "/api/$pairId",
|
||||
"correlationId" : 123456
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.ofg.twitter.place;
|
||||
|
||||
public class Tweet {
|
||||
private String text;
|
||||
private String text;
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
class AcceptanceSpec extends Specification {
|
||||
|
||||
def "should have controller up and running"() {
|
||||
given:
|
||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new PairIdController()).build()
|
||||
expect:
|
||||
mockMvc.perform(put("/api/${1}").
|
||||
contentType(MediaType.APPLICATION_JSON).
|
||||
content("""[{"text":"Gonna see you at Warsaw"}]""")).
|
||||
andExpect(status().isOk())
|
||||
}
|
||||
def "should have controller up and running"() {
|
||||
given:
|
||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new PairIdController()).build()
|
||||
expect:
|
||||
mockMvc.perform(put("/api/${1}").
|
||||
contentType(MediaType.APPLICATION_JSON).
|
||||
content("""[{"text":"Gonna see you at Warsaw"}]""")).
|
||||
andExpect(status().isOk())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import spock.lang.Specification
|
||||
|
||||
abstract class BaseMockMvcSpec extends Specification {
|
||||
|
||||
def setup() {
|
||||
RestAssuredMockMvc.standaloneSetup(new PairIdController())
|
||||
}
|
||||
def setup() {
|
||||
RestAssuredMockMvc.standaloneSetup(new PairIdController())
|
||||
}
|
||||
|
||||
void isProperCorrelationId(Integer correlationId) {
|
||||
assert correlationId == 123456
|
||||
}
|
||||
void isProperCorrelationId(Integer correlationId) {
|
||||
assert correlationId == 123456
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method """PUT"""
|
||||
url """/fraudcheck"""
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":99999}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header("""Content-Type""", """application/vnd.fraud.v1+json""")
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body( """{
|
||||
"fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}",
|
||||
"rejectionReason": "Amount too high"
|
||||
request {
|
||||
method """PUT"""
|
||||
url """/fraudcheck"""
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":99999}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header("""Content-Type""", """application/vnd.fraud.v1+json""")
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body( """{
|
||||
"fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}",
|
||||
"rejectionReason": "Amount too high"
|
||||
}""")
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/fraudcheck'
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header('Content-Type', 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
fraudCheckStatus: "OK",
|
||||
rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/fraudcheck'
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header('Content-Type', 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
fraudCheckStatus: "OK",
|
||||
rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import java.util.Set;
|
||||
|
||||
public class FraudRestApplication extends javax.ws.rs.core.Application {
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Collections.<Class<?>>singleton(FraudDetectionController.class);
|
||||
}
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Collections.<Class<?>>singleton(FraudDetectionController.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
{
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "\\s*\\{\\s*\"clientPesel\"\\s*:\\s*\"?[0-9]{10}\"?\\s*,\\s*\"loanAmount\"\\s*:\\s*\"?99999\"?\\s*\\}\\s*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}"
|
||||
}
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "\\s*\\{\\s*\"clientPesel\"\\s*:\\s*\"?[0-9]{10}\"?\\s*,\\s*\"loanAmount\"\\s*:\\s*\"?99999\"?\\s*\\}\\s*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
{
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "\\s*\\{\\s*\"clientPesel\"\\s*:\\s*\"?[0-9]{10}\"?\\s*,\\s*\"loanAmount\"\\s*:\\s*\"?123.123\"?\\s*\\}\\s*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}"
|
||||
}
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "\\s*\\{\\s*\"clientPesel\"\\s*:\\s*\"?[0-9]{10}\"?\\s*,\\s*\"loanAmount\"\\s*:\\s*\"?123.123\"?\\s*\\}\\s*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}"
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,27 @@
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method """PUT"""
|
||||
url """/fraudcheck"""
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":99999}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header("""Content-Type""", """application/vnd.fraud.v1+json""")
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body( """{
|
||||
"fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}",
|
||||
"rejectionReason": "Amount too high"
|
||||
request {
|
||||
method """PUT"""
|
||||
url """/fraudcheck"""
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":99999}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header("""Content-Type""", """application/vnd.fraud.v1+json""")
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body( """{
|
||||
"fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}",
|
||||
"rejectionReason": "Amount too high"
|
||||
}""")
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
io.codearte.accurest.dsl.GroovyDsl.make {
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/fraudcheck'
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header('Content-Type', 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
fraudCheckStatus: "OK",
|
||||
rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
request {
|
||||
method 'PUT'
|
||||
url '/fraudcheck'
|
||||
body("""
|
||||
{
|
||||
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
|
||||
"loanAmount":123.123
|
||||
}
|
||||
"""
|
||||
)
|
||||
headers {
|
||||
header('Content-Type', 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
fraudCheckStatus: "OK",
|
||||
rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)')))
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': 'application/vnd.fraud.v1+json')
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
{
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"99999\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}"
|
||||
}
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"99999\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}"
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
{
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"123.123\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}"
|
||||
}
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.fraud.v1+json"
|
||||
}
|
||||
},
|
||||
"url": "/fraudcheck",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"123.123\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.fraud.v1+json"
|
||||
},
|
||||
"body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}"
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,7 @@ scmVersion {
|
||||
}
|
||||
|
||||
allprojects {
|
||||
//project.version = scmVersion.version
|
||||
project.version = '0.9.1-SNAPSHOT'
|
||||
project.version = scmVersion.version
|
||||
}
|
||||
|
||||
apply plugin: 'io.codearte.nexus-staging'
|
||||
|
||||
Reference in New Issue
Block a user