Added support for Stub Runner and Pact Broker
fixes gh-191 commit 533f1d3d0e8f6dcd37677bfef555fc2ea86bc1b1 Author: Tim Ysewyn <Tim.Ysewyn@me.com> Date: Wed Mar 7 15:56:48 2018 +0100 Upgraded pact-jvm-model to 3.5.13
This commit is contained in:
@@ -21,6 +21,8 @@ import java.nio.file.Path
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import groovy.transform.PackageScope
|
||||
import org.apache.commons.logging.Log
|
||||
import org.apache.commons.logging.LogFactory
|
||||
import wiremock.com.google.common.collect.ListMultimap
|
||||
|
||||
import org.springframework.cloud.contract.spec.ContractVerifierException
|
||||
@@ -42,6 +44,7 @@ import static org.springframework.cloud.contract.verifier.util.NamesUtil.toLastD
|
||||
*/
|
||||
class TestGenerator {
|
||||
|
||||
private static final Log log = LogFactory.getLog(TestGenerator)
|
||||
private static final String DEFAULT_CLASS_PREFIX = "ContractVerifier"
|
||||
private static final String DEFAULT_TEST_PACKAGE = "org.springframework.cloud.contract.verifier.tests"
|
||||
|
||||
@@ -111,6 +114,9 @@ class TestGenerator {
|
||||
|
||||
private void processIncludedDirectory(
|
||||
final String includedDirectoryRelativePath, Collection<ContractMetadata> contracts, final String basePackageNameForClass) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Collected contracts with metadata ${contracts}")
|
||||
}
|
||||
if (contracts.size()) {
|
||||
def className = afterLast(includedDirectoryRelativePath.toString(), File.separator) + resolveNameSuffix()
|
||||
def convertedClassName = convertIllegalPackageChars(className)
|
||||
|
||||
@@ -87,7 +87,7 @@ class ContractFileScanner {
|
||||
* and try to convert via pluggable Contract Converters any possible contracts
|
||||
*/
|
||||
private void appendRecursively(File baseDir, ListMultimap<Path, ContractMetadata> result) {
|
||||
List<ContractConverter> converters = SpringFactoriesLoader.loadFactories(ContractConverter, null)
|
||||
List<ContractConverter> converters = converters()
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Found the following contract converters ${converters}")
|
||||
}
|
||||
@@ -122,13 +122,18 @@ class ContractFileScanner {
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ContractConverter> converters() {
|
||||
return SpringFactoriesLoader.loadFactories(ContractConverter, null)
|
||||
}
|
||||
|
||||
private void addContractToTestGeneration(List<ContractConverter> converters, ListMultimap<Path, ContractMetadata> result,
|
||||
File[] files, File file, int index) {
|
||||
boolean converted = false
|
||||
if (!file.isDirectory()) {
|
||||
for (ContractConverter converter : converters) {
|
||||
if (converter.isAccepted(file)) {
|
||||
addContractToTestGeneration(result, files, file, index, converter.convertFrom(file))
|
||||
Collection<Contract> contracts = tryConvert(converter, file)
|
||||
if (contracts) {
|
||||
addContractToTestGeneration(result, files, file, index, contracts)
|
||||
converted = true
|
||||
break
|
||||
}
|
||||
@@ -142,6 +147,21 @@ class ContractFileScanner {
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<Contract> tryConvert(ContractConverter converter, File file) {
|
||||
boolean accepted = converter.isAccepted(file)
|
||||
if (!accepted) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return converter.convertFrom(file)
|
||||
} catch (Exception e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Exception occurred while trying to convert the file", e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private void addContractToTestGeneration(ListMultimap<Path, ContractMetadata> result, File[] files, File file,
|
||||
int index, Collection<Contract> convertedContract) {
|
||||
Path path = file.toPath()
|
||||
@@ -154,6 +174,9 @@ class ContractFileScanner {
|
||||
files.size(), order, convertedContract)
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating a contract entry for path [" + path + "] and metadata [" + metadata + "]")
|
||||
}
|
||||
if (convertedContract) {
|
||||
|
||||
}
|
||||
result.put(parent, metadata)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ import spock.lang.Specification
|
||||
|
||||
import java.nio.file.Path
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.ContractConverter
|
||||
|
||||
/**
|
||||
* @author Jakub Kubrynski, codearte.io
|
||||
*/
|
||||
@@ -77,7 +80,27 @@ class ContractFileScannerSpec extends Specification {
|
||||
def "should find contract files with converters"() {
|
||||
given:
|
||||
File baseDir = new File(this.getClass().getResource("/directory/with/mixed").toURI())
|
||||
ContractFileScanner scanner = new ContractFileScanner(baseDir, null, null)
|
||||
ContractFileScanner scanner = new ContractFileScanner(baseDir, null, null) {
|
||||
@Override
|
||||
protected List<ContractConverter> converters() {
|
||||
return [new ContractConverter() {
|
||||
@Override
|
||||
boolean isAccepted(File file) {
|
||||
return file.name.endsWith(".json")
|
||||
}
|
||||
|
||||
@Override
|
||||
Collection<Contract> convertFrom(File file) {
|
||||
throw new RuntimeException("boom")
|
||||
}
|
||||
|
||||
@Override
|
||||
Object convertTo(Collection contract) {
|
||||
throw new RuntimeException("boom")
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
when:
|
||||
ListMultimap<Path, ContractMetadata> result = scanner.findContracts()
|
||||
then:
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"request": {
|
||||
"method": "PUT",
|
||||
"url": "/loanApplication",
|
||||
"headers": {
|
||||
"Content-Type": {
|
||||
"equalTo": "application/vnd.loanapplicationservice.v1+json"
|
||||
}
|
||||
},
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"matches": "\\{\"clientPesel\":\"1234567890\",\"loanAmount\":123.123\\}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"body": "{\"loanApplicationStatus\":\"LOAN_APPLIED\",\"loanApplicationId\":\"${123123123:$anyInt($it)}\",\"rejectionReason\":null}",
|
||||
"headers": {
|
||||
"Content-Type": "application/vnd.loanapplicationservice.v1+json"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user