Merge branch '1.0.x'

fixes #189
This commit is contained in:
Marcin Grzejszczak
2017-01-13 16:41:44 +01:00
2 changed files with 71 additions and 1 deletions

View File

@@ -305,9 +305,9 @@ abstract class MethodBodyBuilder {
String postProcessedMethod = postProcessJsonPathCall(method)
bb.addLine("assertThatJson(parsedJson)" + postProcessedMethod)
addColonIfRequired(bb)
bb.endBlock()
}
if (bodyMatchers?.hasMatchers()) {
bb.endBlock()
bb.addLine(addCommentSignIfRequired('and:'))
bb.startBlock()
// for the rest we'll do JsonPath matching in brute force

View File

@@ -22,6 +22,7 @@ import org.springframework.cloud.contract.verifier.config.ContractVerifierConfig
import org.springframework.cloud.contract.verifier.config.TestMode
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.SyntaxChecker
import org.springframework.util.StringUtils
import spock.lang.Issue
import spock.lang.Specification
@@ -113,6 +114,75 @@ class SingleTestGeneratorSpec extends Specification {
SPOCK | TestMode.EXPLICIT | explicitSpockClassStrings | GROOVY_ASSERTER
}
def "should build test class for #testFramework and mode #mode with two files"() {
given:
File file = tmpFolder.newFile()
file.write("""
org.springframework.cloud.contract.spec.Contract.make {
request {
method 'PUT'
url 'url1'
headers {
contentType(applicationJson())
}
}
response {
status 200
body(foo:"foo", bar:"bar")
headers {
contentType(applicationJson())
}
}
}
""")
and:
File file2 = tmpFolder.newFile()
file2.write("""
org.springframework.cloud.contract.spec.Contract.make {
request {
method 'PUT'
url 'url2'
headers {
contentType(applicationJson())
}
}
response {
status 200
body(foo:"foo", bar:"bar")
headers {
contentType(applicationJson())
}
}
}
""")
and:
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
properties.targetFramework = testFramework
ContractMetadata contract = new ContractMetadata(file.toPath(), false, 1, null)
contract.ignored >> false
and:
ContractMetadata contract2 = new ContractMetadata(file2.toPath(), false, 1, null)
contract2.ignored >> false
and:
SingleTestGenerator testGenerator = new SingleTestGenerator(properties)
when:
String clazz = testGenerator.buildClass([contract, contract2], "test", "test", 'com/foo')
then:
classStrings.each { clazz.contains(it) }
and:
asserter(clazz)
and:
textAssertion(clazz)
where:
testFramework | mode | classStrings | asserter | textAssertion
JUNIT | TestMode.MOCKMVC | mockMvcJUnitClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, "\t\t\tMockMvcRequestSpecification") == 2 }
JUNIT | TestMode.EXPLICIT | explicitJUnitClassStrings | JAVA_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, "\t\t\tMockMvcRequestSpecification") == 2 }
SPOCK | TestMode.MOCKMVC | spockClassStrings | GROOVY_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, "\t\t\tdef request") == 2 }
SPOCK | TestMode.EXPLICIT | explicitSpockClassStrings | GROOVY_ASSERTER | { String test -> StringUtils.countOccurrencesOf(test, "\t\t\tdef request") == 2 }
}
def "should build JaxRs test class for #testFramework"() {
given:
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()