Merge branch 'master' into feature/kotlin-contract-support
This commit is contained in:
@@ -32,7 +32,7 @@ jobs:
|
||||
command: rm -rf ~/.m2/repository/org/springframework/cloud/contract && rm -rf ~/.m2/repository/com/example
|
||||
- run:
|
||||
name: "Running build"
|
||||
command: ./mvnw -s .settings.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install -U -Pdocs,fast,integration,sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
|
||||
command: ./mvnw -s .settings.xml clean install -U -Pdocs,fast,integration -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
|
||||
- run:
|
||||
name: "Aggregate test results"
|
||||
when: always
|
||||
|
||||
@@ -44,8 +44,15 @@ public class OptionalProperty implements Serializable, CanBeDynamic {
|
||||
}
|
||||
|
||||
public String value() {
|
||||
return this.value instanceof RegexProperty
|
||||
? ((RegexProperty) this.value).pattern() : this.value.toString();
|
||||
if (this.value == null) {
|
||||
return "";
|
||||
}
|
||||
else if (this.value instanceof RegexProperty) {
|
||||
return ((RegexProperty) this.value).pattern();
|
||||
}
|
||||
else {
|
||||
return this.value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
protected Pattern optionalPatternValue() {
|
||||
|
||||
@@ -34,12 +34,12 @@ interface QueryParamsResolver {
|
||||
return resolveParamValue(((OptionalProperty) value).optionalPattern());
|
||||
}
|
||||
else if (value instanceof MatchingStrategy) {
|
||||
return ((MatchingStrategy) value).getServerValue().toString();
|
||||
return resolveParamValue(((MatchingStrategy) value).getServerValue());
|
||||
}
|
||||
else if (value instanceof DslProperty) {
|
||||
return resolveParamValue(((DslProperty) value).getServerValue());
|
||||
}
|
||||
return value.toString();
|
||||
return value == null ? "null" : value.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -128,16 +128,19 @@ class ContractVerifierDslConverter implements ContractConverter<Collection<Contr
|
||||
private static Object toObject(ClassLoader cl, File rootFolder, File dsl) {
|
||||
if (isJava(dsl)) {
|
||||
try {
|
||||
return parseJavaFile(dsl)
|
||||
return parseJavaFile(cl, dsl)
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new DslParseException("Exception occurred while trying to parse the file [" + dsl + "] as a contract. Will not parse it.", ex)
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("Exception occurred while trying to parse the file [" + dsl + "] as a contract. Will not parse it.", ex)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
return groovyShell(cl, rootFolder).evaluate(dsl)
|
||||
}
|
||||
|
||||
private static Object parseJavaFile(File dsl) {
|
||||
private static Object parseJavaFile(ClassLoader cl, File dsl) {
|
||||
Constructor<?> constructor = classConstructor(dsl)
|
||||
Object newInstance = constructor.newInstance()
|
||||
if (!newInstance instanceof Supplier) {
|
||||
@@ -158,7 +161,7 @@ class ContractVerifierDslConverter implements ContractConverter<Collection<Contr
|
||||
if (!compilationResult.wasSuccessful()) {
|
||||
throw new IllegalStateException("Exceptions occurred while trying to compile the file " + compilationResult.compilationMessages)
|
||||
}
|
||||
Class<?> clazz = compilationResult.compiledClasses.find { it.name == fqn }
|
||||
Class<?> clazz = compilationResult.compiledClasses.find { it.name == fqn}
|
||||
if (clazz == null) {
|
||||
throw new IllegalStateException("Class with name [" + fqn + "] not found")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.springframework.cloud.contract.verifier.builder
|
||||
|
||||
import org.springframework.cloud.contract.spec.internal.DslProperty
|
||||
import org.springframework.cloud.contract.spec.internal.MatchingStrategy
|
||||
import org.springframework.cloud.contract.spec.internal.OptionalProperty
|
||||
import org.springframework.cloud.contract.spec.internal.QueryParameter
|
||||
import org.springframework.cloud.contract.spec.internal.RegexProperty
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class QueryParamsResolverSpec extends Specification {
|
||||
|
||||
def 'should return serverValue for QueryParameter'() {
|
||||
given:
|
||||
Object parameter = new QueryParameter("some_param", dslProperty)
|
||||
when:
|
||||
String resolved = new QueryParamsResolver() {}.resolveParamValue(parameter)
|
||||
then:
|
||||
resolved == expected
|
||||
where:
|
||||
dslProperty | expected
|
||||
new DslProperty<String>("client", "server") | "server"
|
||||
new DslProperty<String>(null, "server") | "server"
|
||||
new DslProperty<String>("client", null) | "null"
|
||||
new DslProperty<String>(null, null) | "null"
|
||||
}
|
||||
|
||||
def 'should return optionalPattern for OptionalProperty'() {
|
||||
given:
|
||||
Object parameter = new OptionalProperty(value)
|
||||
when:
|
||||
String resolved = new QueryParamsResolver() {}.resolveParamValue(parameter)
|
||||
then:
|
||||
resolved == expected
|
||||
where:
|
||||
value | expected
|
||||
"server" | "(server)?"
|
||||
null | "()?"
|
||||
new RegexProperty(Pattern.compile(".*")) | "(.*)?"
|
||||
new RegexProperty(null, Pattern.compile(".*")) | "(.*)?"
|
||||
new RegexProperty(Pattern.compile(".*"), null) | "(.*)?"
|
||||
new RegexProperty("", Pattern.compile(".*")) | "(.*)?"
|
||||
new RegexProperty(Pattern.compile(".*"), "") | "(.*)?"
|
||||
}
|
||||
|
||||
def 'should return serverValue for MatchingStrategy'() {
|
||||
given:
|
||||
Object parameter = new MatchingStrategy(value, MatchingStrategy.Type.EQUAL_TO)
|
||||
when:
|
||||
String resolved = new QueryParamsResolver() {}.resolveParamValue(parameter)
|
||||
then:
|
||||
resolved == expected
|
||||
where:
|
||||
value | expected
|
||||
"server" | "server"
|
||||
null | "null"
|
||||
new DslProperty<String>("client", "server") | "server"
|
||||
new DslProperty<String>(null, "server") | "server"
|
||||
new DslProperty<String>("client", null) | "null"
|
||||
new DslProperty<String>(null, null) | "null"
|
||||
}
|
||||
|
||||
def 'should return serverValue for DslProperty'() {
|
||||
when:
|
||||
String resolved = new QueryParamsResolver() {}.resolveParamValue(parameter)
|
||||
then:
|
||||
resolved == expected
|
||||
where:
|
||||
parameter | expected
|
||||
new DslProperty<String>("client", "server") | "server"
|
||||
new DslProperty<String>(null, "server") | "server"
|
||||
new DslProperty<String>("client", null) | "null"
|
||||
new DslProperty<String>(null, null) | "null"
|
||||
}
|
||||
|
||||
def 'should return \"null\" for null'() {
|
||||
when:
|
||||
String resolved = new QueryParamsResolver() {}.resolveParamValue(null)
|
||||
then:
|
||||
resolved == "null"
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user