PR code review comments

This commit is contained in:
Denis Stepanov
2015-06-08 13:29:21 +02:00
parent 1eb035189e
commit cd226a009d
5 changed files with 24 additions and 29 deletions

View File

@@ -34,42 +34,43 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy {
}
private Map<String, Object> appendUrl(ClientRequest clientRequest) {
def urlPath = clientRequest?.urlPath?.clientValue
Object urlPath = clientRequest?.urlPath?.clientValue
if (urlPath) {
return [urlPath: urlPath]
}
def url = clientRequest?.url?.clientValue
Object url = clientRequest?.url?.clientValue
return url instanceof Pattern ? [urlPattern: url.pattern()] : [url: url]
}
private Map<String, Object> appendQueryParameters(ClientRequest clientRequest) {
def queryParameters = clientRequest?.urlPath?.queryParameters ?: clientRequest?.url?.queryParameters
QueryParameters queryParameters = clientRequest?.urlPath?.queryParameters ?: clientRequest?.url?.queryParameters
return queryParameters && !queryParameters.parameters.isEmpty() ?
[queryParameters: buildUrlPathQueryParameters(queryParameters)] : [:]
}
private Map buildUrlPathQueryParameters(QueryParameters queryParameters) {
private Map<String, Object> buildUrlPathQueryParameters(QueryParameters queryParameters) {
return queryParameters.parameters.collectEntries { QueryParameter param ->
parseQueryParameter(param.name, param.clientValue)
}
}
protected Map parseQueryParameter(String name, MatchingStrategy matchingStrategy) {
protected Map<String, Object> parseQueryParameter(String name, MatchingStrategy matchingStrategy) {
return buildQueryParameter(name, matchingStrategy.clientValue, matchingStrategy.type)
}
protected Map parseQueryParameter(String name, Object value) {
protected Map<String, Object> parseQueryParameter(String name, Object value) {
return buildQueryParameter(name, value, MatchingStrategy.Type.EQUAL_TO)
}
protected Map parseQueryParameter(String name, Pattern pattern) {
protected Map<String, Object> parseQueryParameter(String name, Pattern pattern) {
return buildQueryParameter(name, pattern.pattern(), MatchingStrategy.Type.MATCHING)
}
private Map buildQueryParameter(String name, Object value, MatchingStrategy.Type type) {
if (value instanceof Pattern) {
value = value.pattern()
}
private Map<String, Object> buildQueryParameter(String name, Pattern pattern, MatchingStrategy.Type type) {
return buildQueryParameter(name, pattern.pattern(), type)
}
private Map<String, Object> buildQueryParameter(String name, Object value, MatchingStrategy.Type type) {
return [(name): [(type.name) : value]]
}

View File

@@ -7,7 +7,7 @@ import groovy.transform.ToString;
@EqualsAndHashCode(includeFields = true)
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true)
@CompileStatic
public class MatchingStrategy extends DslProperty {
class MatchingStrategy extends DslProperty {
Type type

View File

@@ -7,7 +7,7 @@ import groovy.transform.ToString;
@EqualsAndHashCode(includeFields = true)
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true)
@CompileStatic
public class QueryParameter extends DslProperty {
class QueryParameter extends DslProperty {
String name

View File

@@ -7,39 +7,33 @@ import groovy.transform.TypeChecked
@EqualsAndHashCode(includeFields = true)
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true)
@TypeChecked
public class QueryParameters {
class QueryParameters {
List<QueryParameter> parameters = []
public void parameter(Map<String, Object> singleParameter) {
void parameter(Map<String, Object> singleParameter) {
Map.Entry<String, Object> first = singleParameter.entrySet().first()
parameters << new QueryParameter(first?.key, first?.value)
}
public void parameter(String parameterName, Object parameterValue) {
void parameter(String parameterName, Object parameterValue) {
parameters << new QueryParameter(parameterName, parameterValue)
}
def equalTo(Object value) {
MatchingStrategy equalTo(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO)
}
def containing(Object value) {
MatchingStrategy containing(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.CONTAINS)
}
def matching(Object value) {
MatchingStrategy matching(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.MATCHING)
}
def notMatching(Object value) {
MatchingStrategy notMatching(Object value) {
return new MatchingStrategy(value, MatchingStrategy.Type.NOT_MATCHING)
}
void collect(Closure closure) {
parameters?.each {
parameter -> closure(parameter)
}
}
}

View File

@@ -512,15 +512,15 @@ class WiremockGroovyDslSpec extends WiremockSpec {
''')
}
def toJsonString(value) {
String toJsonString(value) {
new JsonBuilder(value).toPrettyString()
}
def parseJson(json) {
Object parseJson(json) {
new JsonSlurper().parseText(json)
}
def toWiremockClientJsonStub(groovyDsl) {
String toWiremockClientJsonStub(groovyDsl) {
new WiremockStubStrategy(groovyDsl).toWiremockClientStub()
}
}