Merge remote-tracking branch 'origin/master'

# Conflicts:
#	spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/util/ContentUtils.groovy
#	spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/util/ContentUtilsSpec.groovy
This commit is contained in:
Olga Maciaszek-Sharma
2019-02-13 13:27:55 +01:00
1272 changed files with 31933 additions and 20845 deletions

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-parent</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.1.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

View File

@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-tools</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.1.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-contract-converters</artifactId>

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.contract.verifier.converter
import groovy.transform.CompileStatic
import org.springframework.cloud.contract.spec.ContractVerifierException
/**

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.converter
@@ -32,6 +32,7 @@ import org.springframework.cloud.contract.verifier.file.ContractFileScannerBuild
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.NamesUtil
import org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter
/**
* Recursively converts contracts into their stub representations
*
@@ -58,11 +59,12 @@ class RecursiveFilesConverter {
}
void processFiles() {
ContractFileScanner scanner = new ContractFileScannerBuilder().baseDir(props.contractsDslDir)
.excluded(props.excludedFiles as Set)
.ignored([] as Set).included([] as Set)
.includeMatcher(props.includedContracts)
.build()
ContractFileScanner scanner = new ContractFileScannerBuilder().
baseDir(props.contractsDslDir)
.excluded(props.excludedFiles as Set)
.ignored([] as Set).included([] as Set)
.includeMatcher(props.includedContracts)
.build()
ListMultimap<Path, ContractMetadata> contracts = scanner.findContracts()
if (log.isDebugEnabled()) {
log.debug("Found the following contracts $contracts")
@@ -73,11 +75,14 @@ class RecursiveFilesConverter {
log.debug("Will create a stub for contract [${contract}]")
}
File sourceFile = contract.path.toFile()
Collection<StubGenerator> stubGenerators = contract.convertedContract ? holder.allOrDefault(new DslToWireMockClientConverter()) :
Collection<StubGenerator> stubGenerators = contract.convertedContract ? holder.
allOrDefault(new DslToWireMockClientConverter()) :
holder.converterForName(sourceFile.name)
try {
String path = sourceFile.path
if (props.isExcludeBuildFolders() && (matchesPath(path, "target") || matchesPath(path, "build"))) {
if (props.isExcludeBuildFolders()
&& (
matchesPath(path, "target") || matchesPath(path, "build"))) {
if (log.isDebugEnabled()) {
log.debug("Exclude build folder is set. Path [${path}] contains [target] or [build] in its path")
}
@@ -92,22 +97,28 @@ class RecursiveFilesConverter {
log.debug("Stub Generators [${stubGenerators}] will convert contents of [${entryKey}]")
}
stubGenerators.each { StubGenerator stubGenerator ->
Map<Contract, String> convertedContent = stubGenerator.convertContents(entryKey.last().toString(), contract)
Map<Contract, String> convertedContent = stubGenerator.
convertContents(entryKey.last().toString(), contract)
if (!convertedContent) {
return
}
convertedContent.entrySet().eachWithIndex { Map.Entry<Contract, String> content, int index ->
Contract dsl = content.key
String converted = content.value
if (converted) {
Path absoluteTargetPath = createAndReturnTargetDirectory(sourceFile)
File newJsonFile = createTargetFileWithProperName(stubGenerator, absoluteTargetPath,
sourceFile, contractsSize, index, dsl)
newJsonFile.setText(converted, StandardCharsets.UTF_8.toString())
}
}
convertedContent.entrySet().
eachWithIndex { Map.Entry<Contract, String> content, int index ->
Contract dsl = content.key
String converted = content.value
if (converted) {
Path absoluteTargetPath =
createAndReturnTargetDirectory(sourceFile)
File newJsonFile =
createTargetFileWithProperName(stubGenerator, absoluteTargetPath,
sourceFile, contractsSize, index, dsl)
newJsonFile.setText(converted, StandardCharsets.UTF_8.
toString())
}
}
}
} catch (Exception e) {
}
catch (Exception e) {
throw new ConversionContractVerifierException("Unable to make conversion of ${sourceFile.name}", e)
}
}
@@ -119,14 +130,15 @@ class RecursiveFilesConverter {
}
private Path createAndReturnTargetDirectory(File sourceFile) {
Path relativePath = Paths.get(props.contractsDslDir.toURI()).relativize(sourceFile.parentFile.toPath())
Path relativePath = Paths.get(props.contractsDslDir.toURI()).
relativize(sourceFile.parentFile.toPath())
Path absoluteTargetPath = outMappingsDir.toPath().resolve(relativePath)
Files.createDirectories(absoluteTargetPath)
return absoluteTargetPath
}
private File createTargetFileWithProperName(StubGenerator stubGenerator, Path absoluteTargetPath,
File sourceFile, int contractsSize, int index, Contract dsl) {
File sourceFile, int contractsSize, int index, Contract dsl) {
String name = generateName(dsl, contractsSize, stubGenerator, sourceFile, index)
File newJsonFile = new File(absoluteTargetPath.toFile(), name)
log.info("Creating new stub [$newJsonFile.path]")
@@ -134,13 +146,14 @@ class RecursiveFilesConverter {
}
private String generateName(Contract dsl, int contractsSize, StubGenerator converter,
File sourceFile, int index) {
File sourceFile, int index) {
String generatedName = converter.generateOutputFileNameForInput(sourceFile.name)
boolean hasDot = NamesUtil.hasDot(generatedName)
String extension = hasDot ? NamesUtil.afterLastDot(generatedName) : ""
if (dsl.name && extension) {
return "${dsl.name}.${extension}"
} else if (contractsSize == 1) {
}
else if (contractsSize == 1) {
return generatedName
}
return "${index}_${generatedName}"

View File

@@ -1,22 +1,23 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.converter
import groovy.transform.CompileStatic
import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.verifier.file.ContractMetadata
@@ -29,18 +30,18 @@ import org.springframework.cloud.contract.verifier.file.ContractMetadata
interface StubGenerator {
/**
* Returns {@code true} if the converter can handle the file to convert it into a stub.
* @return {@code true} if the converter can handle the file to convert it into a stub.
*/
boolean canHandleFileName(String fileName)
/**
* Returns the collection of converted contracts into stubs. One contract can
* @return the collection of converted contracts into stubs. One contract can
* result in multiple stubs.
*/
Map<Contract, String> convertContents(String rootName, ContractMetadata content)
/**
* Returns the name of the converted stub file. If you have multiple contracts
* @return the name of the converted stub file. If you have multiple contracts
* in a single file then a prefix will be added to the generated file. If you
* provide the {@link Contract#name} field then that field will override the
* generated file name.
@@ -50,4 +51,4 @@ interface StubGenerator {
* converter will create two files {@code 0_foo.json} and {@code 1_foo.json}
*/
String generateOutputFileNameForInput(String inputFileName)
}
}

View File

@@ -1,17 +1,34 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.converter
import groovy.transform.CompileStatic
import org.springframework.core.io.support.SpringFactoriesLoader
/**
* Retrieves file converters from the class path and operates on them.
*
*
* @author Marcin Grzejszczak
* @since 1.1.0
*/
@CompileStatic
class StubGeneratorProvider {
private final List<StubGenerator> converters = []
StubGeneratorProvider() {

View File

@@ -1,29 +1,28 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.wiremock
import groovy.transform.CompileStatic
import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubStrategy
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.NamesUtil
import java.nio.charset.StandardCharsets
/**
* Converts DSLs to WireMock stubs
*
@@ -42,13 +41,17 @@ class DslToWireMockClientConverter extends DslToWireMockConverter {
return [:]
}
if (contract.convertedContract.size() == 1) {
return [(contract.convertedContract.first()): convertASingleContract(rootName, contract, contract.convertedContract.first())]
return [(contract.convertedContract.first()):
convertASingleContract(rootName, contract, contract.convertedContract.
first())]
}
Map<Contract, String> convertedContracts = [:]
contract.convertedContract.findAll { it.request }.eachWithIndex { Contract dsl, int index ->
String name = dsl.name ? NamesUtil.convertIllegalPackageChars(dsl.name) : "${rootName}_${index}"
convertedContracts << [(dsl) : convertASingleContract(name, contract, dsl)]
}
contract.convertedContract.findAll { it.request }.
eachWithIndex { Contract dsl, int index ->
String name = dsl.name ? NamesUtil.
convertIllegalPackageChars(dsl.name) : "${rootName}_${index}"
convertedContracts << [(dsl): convertASingleContract(name, contract, dsl)]
}
return convertedContracts
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.wiremock
@@ -19,6 +19,7 @@ package org.springframework.cloud.contract.verifier.wiremock
import groovy.transform.CompileStatic
import org.springframework.cloud.contract.verifier.converter.StubGenerator
/**
* WireMock implementation of the {@link StubGenerator}
*

View File

@@ -1,32 +1,33 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.wiremock
import java.nio.charset.StandardCharsets
import groovy.io.FileType
import groovy.json.JsonOutput
import groovy.json.JsonParserType
import groovy.json.JsonSlurper
import groovy.transform.CompileDynamic
import groovy.xml.XmlUtil
import org.springframework.cloud.contract.spec.Contract
import repackaged.nl.flotsam.xeger.Xeger
import org.springframework.cloud.contract.verifier.util.ContentUtils
import java.nio.charset.StandardCharsets
import org.springframework.cloud.contract.spec.Contract
import static org.apache.commons.text.StringEscapeUtils.escapeJava
@@ -40,7 +41,7 @@ import static org.apache.commons.text.StringEscapeUtils.escapeJava
class WireMockToDslConverter {
/**
* Returns the string content of the contract
* @return the string content of the contract
*
* @param wireMockStringStub - string content of the WireMock JSON stub
*/
@@ -61,32 +62,50 @@ class WireMockToDslConverter {
request {
${request.method ? "method \"\"\"$request.method\"\"\"" : ""}
${request.url ? "url \"\"\"$request.url\"\"\"" : ""}
${urlPattern ? "url \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""}
${urlPathPattern ? "urlPath \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""}
${
urlPattern ? "url \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""
}
${
urlPathPattern ? "urlPath \$(consumer(regex('${escapeJava(urlPattern)}')), producer('${new Xeger(escapeJava(urlPattern)).generate()}'))" : ""
}
${request.urlPath ? "url \"\"\"$request.urlPath\"\"\"" : ""}
${
request.headers ? """headers {
request.headers ? """headers {
${
request.headers.collect {
def assertion = it.value
String headerName = it.key as String
def entry = assertion.entrySet().first()
"""header(\"\"\"$headerName\"\"\", ${buildHeader(entry.key, entry.value)})\n"""
}.join('')
}
request.headers.collect {
def assertion = it.value
String headerName = it.key as String
def entry = assertion.entrySet().first()
"""header(\"\"\"$headerName\"\"\", ${
buildHeader(entry.key, entry.value)
})\n"""
}.join('')
}
}
""" : ""
}
${bodyPatterns?.equalTo?.every { it } ? "body('''${bodyPatterns.equalTo[0]}''')" : ''}
${bodyPatterns?.equalToJson?.every { it } ? "body('''${bodyPatterns.equalToJson[0]}''')" : ''}
${bodyPatterns?.matches?.every { it } ? "body \$(consumer(regex('${escapeJava(bodyPatterns.matches[0])}')), producer('${new Xeger(escapeJava(bodyPatterns.matches[0])).generate()}'))" : ""}
}
${
bodyPatterns?.equalTo?.
every { it } ? "body('''${bodyPatterns.equalTo[0]}''')" : ''
}
${
bodyPatterns?.equalToJson?.
every { it } ? "body('''${bodyPatterns.equalToJson[0]}''')" : ''
}
${
bodyPatterns?.matches?.every {
it
} ? "body \$(consumer(regex('${escapeJava(bodyPatterns.matches[0])}')), producer('${new Xeger(escapeJava(bodyPatterns.matches[0])).generate()}'))" : ""
}
}
response {
${response.status ? "status $response.status" : ""}
${response.body ? "body( ${buildBody(response.body)})" : ""}
${
response.headers ? """headers {
${response.headers.collect { "header('$it.key': '${it.value}')\n" }.join('')}
${
response.headers.collect { "header('$it.key': '${it.value}')\n" }.join('')
}
}
""" : ""
}
@@ -100,19 +119,21 @@ class WireMockToDslConverter {
private String buildHeader(String method, Object value) {
switch (method) {
case 'equalTo':
return wrapWithMultilineGString(value)
default:
return "regex(${wrapWithMultilineGString(escapeJava(value as String))})"
case 'equalTo':
return wrapWithMultilineGString(value)
default:
return "regex(${wrapWithMultilineGString(escapeJava(value as String))})"
}
}
private Object buildBody(Map responseBody) {
return responseBody.entrySet().collectAll(withQuotedMapStringElements()).inject([:], appendToIterable())
return responseBody.entrySet().collectAll(withQuotedMapStringElements()).
inject([:], appendToIterable())
}
private Object buildBody(List responseBody) {
return responseBody.collectAll(withQuotedStringElements()).inject([], appendToIterable())
return responseBody.collectAll(withQuotedStringElements()).
inject([], appendToIterable())
}
private Object buildBody(Integer responseBody) {
@@ -123,11 +144,13 @@ class WireMockToDslConverter {
try {
def json = new JsonSlurper().parseText(responseBody)
return wrapWithMultilineGString(JsonOutput.prettyPrint(responseBody))
} catch (Exception jsonException) {
}
catch (Exception jsonException) {
try {
def xml = ContentUtils.getXmlSlurperWithDefaultErrorHandler().parseText(responseBody)
return wrapWithMultilineGString(XmlUtil.serialize(responseBody))
} catch (Exception xmlException) {
}
catch (Exception xmlException) {
return wrapWithMultilineGString(responseBody)
}
}
@@ -189,12 +212,17 @@ class WireMockToDslConverter {
if (!it.name.endsWith('json')) {
return
}
String dslFromWireMockStub = fromWireMockStub(it.getText(StandardCharsets.UTF_8.toString()))
String dslWrappedWithFactoryMethod = wrapWithFactoryMethod(dslFromWireMockStub)
File newGroovyFile = new File(it.parent, it.name.replaceAll('json', 'groovy'))
String dslFromWireMockStub =
fromWireMockStub(it.getText(StandardCharsets.UTF_8.toString()))
String dslWrappedWithFactoryMethod =
wrapWithFactoryMethod(dslFromWireMockStub)
File newGroovyFile = new File(it.parent, it.name.
replaceAll('json', 'groovy'))
println("Creating new groovy file [$newGroovyFile.path]")
newGroovyFile.setText(dslWrappedWithFactoryMethod, StandardCharsets.UTF_8.toString())
} catch (Exception e) {
newGroovyFile.setText(dslWrappedWithFactoryMethod, StandardCharsets.UTF_8.
toString())
}
catch (Exception e) {
System.err.println(e)
}

View File

@@ -1,3 +1,3 @@
# Stub converters
org.springframework.cloud.contract.verifier.converter.StubGenerator=\
org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter
org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.converter
@@ -52,7 +52,7 @@ class RecursiveFilesConverterSpec extends Specification {
given:
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
File originalSourceRootDirectory = new File(this.getClass()
.getResource("/converter/source").toURI())
.getResource("/converter/source").toURI())
properties.contractsDslDir = tmpFolder.newFolder("source")
properties.stubsOutputDir = tmpFolder.newFolder("target")
FileSystemUtils
@@ -76,7 +76,7 @@ class RecursiveFilesConverterSpec extends Specification {
given:
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
File originalSourceRootDirectory = new File(this.getClass()
.getResource("/converter/source").toURI())
.getResource("/converter/source").toURI())
properties.contractsDslDir = tmpFolder.newFolder("source")
properties.stubsOutputDir = tmpFolder.newFolder("target")
properties.excludedFiles = ["dir1/**"]

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.wiremock
@@ -43,8 +43,10 @@ import org.springframework.util.SocketUtils
class DslToWireMockClientConverterSpec extends Specification {
int port = SocketUtils.findAvailableTcpPort()
@Rule public WireMockRule wireMockRule = new WireMockRule(port)
@Rule public TemporaryFolder tmpFolder = new TemporaryFolder()
@Rule
public WireMockRule wireMockRule = new WireMockRule(port)
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder()
TestRestTemplate restTemplate = new TestRestTemplate()
String url
@@ -70,9 +72,9 @@ class DslToWireMockClientConverterSpec extends Specification {
""")
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals('''
JSONAssert.assertEquals('''
{"request":{"method":"PUT","urlPattern":"/[0-9]{2}"},"response":{"status":200}}
''', json, false)
and:
@@ -114,9 +116,9 @@ class DslToWireMockClientConverterSpec extends Specification {
""")
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals('''
JSONAssert.assertEquals('''
{"request":{"url":"/multipart","method":"POST","headers":{"Content-Type":{"matches":"multipart/form-data.*"}},"bodyPatterns":[{"matches" : ".*--(.*)\\r\\nContent-Disposition: form-data; name=\\"file\\"; filename=\\".+\\"\\r\\n(Content-Type: .*\\r\\n)?(Content-Transfer-Encoding: .*\\r\\n)?(Content-Length: \\\\d+\\r\\n)?\\r\\n.+\\r\\n--\\\\1.*"}]},"response":{"status":200,"body":"hello","transformers":["response-template"]}}
''', json, false)
and:
@@ -127,7 +129,7 @@ class DslToWireMockClientConverterSpec extends Specification {
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>()
parameters.add("file", new ByteArrayResource([100, 117, 100, 97] as byte[]) {
@Override
String getFilename(){
String getFilename() {
return "file"
}
})
@@ -164,7 +166,7 @@ class DslToWireMockClientConverterSpec extends Specification {
''')
when:
Map<Contract, String> convertedContents = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file)))
ContractVerifierDslConverter.convertAsCollection(new File("/"), file)))
then:
convertedContents.size() == 2
JSONAssert.assertEquals(jsonResponse(1), convertedContents.values().first(), false)
@@ -177,11 +179,11 @@ class DslToWireMockClientConverterSpec extends Specification {
wireMockRule.addStubMapping(mapping2)
and:
restTemplate.exchange(RequestEntity.put("${url}/1".toURI())
.header('Content-Type', 'application/json')
.body(""), String)
.header('Content-Type', 'application/json')
.body(""), String)
restTemplate.exchange(RequestEntity.put("${url}/2".toURI())
.header('Content-Type', 'application/json')
.body(""), String)
.header('Content-Type', 'application/json')
.body(""), String)
}
private String jsonResponse(int index) {
@@ -205,7 +207,7 @@ class DslToWireMockClientConverterSpec extends Specification {
when:
Map<Contract, String> convertedContents = converter.convertContents("Test",
new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file)))
ContractVerifierDslConverter.convertAsCollection(new File("/"), file)))
then:
convertedContents.isEmpty()
}
@@ -230,7 +232,7 @@ class DslToWireMockClientConverterSpec extends Specification {
""")
when:
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals('''
{"request":{
@@ -299,9 +301,9 @@ class DslToWireMockClientConverterSpec extends Specification {
""")
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals('''
JSONAssert.assertEquals('''
{
"request" : {
"url" : "/api/12",
@@ -356,8 +358,8 @@ class DslToWireMockClientConverterSpec extends Specification {
wireMockRule.addStubMapping(mapping)
and:
restTemplate.exchange(RequestEntity.put("${url}/api/12".toURI())
.header('Content-Type', 'application/vnd.org.springframework.cloud.contract.verifier.twitter-places-analyzer.v1+json')
.body('''
.header('Content-Type', 'application/vnd.org.springframework.cloud.contract.verifier.twitter-places-analyzer.v1+json')
.body('''
[{
"created_at": "Sat Jul 26 09:38:57 +0000 2014",
"id": 492967299297845248,
@@ -417,7 +419,7 @@ class DslToWireMockClientConverterSpec extends Specification {
""")
when:
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals('''
{"request":{"urlPath":"/foos","method":"GET"},"response":{"body":"[{\\"id\\":\\"123\\"},{\\"id\\":\\"567\\"}]"}}
@@ -456,7 +458,7 @@ class DslToWireMockClientConverterSpec extends Specification {
""")
when:
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
noExceptionThrown()
and:
@@ -503,10 +505,10 @@ class DslToWireMockClientConverterSpec extends Specification {
''')
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals( // tag::wiremock[]
'''
'''
{
"request" : {
"url" : "/users/password",
@@ -533,15 +535,15 @@ class DslToWireMockClientConverterSpec extends Specification {
}
'''
// end::wiremock[]
, json, false)
, json, false)
and:
StubMapping mapping = stubMappingIsValidWireMockStub(json)
and:
wireMockRule.addStubMapping(mapping)
and:
def response = restTemplate.exchange(RequestEntity.post("${url}/users/password".toURI())
.header("Content-Type", "application/json")
.body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''')
.header("Content-Type", "application/json")
.body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''')
, String)
response.headers.get('Content-Type') == ['application/json']
response.statusCodeValue == 404
@@ -691,10 +693,10 @@ class DslToWireMockClientConverterSpec extends Specification {
''')
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals(//tag::matchers[]
'''
'''
{
"request" : {
"urlPath" : "/get",
@@ -755,75 +757,75 @@ class DslToWireMockClientConverterSpec extends Specification {
}
'''
//end::matchers[]
, json, false)
, json, false)
and:
StubMapping mapping = stubMappingIsValidWireMockStub(json)
and:
wireMockRule.addStubMapping(mapping)
and:
def response = restTemplate.exchange(RequestEntity.post("${url}/get".toURI())
.header("Content-Type", "application/json")
.body(JsonOutput.toJson([
duck: 123,
alpha: "abc",
number: 123,
aBoolean: true,
date: "2017-01-01",
dateTime: "2017-01-01T01:23:45",
time: "01:02:34",
valueWithoutAMatcher: "foo",
valueWithTypeMatch: "string",
list: [
some: [
nested: [
json: "with value",
anothervalue: 4
]
],
someother: [
nested: [
json: "with value",
anothervalue: 4
]
]
],
valueWithMin: [
1,2,3
],
valueWithMax: [
1,2,3
],
valueWithMinMax: [
1,2,3
],
valueWithOccurrence: [
1,2,3,4
]
]))
.header("Content-Type", "application/json")
.body(JsonOutput.toJson([
duck : 123,
alpha : "abc",
number : 123,
aBoolean : true,
date : "2017-01-01",
dateTime : "2017-01-01T01:23:45",
time : "01:02:34",
valueWithoutAMatcher: "foo",
valueWithTypeMatch : "string",
list : [
some : [
nested: [
json : "with value",
anothervalue: 4
]
],
someother: [
nested: [
json : "with value",
anothervalue: 4
]
]
],
valueWithMin : [
1, 2, 3
],
valueWithMax : [
1, 2, 3
],
valueWithMinMax : [
1, 2, 3
],
valueWithOccurrence : [
1, 2, 3, 4
]
]))
, String)
response.headers.get('Content-Type') == ['application/json']
response.statusCodeValue == 200
JSONAssert.assertEquals(JsonOutput.toJson([
duck: 123,
alpha: "abc",
number: 123,
aBoolean: true,
date: "2017-01-01",
dateTime: "2017-01-01T01:23:45",
time: "01:02:34",
duck : 123,
alpha : "abc",
number : 123,
aBoolean : true,
date : "2017-01-01",
dateTime : "2017-01-01T01:23:45",
time : "01:02:34",
valueWithoutAMatcher: "foo",
valueWithTypeMatch: "string",
valueWithMin: [
1,2,3
valueWithTypeMatch : "string",
valueWithMin : [
1, 2, 3
],
valueWithMax: [
1,2,3
valueWithMax : [
1, 2, 3
],
valueWithMinMax: [
1,2,3
valueWithMinMax : [
1, 2, 3
],
valueWithOccurrence: [
1,2,3,4
valueWithOccurrence : [
1, 2, 3, 4
],
]), response.body, false)
}
@@ -869,7 +871,7 @@ class DslToWireMockClientConverterSpec extends Specification {
''')
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals(
'''
@@ -898,15 +900,15 @@ class DslToWireMockClientConverterSpec extends Specification {
"priority" : 1
}
'''
, json, false)
, json, false)
and:
StubMapping mapping = stubMappingIsValidWireMockStub(json)
and:
wireMockRule.addStubMapping(mapping)
and:
def response = restTemplate.exchange(RequestEntity.post("${url}/users/password2".toURI())
.header("Content-Type", "application/json")
.body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''')
.header("Content-Type", "application/json")
.body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''')
, String)
response.headers.get('Content-Type') == ['application/json']
response.statusCodeValue == 404
@@ -964,7 +966,7 @@ class DslToWireMockClientConverterSpec extends Specification {
''')
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals(
'''
@@ -996,15 +998,15 @@ class DslToWireMockClientConverterSpec extends Specification {
}
}
'''
, json, false)
, json, false)
and:
StubMapping mapping = stubMappingIsValidWireMockStub(json)
and:
wireMockRule.addStubMapping(mapping)
and:
def response = restTemplate.exchange(RequestEntity.post("${url}/users/password2".toURI())
.header("Content-Type", "application/json")
.body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''')
.header("Content-Type", "application/json")
.body('''{"email":"abc@abc.com", "callback_url":"http://partners.com"}''')
, String)
response.headers.get('Content-Type') == ['application/json;charset=UTF-8']
response.statusCodeValue == 400
@@ -1039,7 +1041,7 @@ class DslToWireMockClientConverterSpec extends Specification {
''')
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(new File("/"),file))).values().first()
ContractVerifierDslConverter.convertAsCollection(new File("/"), file))).values().first()
then:
JSONAssert.assertEquals(
'''
@@ -1058,7 +1060,7 @@ class DslToWireMockClientConverterSpec extends Specification {
}
}
'''
, json, false)
, json, false)
and:
StubMapping mapping = stubMappingIsValidWireMockStub(json)
and:

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.wiremock
@@ -134,7 +134,7 @@ class WireMockToDslConverterSpec extends Specification {
}
response {
status OK()
body( """{
body("""{
"status": "OK"
}""")
headers {
@@ -239,7 +239,7 @@ class WireMockToDslConverterSpec extends Specification {
}
response {
status OK()
body( """[
body("""[
{
"a": 1,
"c": "3"
@@ -349,7 +349,7 @@ class WireMockToDslConverterSpec extends Specification {
request {
method 'POST'
url '/test'
body ('''{"property1":"abc", "property2":"2017-01", "property3":"666", "property4":1428566412}''')
body('''{"property1":"abc", "property2":"2017-01", "property3":"666", "property4":1428566412}''')
}
response {
status OK()

View File

@@ -1,28 +1,29 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.wiremock
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
import spock.lang.Specification
import java.nio.file.Path
import java.nio.file.Paths
import spock.lang.Specification
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
class WiremockScenarioConverterSpec extends Specification {
def "should generate first scenario step"() {

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('POST')

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('GET')

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('POST')

View File

@@ -1,18 +1,17 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import org.springframework.cloud.contract.spec.Contract

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('PUT')

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('PUT')

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
(1..2).collect { int index ->
Contract.make {
request {
@@ -29,4 +29,4 @@ import org.springframework.cloud.contract.spec.Contract
status OK()
}
}
}
}

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
(1..2).collect { int index ->
Contract.make {
name("shouldHaveIndex${index}")
@@ -30,4 +30,4 @@ import org.springframework.cloud.contract.spec.Contract
status OK()
}
}
}
}

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('PUT')

View File

@@ -1,47 +1,47 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import org.springframework.cloud.contract.spec.Contract
[
Contract.make {
name("1_scenario_multiple")
request {
method('PUT')
headers {
header 'Content-Type': 'application/json'
}
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status OK()
}
},
Contract.make {
name("2_scenario_multiple")
request {
method('PUT')
headers {
header 'Content-Type': 'application/json'
}
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status OK()
Contract.make {
name("1_scenario_multiple")
request {
method('PUT')
headers {
header 'Content-Type': 'application/json'
}
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status OK()
}
},
Contract.make {
name("2_scenario_multiple")
request {
method('PUT')
headers {
header 'Content-Type': 'application/json'
}
url $(consumer('/[0-9]{2}'), producer('/12'))
}
response {
status OK()
}
}
]

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('PUT')

View File

@@ -1,21 +1,21 @@
import org.springframework.cloud.contract.spec.Contract
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method('PUT')

View File

@@ -5,12 +5,16 @@ buildscript {
mavenCentral()
mavenLocal()
maven { url 'https://repo.spring.io/plugins-release' }
if (project.hasProperty('fatJar')) jcenter()
if (project.hasProperty('fatJar')) {
jcenter()
}
}
dependencies {
classpath "com.bmuschko:gradle-nexus-plugin:2.3"
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3"
if (project.hasProperty('fatJar')) classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
if (project.hasProperty('fatJar')) {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
}
}
}
@@ -18,10 +22,10 @@ ext {
repoUser = System.getenv('REPO_USERNAME') ?: project.findProperty('REPO_USERNAME') ?: ''
repoPass = System.getenv('REPO_PASSWORD') ?: project.findProperty('REPO_PASSWORD') ?: ''
contractVerifierGradlePluginLibsDir ="$buildDir/contractVerifier-gradle-plugin-libs"
contractVerifierGradlePluginLibsDir = "$buildDir/contractVerifier-gradle-plugin-libs"
testSystemProperties = [
'contract-gradle-plugin-libs-dir': contractVerifierGradlePluginLibsDir,
"WORK_OFFLINE" : gradle.startParameter.isOffline() ? 'TRUE' : 'FALSE'
"WORK_OFFLINE" : gradle.startParameter.isOffline() ? 'TRUE' : 'FALSE'
]
JavaVersion javaVer = JavaVersion.current()
println "Current Java version equal to [${javaVer}]"
@@ -86,7 +90,7 @@ dependencies {
}
task libtest() {
doLast{
doLast {
configurations.testCompile.files.each { println it }
}
}
@@ -152,4 +156,4 @@ task resolveDependencies {
task wrapper(type: Wrapper) {
gradleVersion = '4.10.2'
}
}

View File

@@ -13,10 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
nexusUsername =
nexusPassword =
verifierVersion=2.1.0.BUILD-SNAPSHOT
nexusUsername=
nexusPassword=
verifierVersion=2.1.1.BUILD-SNAPSHOT
org.gradle.daemon=false
aetherVersion=1.1.0
springCloudBuildVersion=2.1.0.BUILD-SNAPSHOT
springCloudBuildVersion=2.1.3.BUILD-SNAPSHOT

View File

@@ -38,8 +38,12 @@ ext {
isReleaseToCentral = project.hasProperty('central')
resolveVersion = { String version ->
if (isMilestoneVersion) return 'milestone'
if (isReleaseVersion) return 'release'
if (isMilestoneVersion) {
return 'milestone'
}
if (isReleaseVersion) {
return 'release'
}
return 'snapshot'
}
@@ -109,4 +113,4 @@ afterEvaluate {
}
}
}
}
}

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-tools</artifactId>
<version>2.1.0.BUILD-SNAPSHOT</version>
<version>2.1.1.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
import org.springframework.cloud.contract.verifier.config.TestFramework
import org.springframework.cloud.contract.verifier.config.TestMode
/**
* @author Marcin Grzejszczak
*/
@@ -137,7 +138,7 @@ class ContractVerifierExtension {
Boolean assertJsonSize = false
ContractRepository contractRepository = new ContractRepository()
/**
* Dependency that contains packaged contracts
*/
@@ -248,8 +249,8 @@ class ContractVerifierExtension {
nameSuffixForTests: this.nameSuffixForTests,
ruleClassForTests: this.ruleClassForTests,
excludedFiles: new ArrayList<String>(this.excludedFiles),
includedFiles: new ArrayList<String>(this.includedFiles),
ignoredFiles: new ArrayList<String>(this.ignoredFiles),
includedFiles: new ArrayList<String>(this.includedFiles),
ignoredFiles: new ArrayList<String>(this.ignoredFiles),
imports: Arrays.asList(this.imports).toArray(),
staticImports: Arrays.asList(this.staticImports).toArray(),
contractsDslDir: this.contractsDslDir,

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -25,5 +25,6 @@ package org.springframework.cloud.contract.verifier.plugin
*/
interface ExtensionHolderSpec {
Closure getExtensionClosure()
void setExtensionClosure(Closure closure)
}
}

View File

@@ -2,6 +2,7 @@ package org.springframework.cloud.contract.verifier.plugin
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
/**

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,10 +19,12 @@ package org.springframework.cloud.contract.verifier.plugin
import org.gradle.api.Task
import org.gradle.api.internal.ConventionTask
import org.gradle.api.tasks.TaskAction
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
import org.springframework.cloud.contract.verifier.converter.RecursiveFilesConverter
import static org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin.COPY_CONTRACTS_TASK_NAME
//TODO: Implement as an incremental task: https://gradle.org/docs/current/userguide/custom_tasks.html#incremental_tasks ?
/**
* Generates stubs from the contracts. The name is WireMock related but the implementation
@@ -55,7 +57,8 @@ class GenerateClientStubsFromDslTask extends ConventionTask {
private ContractVerifierConfigProperties props(Task task) {
try {
return task.ext.contractVerifierConfigProperties
} catch (Exception e) {
}
catch (Exception e) {
project.logger.error("Couldn't retrieve the configuration property set by the copy contracts task", e)
ContractVerifierConfigProperties props = ExtensionToProperties.fromExtension(getConfigProperties())
getDownloader().downloadAndUnpackContractsIfRequired(getConfigProperties(), props)
@@ -66,7 +69,8 @@ class GenerateClientStubsFromDslTask extends ConventionTask {
private File contractsDslDir(Task task, ContractVerifierConfigProperties props) {
try {
return task.ext.contractsDslDir
} catch (Exception e) {
}
catch (Exception e) {
project.logger.error("Couldn't retrieve the contract dsl property set by the copy contracts task", e)
return props.contractsDslDir
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.plugin
@@ -72,7 +72,8 @@ class GenerateServerTestsTask extends ConventionTask {
TestGenerator generator = new TestGenerator(props)
int generatedClasses = generator.generate()
project.logger.info("Generated {} test classes", generatedClasses)
} catch (ContractVerifierException e) {
}
catch (ContractVerifierException e) {
throw new GradleException("Spring Cloud Contract Verifier Plugin exception: ${e.message}", e)
}
}
@@ -80,7 +81,8 @@ class GenerateServerTestsTask extends ConventionTask {
private ContractVerifierConfigProperties props(Task task) {
try {
return task.ext.contractVerifierConfigProperties
} catch (Exception e) {
}
catch (Exception e) {
project.logger.error("Couldn't retrieve the configuration property set by the copy contracts task", e)
ContractVerifierConfigProperties props = ExtensionToProperties.fromExtension(getConfigProperties())
getDownloader().downloadAndUnpackContractsIfRequired(getConfigProperties(), props)
@@ -91,7 +93,8 @@ class GenerateServerTestsTask extends ConventionTask {
private File contractsDslDir(Task task, ContractVerifierConfigProperties props) {
try {
return task.ext.contractsDslDir
} catch (Exception e) {
}
catch (Exception e) {
project.logger.error("Couldn't retrieve the contract dsl property set by the copy contracts task", e)
return props.contractsDslDir
}

View File

@@ -1,9 +1,12 @@
package org.springframework.cloud.contract.verifier.plugin
import java.util.concurrent.ConcurrentHashMap
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.gradle.api.Project
import org.gradle.api.logging.Logger
import org.springframework.cloud.contract.stubrunner.ContractDownloader
import org.springframework.cloud.contract.stubrunner.StubConfiguration
import org.springframework.cloud.contract.stubrunner.StubDownloader
@@ -13,7 +16,6 @@ import org.springframework.cloud.contract.stubrunner.StubRunnerOptionsBuilder
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
import org.springframework.util.StringUtils
import java.util.concurrent.ConcurrentHashMap
/**
* @author Marcin Grzejszczak
*/
@@ -26,14 +28,14 @@ class GradleContractsDownloader {
private final Project project
private final Logger log
protected static final Map<StubConfiguration, File> downloadedContract = new ConcurrentHashMap<>()
GradleContractsDownloader(Project project, Logger log) {
this.project = project
this.log = log
}
File downloadAndUnpackContractsIfRequired(ContractVerifierExtension extension,
ContractVerifierConfigProperties config) {
ContractVerifierConfigProperties config) {
File defaultContractsDir = extension.contractsDslDir
this.log.info("Project has group id [{}], artifact id [{}]", this.project.group, this.project.name)
// download contracts, unzip them and pass as output directory
@@ -73,12 +75,12 @@ class GradleContractsDownloader {
}
protected StubDownloader stubDownloader(ContractVerifierExtension extension) {
StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider()
StubDownloaderBuilderProvider provider = new StubDownloaderBuilderProvider()
return provider.get(options(extension))
}
protected StubRunnerOptions options(ContractVerifierExtension extension) {
StubRunnerOptionsBuilder options = new StubRunnerOptionsBuilder()
StubRunnerOptionsBuilder options = new StubRunnerOptionsBuilder()
.withOptions(StubRunnerOptions.fromSystemProps())
.withStubRepositoryRoot(extension.contractRepository.repositoryUrl)
.withStubsMode(extension.contractsMode)
@@ -92,7 +94,8 @@ class GradleContractsDownloader {
return options.build()
}
@PackageScope StubConfiguration stubConfiguration(ContractVerifierExtension.Dependency contractDependency) {
@PackageScope
StubConfiguration stubConfiguration(ContractVerifierExtension.Dependency contractDependency) {
String groupId = contractDependency.groupId
String artifactId = contractDependency.artifactId
String version = StringUtils.hasText(contractDependency.version) ?

View File

@@ -12,14 +12,14 @@ import org.gradle.api.Project
class OutputFolderBuilder {
private static final String DEFAULT_MAPPINGS_FOLDER = 'mappings'
static String buildRootPath(Project project) {
String groupId = project.group as String
String artifactId = project.name
String version = project.version
return "META-INF/${groupId}/${artifactId}/${version}"
}
static File outputMappingsDir(Project project, File stubsOutputDir) {
String root = OutputFolderBuilder.buildRootPath(project)
return stubsOutputDir != null ?

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,

View File

@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,6 +24,7 @@ import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.jvm.tasks.Jar
/**
* Gradle plugin for Spring Cloud Contract Verifier that from the DSL contract can
* <ul>
@@ -40,7 +41,8 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
private static final String GENERATE_SERVER_TESTS_TASK_NAME = 'generateContractTests'
private static final String DSL_TO_CLIENT_TASK_NAME = 'generateClientStubs'
@PackageScope static final String COPY_CONTRACTS_TASK_NAME = 'copyContracts'
@PackageScope
static final String COPY_CONTRACTS_TASK_NAME = 'copyContracts'
private static final String VERIFIER_STUBS_JAR_TASK_NAME = 'verifierStubsJar'
private static final String PUBLISH_STUBS_TO_SCM_TASK_NAME = 'publishStubsToScm'
@@ -98,7 +100,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
}
private void createGenerateTestsTask(ContractVerifierExtension extension, Task copyContracts,
GradleContractsDownloader gradleContractsDownloader) {
GradleContractsDownloader gradleContractsDownloader) {
Task task = project.tasks.create(GENERATE_SERVER_TESTS_TASK_NAME, GenerateServerTestsTask)
task.description = "Generate server tests from the contracts"
task.group = GROUP_NAME
@@ -113,7 +115,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
}
private void createAndConfigurePublishStubsToScmTask(ContractVerifierExtension extension,
GradleContractsDownloader gradleContractsDownloader) {
GradleContractsDownloader gradleContractsDownloader) {
Task task = project.tasks.create(PUBLISH_STUBS_TO_SCM_TASK_NAME, PublishStubsToScmTask)
task.description = "The generated stubs get committed to the SCM repo and pushed to origin"
task.group = GROUP_NAME
@@ -126,7 +128,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
}
private Task createAndConfigureGenerateClientStubs(ContractVerifierExtension extension,
Task copyContracts) {
Task copyContracts) {
Task task = project.tasks.create(DSL_TO_CLIENT_TASK_NAME, GenerateClientStubsFromDslTask)
task.description = "Generate client stubs from the contracts"
task.group = GROUP_NAME
@@ -144,7 +146,8 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
if (task) {
project.logger.info("Spring Cloud Contract Verifier Plugin: Stubs jar task was present - won't create one. Remember about adding it to artifacts as an archive!")
return task
} else {
}
else {
task = project.tasks.create(type: Jar, name: VERIFIER_STUBS_JAR_TASK_NAME,
dependsOn: DSL_TO_CLIENT_TASK_NAME) {
baseName = project.name
@@ -163,14 +166,15 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
private Task stubsTask() {
try {
return project.tasks.getByName(VERIFIER_STUBS_JAR_TASK_NAME)
} catch (Exception e) {
}
catch (Exception e) {
return null
}
}
private Task createAndConfigureCopyContractsTask(Task stubs,
GradleContractsDownloader gradleContractsDownloader,
ContractVerifierExtension contractVerifierExtension) {
GradleContractsDownloader gradleContractsDownloader,
ContractVerifierExtension contractVerifierExtension) {
Task task = project.tasks.create(COPY_CONTRACTS_TASK_NAME, ContractsCopyTask)
task.description = "Copies contracts to the output folder"
task.group = GROUP_NAME
@@ -203,7 +207,8 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
artifact stubsTask
}
}
} else {
}
else {
project.logger.info("Spring Cloud Contract Verifier Plugin: Stubs publication was present - won't create a new one. Remember about passing stubs as artifact")
}
}
@@ -213,7 +218,8 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
private boolean hasPublication(def publishingExtension) {
try {
return publishingExtension.publications.getByName('stubs')
} catch (Exception e) {
}
catch (Exception e) {
return false
}
}
@@ -222,7 +228,8 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
try {
Class.forName(className)
return true
} catch (Exception e) {
}
catch (Exception e) {
project.logger.debug("Maven Publish Plugin is not available")
}
return false

View File

@@ -13,5 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
implementation-class=org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin
implementation-class=org.springframework.cloud.contract.verifier.plugin.SpringCloudContractVerifierGradlePlugin

View File

@@ -62,7 +62,7 @@ class ContractVerifierExtensionSpec extends Specification {
contractsPath: "foo25",
contractsMode: StubRunnerProperties.StubsMode.CLASSPATH,
packageWithBaseClasses: "foo26",
baseClassMappings: [foo27: "foo28"],
baseClassMappings: [foo27: "foo28"],
excludeBuildFolders: false,
deleteStubsAfterTest: false,
convertToYaml: false,
@@ -106,11 +106,11 @@ class ContractVerifierExtensionSpec extends Specification {
contractsPath = "bar25"
contractsMode = StubRunnerProperties.StubsMode.REMOTE
packageWithBaseClasses = "bar26"
baseClassMappings = [bar27 : "bar28"]
baseClassMappings = [bar27: "bar28"]
excludeBuildFolders = true
deleteStubsAfterTest = true
convertToYaml = true
contractsProperties = [bar29 : "bar30"]
contractsProperties = [bar29: "bar30"]
}
then:
copy.testFramework == TestFramework.JUNIT5
@@ -144,10 +144,10 @@ class ContractVerifierExtensionSpec extends Specification {
copy.contractsPath == "foo25"
copy.contractsMode == StubRunnerProperties.StubsMode.CLASSPATH
copy.packageWithBaseClasses == "foo26"
copy.baseClassMappings == [foo27 : "foo28"]
copy.baseClassMappings == [foo27: "foo28"]
copy.excludeBuildFolders == false
copy.deleteStubsAfterTest == false
copy.convertToYaml == false
copy.contractsProperties == [foo29 : "foo30"]
copy.contractsProperties == [foo29: "foo30"]
}
}

View File

@@ -1,32 +1,35 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.plugin
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes
import java.util.zip.ZipException
import java.util.zip.ZipFile
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.BuildTask
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Specification
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
import java.util.zip.ZipException
import java.util.zip.ZipFile
import static java.nio.charset.StandardCharsets.UTF_8
abstract class ContractVerifierIntegrationSpec extends Specification {
@@ -69,7 +72,7 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
protected void switchToJunitTestFramework(String from, String to) {
Path path = buildFile.toPath()
String content = new StringBuilder(new String(Files.readAllBytes(path), UTF_8)).replaceAll(SPOCK, JUNIT)
.replaceAll(from, to)
.replaceAll(from, to)
Files.write(path, content.getBytes(UTF_8))
}
@@ -92,17 +95,19 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
protected String[] checkAndPublishToMavenLocal() {
String[] args = ["check", "publishToMavenLocal", "--info", "--stacktrace"] as String[]
if (WORK_OFFLINE) args << "--offline"
if (WORK_OFFLINE) {
args << "--offline"
}
return args
}
protected BuildResult run(String... tasks) {
return GradleRunner.create()
.withProjectDir(testProjectDir)
.withArguments(tasks)
.withDebug(true)
.forwardOutput()
.build()
.withProjectDir(testProjectDir)
.withArguments(tasks)
.withDebug(true)
.forwardOutput()
.build()
}
protected void copyResourcesToRoot(String srcDir) {
@@ -118,7 +123,8 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
File resourceFile = new File(resource.toURI())
if (resourceFile.file) {
Files.copy(resourceFile.toPath(), destinationFile.toPath())
} else {
}
else {
Files.walkFileTree(resourceFile.toPath(),
new CopyFileVisitor(destinationFile.toPath()))
}
@@ -151,7 +157,8 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
}
}
}
}catch (ZipException zipEx) {
}
catch (ZipException zipEx) {
println "Unable to open file ${file.name}"
}
}
@@ -161,16 +168,18 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
private static class CopyFileVisitor extends SimpleFileVisitor<Path> {
private final Path targetPath
private Path sourcePath = null
CopyFileVisitor(Path targetPath) {
this.targetPath = targetPath
}
@Override
FileVisitResult preVisitDirectory(final Path dir,
final BasicFileAttributes attrs) throws IOException {
final BasicFileAttributes attrs) throws IOException {
if (sourcePath == null) {
sourcePath = dir
} else {
}
else {
Files.createDirectories(targetPath.resolve(sourcePath
.relativize(dir)))
}
@@ -179,7 +188,7 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
@Override
FileVisitResult visitFile(final Path file,
final BasicFileAttributes attrs) throws IOException {
final BasicFileAttributes attrs) throws IOException {
Path target = targetPath.resolve(sourcePath.relativize(file))
if (!target.toFile().exists()) {
Files.copy(file, target)

View File

@@ -130,7 +130,7 @@ class ContractVerifierSpec extends Specification {
baseClassForTests = "com.example.FooBase"
baseClassMappings {
baseClassMapping('.*/com/.*', 'com.example.ComBase')
baseClassMapping('.*/bar/.*':'com.example.BarBase')
baseClassMapping('.*/bar/.*': 'com.example.BarBase')
}
// end::base_class_mappings[]
}

View File

@@ -2,12 +2,13 @@ package org.springframework.cloud.contract.verifier.plugin
import org.gradle.api.Project
import org.gradle.api.logging.Logger
import spock.lang.Specification
import org.springframework.cloud.contract.stubrunner.AetherStubDownloader
import org.springframework.cloud.contract.stubrunner.ContractDownloader
import org.springframework.cloud.contract.stubrunner.StubConfiguration
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
import spock.lang.Specification
/**
* @author Marcin Grzejszczak
@@ -206,22 +207,22 @@ class GradleContractsDownloaderSpec extends Specification {
def "should pass contract dependency properties as a parameter to the builder"() {
given:
ContractVerifierExtension ext = new ContractVerifierExtension()
ext.with {
contractDependency {
groupId("com.example")
artifactId("foo")
version("1.0.0.BUILD-SNAPSHOT")
classifier("stubs")
ContractVerifierExtension ext = new ContractVerifierExtension()
ext.with {
contractDependency {
groupId("com.example")
artifactId("foo")
version("1.0.0.BUILD-SNAPSHOT")
classifier("stubs")
}
contractRepository {
repositoryUrl("foo")
username("foo1")
password("foo2")
proxyHost("foo3")
proxyPort(12)
}
}
contractRepository {
repositoryUrl("foo")
username("foo1")
password("foo2")
proxyHost("foo3")
proxyPort(12)
}
}
and:
final AetherStubDownloader downloader = Mock(AetherStubDownloader)
final ContractDownloader contractDownloader = Mock(ContractDownloader)

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.plugin
@@ -24,7 +24,8 @@ class SampleJerseyProjectSpec extends ContractVerifierIntegrationSpec {
def setup() {
setupForProject("functionalTest/sampleJerseyProject")
runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it
runTasksSuccessfully('clean')
//delete accidental output when previously importing SimpleBoot into Idea to tweak it
}
def "should pass basic flow for Spock"() {

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.plugin
@@ -25,7 +25,8 @@ class SampleProjectSpec extends ContractVerifierIntegrationSpec {
def setup() {
setupForProject("functionalTest/sampleProject")
runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it
runTasksSuccessfully('clean')
//delete accidental output when previously importing SimpleBoot into Idea to tweak it
}
def "should pass basic flow for Spock"() {
@@ -33,7 +34,9 @@ class SampleProjectSpec extends ContractVerifierIntegrationSpec {
assert fileExists('build.gradle')
expect:
String[] args = ["check", "publishToMavenLocal", "--debug"] as String[]
if (WORK_OFFLINE) args << "--offline"
if (WORK_OFFLINE) {
args << "--offline"
}
runTasksSuccessfully(args)
jarContainsContractVerifierContracts('fraudDetectionService/build/libs')
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.plugin
@@ -23,7 +23,8 @@ class ScenarioProjectSpec extends ContractVerifierIntegrationSpec {
def setup() {
setupForProject("functionalTest/scenarioProject")
runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it
runTasksSuccessfully('clean')
//delete accidental output when previously importing SimpleBoot into Idea to tweak it
}
def "should pass basic flow for Spock"() {

View File

@@ -54,7 +54,7 @@ contracts {
contractsDslDir = contractsDir
// generatedTestSourcesDir = file("${project.rootDir}/src/test/groovy/")
stubsOutputDir = stubsOutputDirRoot
testFramework ='Spock'
testFramework = 'Spock'
}
generateContractTests.dependsOn generateClientStubs
@@ -67,4 +67,4 @@ test {
testLogging {
exceptionFormat = 'full'
}
}
}

View File

@@ -15,5 +15,5 @@
#
wiremockVersion=2.20.0
jsonAssertVersion=0.4.13
verifierVersion=2.1.0.BUILD-SNAPSHOT
groovyVersion=2.4.15
verifierVersion=2.1.1.BUILD-SNAPSHOT
groovyVersion=2.4.15

View File

@@ -1,23 +1,24 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
priority 2
priority 2
request {
method 'PUT'
url '/api/12'
@@ -33,4 +34,4 @@ Contract.make {
response {
status OK()
}
}
}

View File

@@ -1,19 +1,20 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
@@ -34,10 +35,10 @@ Contract.make {
header 'Content-Type': $(consumer('application/json'), producer(regex('application/json.*')))
header 'Location': $(consumer('https://localhost:8080'), producer(execute('isEmpty($it)')))
}
body (
path: $(consumer('/api/12'), producer(regex('^/api/[0-9]{2}$'))),
correlationId: $(consumer('1223456'), producer(execute('isProperCorrelationId($it)')))
body(
path: $(consumer('/api/12'), producer(regex('^/api/[0-9]{2}$'))),
correlationId: $(consumer('1223456'), producer(execute('isProperCorrelationId($it)')))
)
status OK()
}
}
}

View File

@@ -1,17 +1,18 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
rootProject.name='bootSimple'
rootProject.name = 'bootSimple'

View File

@@ -1,23 +1,24 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.twitter.place
import groovy.transform.TypeChecked
import groovy.util.logging.Slf4j
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestBody

View File

@@ -1,6 +1,23 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.twitter.place;
public class Tweet {
private String text;
public String getText() {
@@ -10,4 +27,5 @@ public class Tweet {
public void setText(String text) {
this.text = text;
}
}

View File

@@ -1,26 +1,27 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.twitter.places
import spock.lang.Specification
import org.springframework.cloud.contract.verifier.twitter.place.PairIdController
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import spock.lang.Specification
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

View File

@@ -1,25 +1,26 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.contract.verifier.twitter.places
import io.restassured.module.mockmvc.RestAssuredMockMvc
import org.springframework.cloud.contract.verifier.twitter.place.PairIdController
import spock.lang.Specification
import org.springframework.cloud.contract.verifier.twitter.place.PairIdController
// tag::base_class[]
abstract class BaseMockMvcSpec extends Specification {

View File

@@ -1,19 +1,20 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
@@ -21,9 +22,9 @@ String console = "CONSOLE"
String logPattern = "%d{yyyy-MM-dd HH:mm:ss.SSSZ, Europe/Warsaw} | %-5level | %X{correlationId} | %thread | %logger{1} | %m%n"
appender(console, ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = logPattern
}
encoder(PatternLayoutEncoder) {
pattern = logPattern
}
}
root(INFO, [console])

View File

@@ -1,19 +1,20 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
buildscript {
repositories {
mavenLocal()
@@ -124,7 +125,7 @@ configure(project(':fraudDetectionService')) {
contracts {
contractsMode = "REMOTE"
testFramework ='Spock'
testFramework = 'Spock'
testMode = 'JaxRsClient'
baseClassForTests = 'org.springframework.cloud.MvcSpec'
contractDependency {
@@ -154,4 +155,4 @@ configure(project(':loanApplicationService')) {
wrapper {
gradleVersion '4.10.2'
}
}

View File

@@ -1,5 +1,23 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection;
import java.math.BigDecimal;
import org.springframework.cloud.frauddetection.model.FraudCheck;
import org.springframework.cloud.frauddetection.model.FraudCheckResult;
import org.springframework.stereotype.Controller;
@@ -17,15 +35,19 @@ import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.OK
public class FraudDetectionController {
private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json";
private static final String NO_REASON = null;
private static final String AMOUNT_TOO_HIGH = "Amount too high";
private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000");
@PUT
@Path("/fraudcheck")
@Produces(FRAUD_SERVICE_JSON_VERSION_1)
@Consumes(FRAUD_SERVICE_JSON_VERSION_1)
public FraudCheckResult fraudCheck(@RequestBody(required = false) FraudCheck fraudCheck) {
public FraudCheckResult fraudCheck(
@RequestBody(required = false) FraudCheck fraudCheck) {
if (amountGreaterThanThreshold(fraudCheck)) {
return new FraudCheckResult(FRAUD, AMOUNT_TOO_HIGH);
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
import java.math.BigDecimal;
@@ -26,4 +42,5 @@ public class FraudCheck {
public void setLoanAmount(BigDecimal loanAmount) {
this.loanAmount = loanAmount;
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
public class FraudCheckResult {
@@ -29,4 +45,5 @@ public class FraudCheckResult {
public void setRejectionReason(String rejectionReason) {
this.rejectionReason = rejectionReason;
}
}

View File

@@ -1,5 +1,23 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
public enum FraudCheckStatus {
OK, FRAUD
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud

View File

@@ -1,6 +1,23 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud;
import java.net.URI;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
@@ -12,6 +29,7 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.client.ClientConfig;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.springframework.cloud.frauddetection.FraudDetectionController;
import static org.springframework.util.SocketUtils.findAvailableTcpPort;
@@ -21,6 +39,7 @@ public abstract class MvcTest {
public static WebTarget webTarget;
private static Server server;
private static Client client;
@BeforeClass
@@ -30,14 +49,17 @@ public abstract class MvcTest {
// Create Server
Server server = new Server(port);
// Configure ServletContextHandler
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
// Create Servlet Container
ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
ServletHolder jerseyServlet = context
.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
// Tells the Jersey Servlet which REST service/class to load.
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", FraudDetectionController.class.getCanonicalName());
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
FraudDetectionController.class.getCanonicalName());
// Start the server
server.start();
ClientConfig clientConfig = new ClientConfig();
@@ -45,20 +67,22 @@ public abstract class MvcTest {
webTarget = client.target(baseUri);
try {
server.start();
} catch (Exception e) {
}
catch (Exception e) {
e.printStackTrace();
}
}
@AfterClass
public static void cleanupTest() {
if(client != null) {
if (client != null) {
client.close();
}
if (server != null) {
try {
server.stop();
} catch (Exception e) {
}
catch (Exception e) {
e.printStackTrace();
}
}
@@ -67,4 +91,5 @@ public abstract class MvcTest {
public void assertThatRejectionReasonIsNull(Object rejectionReason) {
assert rejectionReason == null;
}
}
}

View File

@@ -15,5 +15,5 @@
#
wiremockVersion=2.20.0
jsonAssertVersion=0.4.13
verifierVersion=2.1.0.BUILD-SNAPSHOT
verifierVersion=2.1.1.BUILD-SNAPSHOT
bootVersion=2.1.2.RELEASE

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection;

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection;
@@ -32,8 +32,7 @@ import org.springframework.web.client.RestTemplate;
@Service
public class LoanApplicationService {
private static final String FRAUD_SERVICE_JSON_VERSION_1 =
"application/vnd.fraud.v1+json";
private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json";
private final RestTemplate restTemplate;
@@ -44,11 +43,9 @@ public class LoanApplicationService {
}
public LoanApplicationResult loanApplication(LoanApplication loanApplication) {
FraudServiceRequest request =
new FraudServiceRequest(loanApplication);
FraudServiceRequest request = new FraudServiceRequest(loanApplication);
FraudServiceResponse response =
sendRequestToFraudDetectionService(request);
FraudServiceResponse response = sendRequestToFraudDetectionService(request);
return buildResponseFromFraudResult(response);
}
@@ -58,23 +55,25 @@ public class LoanApplicationService {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
ResponseEntity<FraudServiceResponse> response =
this.restTemplate.exchange("http://localhost:" + this.port + "/fraudcheck", HttpMethod.PUT,
new HttpEntity<>(request, httpHeaders),
FraudServiceResponse.class);
ResponseEntity<FraudServiceResponse> response = this.restTemplate.exchange(
"http://localhost:" + this.port + "/fraudcheck", HttpMethod.PUT,
new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class);
return response.getBody();
}
private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) {
private LoanApplicationResult buildResponseFromFraudResult(
FraudServiceResponse response) {
LoanApplicationStatus applicationStatus = null;
if (FraudCheckStatus.OK == response.getFraudCheckStatus()) {
applicationStatus = LoanApplicationStatus.LOAN_APPLIED;
} else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) {
}
else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) {
applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED;
}
return new LoanApplicationResult(applicationStatus, response.getRejectionReason());
return new LoanApplicationResult(applicationStatus,
response.getRejectionReason());
}
public void setPort(int port) {

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
@@ -27,4 +27,5 @@ public class Client {
public void setPesel(String pesel) {
this.pesel = pesel;
}
}

View File

@@ -1,21 +1,23 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
public enum FraudCheckStatus {
OK, FRAUD
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
@@ -47,4 +47,5 @@ public class FraudServiceRequest {
public void setLoanAmount(BigDecimal loanAmount) {
this.loanAmount = loanAmount;
}
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
@@ -40,4 +40,5 @@ public class FraudServiceResponse {
public void setRejectionReason(String rejectionReason) {
this.rejectionReason = rejectionReason;
}
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
@@ -49,4 +49,5 @@ public class LoanApplication {
public void setLoanApplicationId(String loanApplicationId) {
this.loanApplicationId = loanApplicationId;
}
}

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
@@ -25,7 +25,8 @@ public class LoanApplicationResult {
public LoanApplicationResult() {
}
public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) {
public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus,
String rejectionReason) {
this.loanApplicationStatus = loanApplicationStatus;
this.rejectionReason = rejectionReason;
}
@@ -45,4 +46,5 @@ public class LoanApplicationResult {
public void setRejectionReason(String rejectionReason) {
this.rejectionReason = rejectionReason;
}
}

View File

@@ -1,21 +1,23 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
public enum LoanApplicationStatus {
LOAN_APPLIED, LOAN_APPLICATION_REJECTED
}

View File

@@ -1,21 +1,27 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud
import com.github.tomakehurst.wiremock.junit.WireMockClassRule
import org.junit.ClassRule
import spock.lang.Shared
import spock.lang.Specification
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootContextLoader
import org.springframework.cloud.frauddetection.Application
import org.springframework.cloud.frauddetection.LoanApplicationService
@@ -23,12 +29,7 @@ import org.springframework.cloud.frauddetection.model.Client
import org.springframework.cloud.frauddetection.model.LoanApplication
import org.springframework.cloud.frauddetection.model.LoanApplicationResult
import org.springframework.cloud.frauddetection.model.LoanApplicationStatus
import com.github.tomakehurst.wiremock.junit.WireMockClassRule
import org.junit.ClassRule
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import spock.lang.Shared
import spock.lang.Specification
@ContextConfiguration(loader = SpringBootContextLoader, classes = Application)
class LoanApplicationServiceSpec extends Specification {
@@ -68,5 +69,4 @@ class LoanApplicationServiceSpec extends Specification {
loanApplication.rejectionReason == 'Amount too high'
}
}

View File

@@ -1,26 +1,31 @@
{
"id" : "856bd753-2488-4549-b84f-512e851958a9",
"request" : {
"url" : "/fraudcheck",
"method" : "PUT",
"headers" : {
"Content-Type" : {
"equalTo" : "application/vnd.fraud.v1+json"
"id": "856bd753-2488-4549-b84f-512e851958a9",
"request": {
"url": "/fraudcheck",
"method": "PUT",
"headers": {
"Content-Type": {
"equalTo": "application/vnd.fraud.v1+json"
}
},
"bodyPatterns" : [ {
"matchesJsonPath" : "$[?(@.['loanAmount'] == 99999)]"
}, {
"matchesJsonPath" : "$[?(@.['clientPesel'] =~ /[0-9]{10}/)]"
} ]
"bodyPatterns": [
{
"matchesJsonPath": "$[?(@.['loanAmount'] == 99999)]"
},
{
"matchesJsonPath": "$[?(@.['clientPesel'] =~ /[0-9]{10}/)]"
}
]
},
"response" : {
"status" : 200,
"body" : "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}",
"headers" : {
"Content-Type" : "application/vnd.fraud.v1+json"
"response": {
"status": 200,
"body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}",
"headers": {
"Content-Type": "application/vnd.fraud.v1+json"
},
"transformers" : [ "response-template" ]
"transformers": [
"response-template"
]
},
"uuid" : "856bd753-2488-4549-b84f-512e851958a9"
}
"uuid": "856bd753-2488-4549-b84f-512e851958a9"
}

View File

@@ -1,26 +1,31 @@
{
"id" : "263aac46-1534-497d-9cc6-114a29ffa0de",
"request" : {
"url" : "/fraudcheck",
"method" : "PUT",
"headers" : {
"Content-Type" : {
"equalTo" : "application/vnd.fraud.v1+json"
"id": "263aac46-1534-497d-9cc6-114a29ffa0de",
"request": {
"url": "/fraudcheck",
"method": "PUT",
"headers": {
"Content-Type": {
"equalTo": "application/vnd.fraud.v1+json"
}
},
"bodyPatterns" : [ {
"matchesJsonPath" : "$[?(@.['loanAmount'] == 123.123)]"
}, {
"matchesJsonPath" : "$[?(@.['clientPesel'] =~ /[0-9]{10}/)]"
} ]
"bodyPatterns": [
{
"matchesJsonPath": "$[?(@.['loanAmount'] == 123.123)]"
},
{
"matchesJsonPath": "$[?(@.['clientPesel'] =~ /[0-9]{10}/)]"
}
]
},
"response" : {
"status" : 200,
"body" : "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}",
"headers" : {
"Content-Type" : "application/vnd.fraud.v1+json"
"response": {
"status": 200,
"body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}",
"headers": {
"Content-Type": "application/vnd.fraud.v1+json"
},
"transformers" : [ "response-template" ]
"transformers": [
"response-template"
]
},
"uuid" : "263aac46-1534-497d-9cc6-114a29ffa0de"
}
"uuid": "263aac46-1534-497d-9cc6-114a29ffa0de"
}

View File

@@ -15,11 +15,12 @@
~ limitations under the License.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>jersey-contracts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>jersey-contracts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
</project>

View File

@@ -16,13 +16,13 @@
-->
<metadata>
<groupId>com.example</groupId>
<artifactId>jersey-contracts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<versioning>
<versions>
<version>0.0.1-SNAPSHOT</version>
</versions>
<lastUpdated>20160409062112</lastUpdated>
</versioning>
<groupId>com.example</groupId>
<artifactId>jersey-contracts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<versioning>
<versions>
<version>0.0.1-SNAPSHOT</version>
</versions>
<lastUpdated>20160409062112</lastUpdated>
</versioning>
</metadata>

View File

@@ -1,17 +1,17 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
include ':fraudDetectionService'

View File

@@ -1,19 +1,20 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
buildscript {
repositories {
mavenCentral()
@@ -73,7 +74,7 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
contracts {
contractsMode = "REMOTE"
testFramework ='Spock'
testFramework = 'Spock'
testMode = 'MockMvc'
baseClassForTests = 'org.springframework.cloud.MvcSpec'
contractsDslDir = file("${project.projectDir.absolutePath}/mappings/")

View File

@@ -1,47 +1,48 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method """PUT"""
url """/fraudcheck"""
body("""
request {
method """PUT"""
url """/fraudcheck"""
body("""
{
"clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}",
"loanAmount":99999}
"""
)
headers {
header("""Content-Type""", """application/vnd.fraud.v1+json""")
}
)
headers {
header("""Content-Type""", """application/vnd.fraud.v1+json""")
}
}
response {
status OK()
body( """{
}
response {
status OK()
body("""{
"fraudCheckStatus": "${value(consumer('FRAUD'), producer(regex('[A-Z]{5}')))}",
"rejectionReason": "Amount too high"
}""")
headers {
header('Content-Type': value(
producer(regex('application/vnd.fraud.v1.json.*')),
consumer('application/vnd.fraud.v1+json'))
)
}
}
headers {
header('Content-Type': value(
producer(regex('application/vnd.fraud.v1.json.*')),
consumer('application/vnd.fraud.v1+json'))
)
}
}
}

View File

@@ -1,48 +1,49 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'PUT'
url '/fraudcheck'
body("""
request {
method 'PUT'
url '/fraudcheck'
body("""
{
"clientPesel":"${value(consumer(regex('[0-9]{10}')), producer('1234567890'))}",
"loanAmount":123.123
}
"""
)
headers {
header('Content-Type', 'application/vnd.fraud.v1+json')
}
)
headers {
header('Content-Type', 'application/vnd.fraud.v1+json')
}
}
response {
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))
)
headers {
header('Content-Type': value(
producer(regex('application/vnd.fraud.v1.json.*')),
consumer('application/vnd.fraud.v1+json'))
)
}
}
}
response {
status OK()
body(
fraudCheckStatus: "OK",
rejectionReason: $(consumer(null), producer(execute('assertThatRejectionReasonIsNull($it)')))
)
headers {
header('Content-Type': value(
producer(regex('application/vnd.fraud.v1.json.*')),
consumer('application/vnd.fraud.v1+json'))
)
}
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection;
import org.springframework.boot.SpringApplication;
@@ -11,8 +27,8 @@ import org.springframework.context.annotation.Configuration;
public class Application {
public static void main(String[] args) {
SpringApplication.run(
org.springframework.cloud.frauddetection.Application.class, args);
SpringApplication.run(org.springframework.cloud.frauddetection.Application.class,
args);
}
}

View File

@@ -1,13 +1,29 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection;
import java.math.BigDecimal;
import org.springframework.cloud.frauddetection.model.FraudCheck;
import org.springframework.cloud.frauddetection.model.FraudCheckResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.FRAUD;
import static org.springframework.cloud.frauddetection.model.FraudCheckStatus.OK;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
@@ -16,15 +32,14 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT;
public class FraudDetectionController {
private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json";
private static final String NO_REASON = null;
private static final String AMOUNT_TOO_HIGH = "Amount too high";
private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000");
@RequestMapping(
value = "/fraudcheck",
method = PUT,
consumes = FRAUD_SERVICE_JSON_VERSION_1,
produces = FRAUD_SERVICE_JSON_VERSION_1)
@RequestMapping(value = "/fraudcheck", method = PUT, consumes = FRAUD_SERVICE_JSON_VERSION_1, produces = FRAUD_SERVICE_JSON_VERSION_1)
public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) {
if (amountGreaterThanThreshold(fraudCheck)) {
return new FraudCheckResult(FRAUD, AMOUNT_TOO_HIGH);

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
import java.math.BigDecimal;
@@ -26,4 +42,5 @@ public class FraudCheck {
public void setLoanAmount(BigDecimal loanAmount) {
this.loanAmount = loanAmount;
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
public class FraudCheckResult {
@@ -29,4 +45,5 @@ public class FraudCheckResult {
public void setRejectionReason(String rejectionReason) {
this.rejectionReason = rejectionReason;
}
}

View File

@@ -1,5 +1,23 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
public enum FraudCheckStatus {
OK, FRAUD
}

View File

@@ -1,4 +1,4 @@
#WireMock password - http://wiremock.org/docs/running-standalone/
server.ssl.key-store-password=password
server.ssl.key-password=password
server.ssl.trust-store-password=password
server.ssl.trust-store-password=password

View File

@@ -1,25 +1,26 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud
import org.springframework.cloud.frauddetection.FraudDetectionController
import io.restassured.module.mockmvc.RestAssuredMockMvc
import spock.lang.Specification
import org.springframework.cloud.frauddetection.FraudDetectionController
class MvcSpec extends Specification {
def setup() {
RestAssuredMockMvc.standaloneSetup(new FraudDetectionController())

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
@@ -7,10 +23,12 @@ public class MvcTest {
@Before
public void setup() {
RestAssuredMockMvc.standaloneSetup(new org.springframework.cloud.frauddetection.FraudDetectionController());
RestAssuredMockMvc.standaloneSetup(
new org.springframework.cloud.frauddetection.FraudDetectionController());
}
public void assertThatRejectionReasonIsNull(Object rejectionReason) {
assert rejectionReason == null;
}
}
}

View File

@@ -15,5 +15,5 @@
#
wiremockVersion=2.20.0
jsonAssertVersion=0.4.13
verifierVersion=2.1.0.BUILD-SNAPSHOT
verifierVersion=2.1.1.BUILD-SNAPSHOT
bootVersion=2.1.2.RELEASE

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection;
import org.springframework.boot.SpringApplication;
@@ -11,8 +27,8 @@ import org.springframework.context.annotation.Configuration;
public class Application {
public static void main(String[] args) {
SpringApplication.run(
org.springframework.cloud.frauddetection.Application.class, args);
SpringApplication.run(org.springframework.cloud.frauddetection.Application.class,
args);
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection;
import org.springframework.cloud.frauddetection.model.FraudCheckStatus;
@@ -16,8 +32,7 @@ import org.springframework.web.client.RestTemplate;
@Service
public class LoanApplicationService {
private static final String FRAUD_SERVICE_JSON_VERSION_1 =
"application/vnd.fraud.v1+json";
private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json";
private final RestTemplate restTemplate;
@@ -28,11 +43,9 @@ public class LoanApplicationService {
}
public LoanApplicationResult loanApplication(LoanApplication loanApplication) {
FraudServiceRequest request =
new FraudServiceRequest(loanApplication);
FraudServiceRequest request = new FraudServiceRequest(loanApplication);
FraudServiceResponse response =
sendRequestToFraudDetectionService(request);
FraudServiceResponse response = sendRequestToFraudDetectionService(request);
return buildResponseFromFraudResult(response);
}
@@ -42,23 +55,25 @@ public class LoanApplicationService {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
ResponseEntity<FraudServiceResponse> response =
this.restTemplate.exchange("http://localhost:" + this.port + "/fraudcheck", HttpMethod.PUT,
new HttpEntity<>(request, httpHeaders),
FraudServiceResponse.class);
ResponseEntity<FraudServiceResponse> response = this.restTemplate.exchange(
"http://localhost:" + this.port + "/fraudcheck", HttpMethod.PUT,
new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class);
return response.getBody();
}
private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) {
private LoanApplicationResult buildResponseFromFraudResult(
FraudServiceResponse response) {
LoanApplicationStatus applicationStatus = null;
if (FraudCheckStatus.OK == response.getFraudCheckStatus()) {
applicationStatus = LoanApplicationStatus.LOAN_APPLIED;
} else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) {
}
else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) {
applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED;
}
return new LoanApplicationResult(applicationStatus, response.getRejectionReason());
return new LoanApplicationResult(applicationStatus,
response.getRejectionReason());
}
public void setPort(int port) {

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.frauddetection.model;
public class Client {
@@ -11,4 +27,5 @@ public class Client {
public void setPesel(String pesel) {
this.pesel = pesel;
}
}

Some files were not shown because too many files have changed in this diff Show More