Fixed wrong conditional on missing beans for messaging; fixes gh-1513
This commit is contained in:
@@ -121,7 +121,7 @@ public class RecursiveFilesConverter {
|
||||
File sourceFile = contract.getPath().toFile();
|
||||
Collection<StubGenerator> stubGenerators = contract.getConvertedContract() != null
|
||||
? holder.allOrDefault(new DslToWireMockClientConverter())
|
||||
: holder.converterForName(sourceFile.getName());
|
||||
: holder.converterForName(sourceFile.getAbsolutePath());
|
||||
try {
|
||||
String path = sourceFile.getPath();
|
||||
if (excludeBuildFolders && (matchesPath(path, "target") || matchesPath(path, "build"))) {
|
||||
|
||||
@@ -32,12 +32,12 @@ import org.springframework.cloud.contract.verifier.file.ContractMetadata;
|
||||
public interface StubGenerator<T> {
|
||||
|
||||
/**
|
||||
* @param fileName - file name
|
||||
* @return {@code true} if the converter can handle the file to convert it into a
|
||||
* stub.
|
||||
* @param fileName - file name or absolute path of a contract
|
||||
* @return {@code true} if the converter can handle the contract file to convert it
|
||||
* into a stub.
|
||||
*/
|
||||
default boolean canHandleFileName(String fileName) {
|
||||
return fileName.endsWith(fileExtension());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,8 @@ public interface StubGenerator<T> {
|
||||
* @param inputFileName - name of the input file
|
||||
* @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.
|
||||
* {@link Contract#getName()} 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
|
||||
@@ -90,8 +91,8 @@ public interface StubGenerator<T> {
|
||||
String generateOutputFileNameForInput(String inputFileName);
|
||||
|
||||
/**
|
||||
* Describes the file extension that this stub generator can handle.
|
||||
* @return string describing the file extension
|
||||
* Describes the file extension that this stub generator will generate.
|
||||
* @return string describing the file extension starting with a dot
|
||||
*/
|
||||
default String fileExtension() {
|
||||
return ".json";
|
||||
|
||||
@@ -32,6 +32,8 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
*/
|
||||
public class StubGeneratorProvider {
|
||||
|
||||
private final List<StubGenerator> converters = new ArrayList<StubGenerator>();
|
||||
|
||||
public StubGeneratorProvider() {
|
||||
this.converters.addAll(SpringFactoriesLoader.loadFactories(StubGenerator.class, null));
|
||||
}
|
||||
@@ -49,6 +51,4 @@ public class StubGeneratorProvider {
|
||||
return this.converters.isEmpty() ? Collections.singletonList(defaultStubGenerator) : this.converters;
|
||||
}
|
||||
|
||||
private final List<StubGenerator> converters = new ArrayList<StubGenerator>();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.wiremock;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
|
||||
|
||||
import org.springframework.cloud.contract.verifier.converter.StubGenerator;
|
||||
@@ -40,4 +43,18 @@ public abstract class DslToWireMockConverter implements StubGenerator<StubMappin
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHandleFileName(String fileName) {
|
||||
if (!fileName.endsWith(fileExtension())) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
StubMapping.buildFrom(new String(Files.readAllBytes(new File(fileName).toPath())));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user