Removing deprecations

This commit is contained in:
Marcin Grzejszczak
2017-06-19 18:46:02 +02:00
parent d67e69624a
commit 12ce468b6d
18 changed files with 78 additions and 349 deletions

View File

@@ -1109,7 +1109,7 @@ Example of a `pom.xml` inside the `server` folder.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.BUILD-SNAPSHOT</version>
<version>1.5.4.RELEASE</version>
<relativePath />
</parent>

View File

@@ -40,12 +40,6 @@ public class StubRunner implements StubRunning {
private final StubRunnerOptions stubRunnerOptions;
private final StubRunnerExecutor localStubRunner;
@Deprecated
StubRunner(Arguments arguments) {
this(arguments.getStubRunnerOptions(), arguments.getRepositoryPath(),
arguments.getStub());
}
public StubRunner(StubRunnerOptions stubRunnerOptions, String repositoryPath,
StubConfiguration stubsConfiguration) {
this(stubRunnerOptions, repositoryPath, stubsConfiguration,

View File

@@ -100,14 +100,6 @@ public class StubRunnerOptionsBuilder {
return this;
}
/**
* @deprecated there is no context path for the stub server
*/
@Deprecated
public StubRunnerOptionsBuilder withContextPath(String contextPath) {
return this;
}
public StubRunnerOptionsBuilder withOptions(StubRunnerOptions options) {
this.minPortValue = options.minPortValue;
this.maxPortValue = options.maxPortValue;

View File

@@ -26,7 +26,9 @@ class StubRunnerSpec extends Specification {
def 'should provide stub URL for provided groupid and artifactId'() {
given:
StubRunner runner = new StubRunner(argumentsWithProjectDefinition())
Arguments args = argumentsWithProjectDefinition()
StubRunner runner = new StubRunner(args.stubRunnerOptions,
args.repositoryPath, args.stub)
when:
runner.runStubs()
then:
@@ -37,7 +39,9 @@ class StubRunnerSpec extends Specification {
def 'should provide stub URL if only artifactId was passed'() {
given:
StubRunner runner = new StubRunner(argumentsWithProjectDefinition())
Arguments args = argumentsWithProjectDefinition()
StubRunner runner = new StubRunner(args.stubRunnerOptions,
args.repositoryPath, args.stub)
when:
runner.runStubs()
then:

View File

@@ -1,61 +0,0 @@
/*
* Copyright 2013-2017 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.cloud.contract.spec.Contract
import org.springframework.cloud.contract.verifier.file.ContractMetadata
/**
* Converts contracts into their stub representation.
*
* @since 1.0.0
* @deprecated use {@link StubGenerator}
*/
@CompileStatic
@Deprecated
interface SingleFileConverter {
/**
* Returns {@code true} if the converter can handle the file to convert it into a stub.
*/
boolean canHandleFileName(String fileName)
/**
* Returns the content of the converted file. The content will be a single stub.
*/
@Deprecated
String convertContent(String rootName, ContractMetadata content)
/**
* Returns 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
* 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.
*
* Example: name of file with 2 contracts is {@code foo.groovy}, it will be
* converted by the implementation to {@code foo.json}. The recursive file
* converter will create two files {@code 0_foo.json} and {@code 1_foo.json}
*/
String generateOutputFileNameForInput(String inputFileName)
}

View File

@@ -32,12 +32,6 @@ import java.nio.charset.StandardCharsets
@CompileStatic
class DslToWireMockClientConverter extends DslToWireMockConverter {
@Deprecated
String convertContent(String rootName, ContractMetadata contract) {
return convertASingleContract(rootName, contract, contract.convertedContract.first() ?: createGroovyDSLFromStringContent(
contract.path.getText(StandardCharsets.UTF_8.toString())).first())
}
private String convertASingleContract(String rootName, ContractMetadata contract, Contract dsl) {
return new WireMockStubStrategy(rootName, contract, dsl).toWireMockClientStub()
}

View File

@@ -1,151 +0,0 @@
/*
* Copyright 2013-2017 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.wiremock
import com.google.common.collect.ListMultimap
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
import org.springframework.cloud.contract.verifier.converter.ConversionContractVerifierException
import org.springframework.cloud.contract.verifier.converter.SingleFileConverter
import org.springframework.cloud.contract.verifier.converter.StubGenerator
import org.springframework.cloud.contract.verifier.converter.StubGeneratorProvider
import org.springframework.cloud.contract.verifier.file.ContractFileScanner
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.NamesUtil
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
/**
* Recursively converts contracts into their stub representations
*
* @since 1.0.0
* @deprecated use {@link org.springframework.cloud.contract.verifier.converter.RecursiveFilesConverter}
*/
@Slf4j
@CompileStatic
@Deprecated
class RecursiveFilesConverter {
private final StubGeneratorProvider holder
private final ContractVerifierConfigProperties properties
private final File outMappingsDir
RecursiveFilesConverter(ContractVerifierConfigProperties properties, StubGeneratorProvider holder = null) {
this.properties = properties
this.outMappingsDir = properties.stubsOutputDir
this.holder = holder ?: new StubGeneratorProvider()
}
RecursiveFilesConverter(ContractVerifierConfigProperties properties, File outMappingsDir, StubGeneratorProvider holder = null) {
this.properties = properties
this.outMappingsDir = outMappingsDir
this.holder = holder ?: new StubGeneratorProvider()
}
@Deprecated
RecursiveFilesConverter(SingleFileConverter singleFileConverter, ContractVerifierConfigProperties properties) {
this.properties = properties
this.outMappingsDir = properties.stubsOutputDir
this.holder = new StubGeneratorProvider()
}
@Deprecated
RecursiveFilesConverter(SingleFileConverter singleFileConverter, ContractVerifierConfigProperties properties, File outMappingsDir) {
this.properties = properties
this.outMappingsDir = outMappingsDir
this.holder = new StubGeneratorProvider()
}
void processFiles() {
ContractFileScanner scanner = new ContractFileScanner(properties.contractsDslDir,
properties.excludedFiles as Set, [] as Set, properties.includedContracts)
ListMultimap<Path, ContractMetadata> contracts = scanner.findContracts()
if (log.isDebugEnabled()) {
log.debug("Found the following contracts ${contracts}")
log.debug("Exclude build folder: [${properties.isExcludeBuildFolders()}]")
}
contracts.asMap().entrySet().each { entry ->
entry.value.each { ContractMetadata contract ->
File sourceFile = contract.path.toFile()
StubGenerator stubGenerator = holder.converterForName(sourceFile.name).first()
try {
String path = sourceFile.path
if (properties.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")
}
return
}
if (!contract.convertedContract && !stubGenerator) {
return
}
int contractsSize = contract.convertedContract.size()
Map<Contract, String> convertedContent = stubGenerator.convertContents(entry.key.last().toString(), contract)
if (!convertedContent) {
return
}
convertedContent.entrySet().eachWithIndex { Map.Entry<Contract, String> content, int index ->
Contract dsl = content.key
String converted = content.value
Path absoluteTargetPath = createAndReturnTargetDirectory(sourceFile)
File newJsonFile = createTargetFileWithProperName(stubGenerator, absoluteTargetPath,
sourceFile, contractsSize, index, dsl)
newJsonFile.setText(converted, StandardCharsets.UTF_8.toString())
}
} catch (Exception e) {
throw new ConversionContractVerifierException("Unable to make conversion of ${sourceFile.name}", e)
}
}
}
}
private boolean matchesPath(String path, String folder) {
return path.matches("^.*${File.separator}${folder}${File.separator}.*\$")
}
private Path createAndReturnTargetDirectory(File sourceFile) {
Path relativePath = Paths.get(properties.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) {
String name = generateName(dsl, contractsSize, stubGenerator, sourceFile, index)
File newJsonFile = new File(absoluteTargetPath.toFile(), name)
log.info("Creating new stub [$newJsonFile.path]")
return newJsonFile
}
private String generateName(Contract dsl, int contractsSize, StubGenerator converter,
File sourceFile, int index) {
String generatedName = converter.generateOutputFileNameForInput(sourceFile.name)
String extension = NamesUtil.afterLastDot(generatedName)
if (dsl.name) {
return "${dsl.name}.${extension}"
} else if (contractsSize == 1) {
return generatedName
}
return "${index}_${generatedName}"
}
}

View File

@@ -27,6 +27,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockStubMapping
import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
import org.springframework.http.RequestEntity
import org.springframework.util.SocketUtils
import spock.lang.Issue
@@ -63,7 +64,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
""")
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null)).values().first()
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
JSONAssert.assertEquals('''
{"request":{"method":"PUT","urlPattern":"/[0-9]{2}"},"response":{"status":200}}
@@ -98,7 +100,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
''')
when:
Map<Contract, String> convertedContents = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null))
Map<Contract, String> convertedContents = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file)))
then:
convertedContents.size() == 2
JSONAssert.assertEquals(jsonResponse(1), convertedContents.values().first(), false)
@@ -137,7 +140,9 @@ class DslToWireMockClientConverterSpec extends Specification {
}
''')
when:
Map<Contract, String> convertedContents = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null))
Map<Contract, String> convertedContents = converter.convertContents("Test",
new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file)))
then:
convertedContents.isEmpty()
}
@@ -161,7 +166,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
""")
when:
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null)).values().first()
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
JSONAssert.assertEquals('''
{"request":{
@@ -229,7 +235,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
""")
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null)).values().first()
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
JSONAssert.assertEquals('''
{
@@ -346,7 +353,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
""")
when:
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null)).values().first()
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
JSONAssert.assertEquals('''
{"request":{"urlPath":"/foos","method":"GET"},"response":{"body":"[{\\"id\\":\\"123\\"},{\\"id\\":\\"567\\"}]"}}
@@ -384,7 +392,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
""")
when:
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null)).values().first()
String json = converter.convertContents("test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
noExceptionThrown()
and:
@@ -430,7 +439,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
''')
when:
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null)).values().first()
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
JSONAssert.assertEquals( // tag::wiremock[]
'''
@@ -584,7 +594,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
''')
when:
String json = converter.convertContent("Test", new ContractMetadata(file.toPath(), false, 0, null))
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
JSONAssert.assertEquals(//tag::matchers[]
'''
@@ -737,7 +748,8 @@ class DslToWireMockClientConverterSpec extends Specification {
}
''')
when:
String json = converter.convertContent("Test", new ContractMetadata(file.toPath(), false, 0, null))
String json = converter.convertContents("Test", new ContractMetadata(file.toPath(), false, 0, null,
ContractVerifierDslConverter.convertAsCollection(file))).values().first()
then:
JSONAssert.assertEquals(
'''

View File

@@ -88,12 +88,12 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
def a = ContractVerifierDslConverter.convert(
def a = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
def b = expectedGroovyDsl
a == b
a.first() == b
}
@@ -143,12 +143,12 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
def a = ContractVerifierDslConverter.convert(
def a = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
def b = expectedGroovyDsl
(a.request.url.clientValue as Pattern).pattern() == (b.request.url.clientValue as Pattern).pattern()
(a.first().request.url.clientValue as Pattern).pattern() == (b.request.url.clientValue as Pattern).pattern()
}
def 'should convert WireMock stub with response body containing integer'() {
@@ -196,10 +196,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
ContractVerifierDslConverter.convert(
ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""") == expectedGroovyDsl
}""").first() == expectedGroovyDsl
}
def 'should convert WireMock stub with response body as a list'() {
@@ -253,10 +253,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
ContractVerifierDslConverter.convert(
ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""") == expectedGroovyDsl
}""").first() == expectedGroovyDsl
}
def 'should convert WireMock stub with response body containing a nested list'() {
@@ -318,10 +318,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
ContractVerifierDslConverter.convert(
ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""") == expectedGroovyDsl
}""").first() == expectedGroovyDsl
}
def 'should convert WireMock stub with request body checking equality to Json'() {
@@ -356,10 +356,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert(
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
}""").first()
and:
evaluatedGroovyDsl == expectedGroovyDsl
}
@@ -396,10 +396,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert(
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
}""").first()
and:
(evaluatedGroovyDsl.request.body.clientValue as Pattern).pattern() == (expectedGroovyDsl.request.body.clientValue as Pattern).pattern()
}
@@ -437,10 +437,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert(
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
}""").first()
and:
evaluatedGroovyDsl == expectedGroovyDsl
}
@@ -477,10 +477,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert(
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
}""").first()
and:
evaluatedGroovyDsl == expectedGroovyDsl
}
@@ -517,10 +517,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert(
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
}""").first()
and:
(evaluatedGroovyDsl.request.body.clientValue as Pattern).pattern() == (expectedGroovyDsl.request.body.clientValue as Pattern).pattern()
}
@@ -555,10 +555,10 @@ class WireMockToDslConverterSpec extends Specification {
when:
String groovyDsl = WireMockToDslConverter.fromWireMockStub(wireMockStub)
then:
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convert(
Contract evaluatedGroovyDsl = ContractVerifierDslConverter.convertAsCollection(
"""org.springframework.cloud.contract.spec.Contract.make {
$groovyDsl
}""")
}""").first()
and:
evaluatedGroovyDsl == expectedGroovyDsl
}

View File

@@ -17,6 +17,7 @@
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
@@ -29,7 +30,8 @@ class WiremockScenarioConverterSpec extends Specification {
DslToWireMockClientConverter converter = new DslToWireMockClientConverter()
Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/01_login.groovy").toURI())
when:
String content = converter.convertContents("Test", new ContractMetadata(dsl, false, 3, 0)).values().first()
String content = converter.convertContents("Test", new ContractMetadata(dsl, false, 3, 0,
ContractVerifierDslConverter.convertAsCollection(dsl.toFile()))).values().first()
then:
content.contains('"requiredScenarioState" : "Started"')
content.contains('"newScenarioState" : "Step1"')
@@ -41,7 +43,8 @@ class WiremockScenarioConverterSpec extends Specification {
DslToWireMockClientConverter converter = new DslToWireMockClientConverter()
Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/02_showCart.groovy").toURI())
when:
String content = converter.convertContents("Test", new ContractMetadata(dsl, false, 3, 1)).values().first()
String content = converter.convertContents("Test", new ContractMetadata(dsl, false, 3, 1,
ContractVerifierDslConverter.convertAsCollection(dsl.toFile()))).values().first()
then:
content.contains('"requiredScenarioState" : "Step1"')
content.contains('"newScenarioState" : "Step2"')
@@ -53,7 +56,8 @@ class WiremockScenarioConverterSpec extends Specification {
DslToWireMockClientConverter converter = new DslToWireMockClientConverter()
Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/03_logout.groovy").toURI())
when:
String content = converter.convertContents("Test", new ContractMetadata(dsl, false, 3, 2)).values().first()
String content = converter.convertContents("Test", new ContractMetadata(dsl, false, 3, 2,
ContractVerifierDslConverter.convertAsCollection(dsl.toFile()))).values().first()
then:
content.contains('"requiredScenarioState" : "Step2"')
!content.contains('"newScenarioState"')

View File

@@ -142,6 +142,11 @@
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</plugin>
<plugin>

View File

@@ -302,16 +302,6 @@ abstract class MethodBodyBuilder {
bb.unindent()
}
/**
* Builds the response body verification part. The code will differ depending on the
* ContentType, type of response etc. The result will be appended to {@link BlockBuilder}
* @deprecated - use {@link MethodBodyBuilder#validateResponseBodyBlock(org.springframework.cloud.contract.verifier.builder.BlockBuilder, org.springframework.cloud.contract.spec.internal.BodyMatchers, java.lang.Object)}
*/
@Deprecated
protected void validateResponseBodyBlock(BlockBuilder bb, Object responseBody) {
validateResponseBodyBlock(bb, null, responseBody)
}
/**
* Builds the response body verification part. The code will differ depending on the
* ContentType, type of response etc. The result will be appended to {@link BlockBuilder}

View File

@@ -55,11 +55,6 @@ class ContractMetadata {
*/
final Collection<Contract> convertedContract = []
@Deprecated
ContractMetadata(Path path, boolean ignored, int groupSize, Integer order) {
this(path, ignored, groupSize, order, ContractVerifierDslConverter.convertAsCollection(path.toFile()))
}
ContractMetadata(Path path, boolean ignored, int groupSize, Integer order, Contract convertedContract) {
this(path, ignored, groupSize, order, [convertedContract])
}

View File

@@ -32,26 +32,6 @@ import org.springframework.cloud.contract.spec.Contract
@Slf4j
class ContractVerifierDslConverter {
@Deprecated
static Contract convert(String dsl) {
try {
return groovyShell().evaluate(dsl) as Contract
} catch (Exception e) {
log.error("Exception occurred while trying to evaluate the contract", e)
throw new DslParseException(e)
}
}
@Deprecated
static Contract convert(File dsl) {
try {
return groovyShell().evaluate(dsl) as Contract
} catch (Exception e) {
log.error("Exception occurred while trying to evaluate the contract", e)
throw new DslParseException(e)
}
}
static Collection<Contract> convertAsCollection(String dsl) {
try {
Object object = groovyShell().evaluate(dsl)

View File

@@ -22,6 +22,7 @@ import org.springframework.cloud.contract.verifier.TestGenerator
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
import org.springframework.cloud.contract.verifier.config.TestMode
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
import org.springframework.cloud.contract.verifier.util.SyntaxChecker
import org.springframework.util.StringUtils
import spock.lang.Issue
@@ -186,7 +187,8 @@ class SingleTestGeneratorSpec extends Specification {
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
properties.targetFramework = testFramework
properties.testMode = mode
ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, 2)
ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, 2,
ContractVerifierDslConverter.convertAsCollection(file) )
contract.ignored >> true
contract.order >> 2
JavaTestGenerator testGenerator = new JavaTestGenerator(checker: new ClassPresenceChecker() {
@@ -255,10 +257,12 @@ class SingleTestGeneratorSpec extends Specification {
and:
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
properties.targetFramework = testFramework
ContractMetadata contract = new ContractMetadata(file.toPath(), false, 1, null)
ContractMetadata contract = new ContractMetadata(file.toPath(), false, 1, null,
ContractVerifierDslConverter.convertAsCollection(file) )
contract.ignored >> false
and:
ContractMetadata contract2 = new ContractMetadata(file2.toPath(), false, 1, null)
ContractMetadata contract2 = new ContractMetadata(file2.toPath(), false, 1, null,
ContractVerifierDslConverter.convertAsCollection(file2) )
contract2.ignored >> false
and:
JavaTestGenerator testGenerator = new JavaTestGenerator()
@@ -440,7 +444,8 @@ class SingleTestGeneratorSpec extends Specification {
properties.testMode = TestMode.EXPLICIT
properties.baseClassForTests = "test.ContextPathTestingBaseClass"
and:
ContractMetadata contract = new ContractMetadata(file.toPath(), false, 1, null)
ContractMetadata contract = new ContractMetadata(file.toPath(), false, 1,
null, ContractVerifierDslConverter.convertAsCollection(file))
and:
SingleTestGenerator testGenerator = new JavaTestGenerator()
when:

View File

@@ -69,20 +69,6 @@ class ContractVerifierDslConverterSpec extends Specification {
}
}
def "should convert file to a Contract"() {
when:
Contract contract = ContractVerifierDslConverter.convert(singleContract)
then:
contract == expectedSingleContract
}
def "should throw exception when invalid file is parsed"() {
when:
ContractVerifierDslConverter.convert(invalidContract)
then:
thrown(DslParseException)
}
def "should convert file to a list of Contracts"() {
when:
List<Contract> contract = ContractVerifierDslConverter.convertAsCollection(multipleContracts)
@@ -90,20 +76,6 @@ class ContractVerifierDslConverterSpec extends Specification {
contract == expectedMultipleContracts
}
def "should throw exception when invalid text is parsed"() {
when:
ContractVerifierDslConverter.convert(invalidContract.text)
then:
thrown(DslParseException)
}
def "should convert text to a Contract"() {
when:
Contract contract = ContractVerifierDslConverter.convert(singleContract.text)
then:
contract == expectedSingleContract
}
def "should convert text to a list of Contracts"() {
when:
Collection<Contract> contract = ContractVerifierDslConverter.convertAsCollection(multipleContracts.text)

View File

@@ -44,10 +44,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration.BeanPostProcessorsRegistrar;

View File

@@ -5,6 +5,7 @@ import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -81,9 +82,8 @@ public class ContractDslSnippetTests {
then(file("/contracts/index.groovy")).exists();
then(file("/index/dsl-contract.adoc")).exists();
String contract = readFromFile(file("/contracts/index.groovy"));
// try to parse the contract
Contract parsedContract = ContractVerifierDslConverter.convert(contract);
Collection<Contract> parsedContracts = ContractVerifierDslConverter.convertAsCollection(file("/contracts/index.groovy"));
Contract parsedContract = parsedContracts.iterator().next();
then(parsedContract.getRequest().getHeaders().getEntries()).isNotNull();
then(headerNames(parsedContract.getRequest().getHeaders().getEntries())).doesNotContain
(HttpHeaders.HOST, HttpHeaders.CONTENT_LENGTH);
@@ -105,9 +105,8 @@ public class ContractDslSnippetTests {
then(file("/contracts/empty.groovy")).exists();
then(file("/empty/dsl-contract.adoc")).exists();
String contract = readFromFile(file("/contracts/empty.groovy"));
// try to parse the contract
Contract parsedContract = ContractVerifierDslConverter.convert(contract);
Collection<Contract> parsedContracts = ContractVerifierDslConverter.convertAsCollection(file("/contracts/empty.groovy"));
Contract parsedContract = parsedContracts.iterator().next();
then(parsedContract.getRequest().getHeaders()).isNull();
then(parsedContract.getRequest().getMethod().getClientValue()).isNotNull();
then(parsedContract.getRequest().getUrl().getClientValue()).isNotNull();
@@ -131,11 +130,6 @@ public class ContractDslSnippetTests {
return new File(OUTPUT, name);
}
private String readFromFile(File f) throws IOException {
byte[] encoded = Files.readAllBytes(f.toPath());
return new String(encoded, StandardCharsets.UTF_8);
}
@Configuration
@EnableAutoConfiguration
@RestController