Bumping versions
This commit is contained in:
@@ -35,13 +35,13 @@ public class GroovyDslPropertyConverter implements DslPropertyConverter {
|
|||||||
public Object testSide(Object object) {
|
public Object testSide(Object object) {
|
||||||
if (object instanceof GString) {
|
if (object instanceof GString) {
|
||||||
boolean anyPattern = Arrays.stream(((GString) object).getValues())
|
boolean anyPattern = Arrays.stream(((GString) object).getValues())
|
||||||
.anyMatch(it -> it instanceof RegexProperty);
|
.anyMatch(it -> it instanceof RegexProperty);
|
||||||
if (!anyPattern) {
|
if (!anyPattern) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
List<Object> generatedValues = Arrays.stream(((GString) object).getValues())
|
List<Object> generatedValues = Arrays.stream(((GString) object).getValues())
|
||||||
.map(it -> it instanceof RegexProperty ? ((RegexProperty) it).generate() : it)
|
.map(it -> it instanceof RegexProperty ? ((RegexProperty) it).generate() : it)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
Object[] arrayOfObjects = generatedValues.toArray();
|
Object[] arrayOfObjects = generatedValues.toArray();
|
||||||
String[] strings = Arrays.copyOf(((GString) object).getStrings(), ((GString) object).getStrings().length,
|
String[] strings = Arrays.copyOf(((GString) object).getStrings(), ((GString) object).getStrings().length,
|
||||||
String[].class);
|
String[].class);
|
||||||
|
|||||||
@@ -40,10 +40,11 @@ import java.util.stream.Collectors;
|
|||||||
public class Common {
|
public class Common {
|
||||||
|
|
||||||
public Map<String, DslProperty> convertObjectsToDslProperties(Map<String, Object> body) {
|
public Map<String, DslProperty> convertObjectsToDslProperties(Map<String, Object> body) {
|
||||||
return body.entrySet().stream()
|
return body.entrySet()
|
||||||
.collect(Collectors.toMap((Function<Map.Entry, String>) t -> t.getKey().toString(),
|
.stream()
|
||||||
(Function<Map.Entry, DslProperty>) t -> toDslProperty(t.getValue()), throwingMerger(),
|
.collect(Collectors.toMap((Function<Map.Entry, String>) t -> t.getKey().toString(),
|
||||||
LinkedHashMap::new));
|
(Function<Map.Entry, DslProperty>) t -> toDslProperty(t.getValue()), throwingMerger(),
|
||||||
|
LinkedHashMap::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> BinaryOperator<T> throwingMerger() {
|
private static <T> BinaryOperator<T> throwingMerger() {
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ import java.util.regex.Pattern;
|
|||||||
public class Headers {
|
public class Headers {
|
||||||
|
|
||||||
private static final BiFunction<String, Header, Object> CLIENT_SIDE = (s, header) -> ContractUtils
|
private static final BiFunction<String, Header, Object> CLIENT_SIDE = (s, header) -> ContractUtils
|
||||||
.convertStubSideRecursively(header);
|
.convertStubSideRecursively(header);
|
||||||
|
|
||||||
private static final BiFunction<String, Header, Object> SERVER_SIDE = (s, header) -> ContractUtils
|
private static final BiFunction<String, Header, Object> SERVER_SIDE = (s, header) -> ContractUtils
|
||||||
.convertTestSideRecursively(header);
|
.convertTestSideRecursively(header);
|
||||||
|
|
||||||
private Set<Header> entries = new LinkedHashSet<>();
|
private Set<Header> entries = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
|||||||
@@ -68,16 +68,16 @@ public final class RegexPatterns {
|
|||||||
protected static final Pattern HTTPS_URL = UrlHelper.HTTPS_URL;
|
protected static final Pattern HTTPS_URL = UrlHelper.HTTPS_URL;
|
||||||
|
|
||||||
protected static final Pattern UUID = Pattern
|
protected static final Pattern UUID = Pattern
|
||||||
.compile("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}", Pattern.CASE_INSENSITIVE);
|
.compile("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
protected static final Pattern UUID4 = Pattern
|
protected static final Pattern UUID4 = Pattern
|
||||||
.compile("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}", Pattern.CASE_INSENSITIVE);
|
.compile("[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
protected static final Pattern ANY_DATE = Pattern
|
protected static final Pattern ANY_DATE = Pattern
|
||||||
.compile("(\\d\\d\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])");
|
.compile("(\\d\\d\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])");
|
||||||
|
|
||||||
protected static final Pattern ANY_DATE_TIME = Pattern.compile(
|
protected static final Pattern ANY_DATE_TIME = Pattern
|
||||||
"([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])");
|
.compile("([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])");
|
||||||
|
|
||||||
protected static final Pattern ANY_TIME = Pattern.compile("(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])");
|
protected static final Pattern ANY_TIME = Pattern.compile("(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])");
|
||||||
|
|
||||||
@@ -89,9 +89,9 @@ public final class RegexPatterns {
|
|||||||
"([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.\\d+)?(Z|[+-][01]\\d:[0-5]\\d)");
|
"([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\\.\\d+)?(Z|[+-][01]\\d:[0-5]\\d)");
|
||||||
|
|
||||||
protected static Pattern anyOf(String... values) {
|
protected static Pattern anyOf(String... values) {
|
||||||
return Pattern
|
return Pattern.compile(Arrays.stream(values)
|
||||||
.compile(Arrays.stream(values).map(it -> '^' + RegexpUtils.escapeSpecialRegexWithSingleEscape(it) + '$')
|
.map(it -> '^' + RegexpUtils.escapeSpecialRegexWithSingleEscape(it) + '$')
|
||||||
.collect(Collectors.joining("|")));
|
.collect(Collectors.joining("|")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String multipartParam(Object name, Object value) {
|
public static String multipartParam(Object name, Object value) {
|
||||||
|
|||||||
@@ -742,8 +742,8 @@ public class Response extends Common implements RegexCreatingProperty<ServerDslP
|
|||||||
@Override
|
@Override
|
||||||
public DslProperty matching(final String value) {
|
public DslProperty matching(final String value) {
|
||||||
return this.common.$(
|
return this.common.$(
|
||||||
this.common.p(
|
this.common
|
||||||
notEscaped(Pattern.compile(RegexpUtils.escapeSpecialRegexWithSingleEscape(value) + ".*"))),
|
.p(notEscaped(Pattern.compile(RegexpUtils.escapeSpecialRegexWithSingleEscape(value) + ".*"))),
|
||||||
this.common.c(value));
|
this.common.c(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ public class Xeger {
|
|||||||
assert random != null;
|
assert random != null;
|
||||||
// https://stackoverflow.com/questions/1578789/how-do-i-generate-text-matching-a-regular-expression-from-a-regular-expression
|
// https://stackoverflow.com/questions/1578789/how-do-i-generate-text-matching-a-regular-expression-from-a-regular-expression
|
||||||
String pattern = regex.replace("\\d", "[0-9]") // Used d=Digit
|
String pattern = regex.replace("\\d", "[0-9]") // Used d=Digit
|
||||||
.replace("\\w", "[A-Za-z0-9_]") // Used =Word
|
.replace("\\w", "[A-Za-z0-9_]") // Used =Word
|
||||||
.replace("\\s", "[ \t\r\n]"); // Used s="White"Space
|
.replace("\\s", "[ \t\r\n]"); // Used s="White"Space
|
||||||
this.automaton = new RegExp(pattern).toAutomaton();
|
this.automaton = new RegExp(pattern).toAutomaton();
|
||||||
this.random = random;
|
this.random = random;
|
||||||
String generatedCharsSysProp = System.getProperty("springCloudContractGeneratedCharsFromRegex");
|
String generatedCharsSysProp = System.getProperty("springCloudContractGeneratedCharsFromRegex");
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class AetherStubDownloader implements StubDownloader {
|
|||||||
for (int i = 0; i < repos.length; i++) {
|
for (int i = 0; i < repos.length; i++) {
|
||||||
if (StringUtils.hasText(repos[i])) {
|
if (StringUtils.hasText(repos[i])) {
|
||||||
final RemoteRepository.Builder builder = new RemoteRepository.Builder("remote" + i, "default", repos[i])
|
final RemoteRepository.Builder builder = new RemoteRepository.Builder("remote" + i, "default", repos[i])
|
||||||
.setAuthentication(resolveAuthentication(stubRunnerOptions));
|
.setAuthentication(resolveAuthentication(stubRunnerOptions));
|
||||||
if (stubRunnerOptions.getProxyOptions() != null) {
|
if (stubRunnerOptions.getProxyOptions() != null) {
|
||||||
final StubRunnerProxyOptions p = stubRunnerOptions.getProxyOptions();
|
final StubRunnerProxyOptions p = stubRunnerOptions.getProxyOptions();
|
||||||
builder.setProxy(new Proxy(null, p.getProxyHost(), p.getProxyPort()));
|
builder.setProxy(new Proxy(null, p.getProxyHost(), p.getProxyPort()));
|
||||||
@@ -176,7 +176,9 @@ public class AetherStubDownloader implements StubDownloader {
|
|||||||
}
|
}
|
||||||
SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(stubServer);
|
SettingsDecryptionRequest settingsDecryptionRequest = new DefaultSettingsDecryptionRequest(stubServer);
|
||||||
String stubServerPassword = new MavenSettings().createSettingsDecrypter()
|
String stubServerPassword = new MavenSettings().createSettingsDecrypter()
|
||||||
.decrypt(settingsDecryptionRequest).getServer().getPassword();
|
.decrypt(settingsDecryptionRequest)
|
||||||
|
.getServer()
|
||||||
|
.getPassword();
|
||||||
return buildAuthentication(stubServerPassword, stubServer.getUsername());
|
return buildAuthentication(stubServerPassword, stubServer.getUsername());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,8 +274,9 @@ public class AetherStubDownloader implements StubDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerShutdownHook() {
|
private void registerShutdownHook() {
|
||||||
Runtime.getRuntime().addShutdownHook(
|
Runtime.getRuntime()
|
||||||
new Thread(() -> TemporaryFileStorage.cleanup(AetherStubDownloader.this.deleteStubsAfterTest)));
|
.addShutdownHook(
|
||||||
|
new Thread(() -> TemporaryFileStorage.cleanup(AetherStubDownloader.this.deleteStubsAfterTest)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class ContractDownloader {
|
|||||||
log.debug("Will download contracts for [" + this.contractsJarStubConfiguration + "]");
|
log.debug("Will download contracts for [" + this.contractsJarStubConfiguration + "]");
|
||||||
}
|
}
|
||||||
Map.Entry<StubConfiguration, File> unpackedContractStubs = this.stubDownloader
|
Map.Entry<StubConfiguration, File> unpackedContractStubs = this.stubDownloader
|
||||||
.downloadAndUnpackStubJar(this.contractsJarStubConfiguration);
|
.downloadAndUnpackStubJar(this.contractsJarStubConfiguration);
|
||||||
if (unpackedContractStubs == null) {
|
if (unpackedContractStubs == null) {
|
||||||
throw new IllegalStateException("The contracts failed to be downloaded!");
|
throw new IllegalStateException("The contracts failed to be downloaded!");
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,8 @@ public class ContractDownloader {
|
|||||||
|
|
||||||
private String patternFromProperty(File contractsDirectory) {
|
private String patternFromProperty(File contractsDirectory) {
|
||||||
return ("^" + contractsDirectory.getAbsolutePath() + "(" + File.separator + ")?" + ".*"
|
return ("^" + contractsDirectory.getAbsolutePath() + "(" + File.separator + ")?" + ".*"
|
||||||
+ contractsPath().replace("/", File.separator) + ".*$").replace("\\", "\\\\");
|
+ contractsPath().replace("/", File.separator) + ".*$")
|
||||||
|
.replace("\\", "\\\\");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String contractsPath() {
|
private String contractsPath() {
|
||||||
@@ -165,7 +166,7 @@ public class ContractDownloader {
|
|||||||
private String groupArtifactToPattern(File contractsDirectory) {
|
private String groupArtifactToPattern(File contractsDirectory) {
|
||||||
return ("^" + contractsDirectory.getAbsolutePath() + "(" + File.separator + ")?" + ".*"
|
return ("^" + contractsDirectory.getAbsolutePath() + "(" + File.separator + ")?" + ".*"
|
||||||
+ slashSeparatedGroupId() + File.separator + this.projectArtifactId + File.separator + ".*$")
|
+ slashSeparatedGroupId() + File.separator + this.projectArtifactId + File.separator + ".*$")
|
||||||
.replace("\\", "\\\\");
|
.replace("\\", "\\\\");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String fileToPattern(File contractsDirectory) {
|
private String fileToPattern(File contractsDirectory) {
|
||||||
|
|||||||
@@ -152,10 +152,11 @@ class StubsStubDownloader implements StubDownloader {
|
|||||||
String schemeSpecific = schemeSpecificPart();
|
String schemeSpecific = schemeSpecificPart();
|
||||||
log.info("Stubs are present under [" + schemeSpecific + "]. Will copy them to a temporary directory.");
|
log.info("Stubs are present under [" + schemeSpecific + "]. Will copy them to a temporary directory.");
|
||||||
return new ResourceResolvingStubDownloader(stubRunnerOptions, this::repoRootForSchemeSpecificPart,
|
return new ResourceResolvingStubDownloader(stubRunnerOptions, this::repoRootForSchemeSpecificPart,
|
||||||
this::anyPattern).downloadAndUnpackStubJar(stubConfiguration);
|
this::anyPattern)
|
||||||
|
.downloadAndUnpackStubJar(stubConfiguration);
|
||||||
}
|
}
|
||||||
return new ResourceResolvingStubDownloader(stubRunnerOptions, this::repoRoot, this::gavPattern)
|
return new ResourceResolvingStubDownloader(stubRunnerOptions, this::repoRoot, this::gavPattern)
|
||||||
.downloadAndUnpackStubJar(stubConfiguration);
|
.downloadAndUnpackStubJar(stubConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RepoRoots repoRootForSchemeSpecificPart(StubRunnerOptions stubRunnerOptions,
|
private RepoRoots repoRootForSchemeSpecificPart(StubRunnerOptions stubRunnerOptions,
|
||||||
|
|||||||
@@ -219,8 +219,9 @@ class GitRepo {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Project git url [" + projectGitUrl + "]");
|
log.debug("Project git url [" + projectGitUrl + "]");
|
||||||
}
|
}
|
||||||
CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository().setURI(projectGitUrl)
|
CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository()
|
||||||
.setDirectory(destinationFolder);
|
.setURI(projectGitUrl)
|
||||||
|
.setDirectory(destinationFolder);
|
||||||
try {
|
try {
|
||||||
Git git = command.call();
|
Git git = command.call();
|
||||||
if (git.getRepository().getRemoteNames().isEmpty()) {
|
if (git.getRepository().getRemoteNames().isEmpty()) {
|
||||||
@@ -278,8 +279,10 @@ class GitRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void trackBranch(CheckoutCommand checkout, String label) {
|
private void trackBranch(CheckoutCommand checkout, String label) {
|
||||||
checkout.setCreateBranch(true).setName(label).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
|
checkout.setCreateBranch(true)
|
||||||
.setStartPoint("origin/" + label);
|
.setName(label)
|
||||||
|
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
|
||||||
|
.setStartPoint("origin/" + label);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBranch(Git git, String label) throws GitAPIException {
|
private boolean isBranch(Git git, String label) throws GitAPIException {
|
||||||
@@ -389,8 +392,9 @@ class GitRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CloneCommand getCloneCommandByCloneRepository() {
|
CloneCommand getCloneCommandByCloneRepository() {
|
||||||
return Git.cloneRepository().setCredentialsProvider(this.provider)
|
return Git.cloneRepository()
|
||||||
.setTransportConfigCallback(this.callback);
|
.setCredentialsProvider(this.provider)
|
||||||
|
.setTransportConfigCallback(this.callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
PushCommand push(Git git) {
|
PushCommand push(Git git) {
|
||||||
|
|||||||
@@ -109,8 +109,9 @@ class ResourceResolvingStubDownloader implements StubDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerShutdownHook() {
|
private void registerShutdownHook() {
|
||||||
Runtime.getRuntime().addShutdownHook(
|
Runtime.getRuntime()
|
||||||
new Thread(() -> TemporaryFileStorage.cleanup(stubRunnerOptions.isDeleteStubsAfterTest())));
|
.addShutdownHook(
|
||||||
|
new Thread(() -> TemporaryFileStorage.cleanup(stubRunnerOptions.isDeleteStubsAfterTest())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyTheFoundFiles(File tmp, Resource resource, String relativePath) throws IOException {
|
private void copyTheFoundFiles(File tmp, Resource resource, String relativePath) throws IOException {
|
||||||
|
|||||||
@@ -203,8 +203,9 @@ class GitStubDownloader implements StubDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerShutdownHook() {
|
private void registerShutdownHook() {
|
||||||
Runtime.getRuntime().addShutdownHook(
|
Runtime.getRuntime()
|
||||||
new Thread(() -> TemporaryFileStorage.cleanup(GitStubDownloader.this.deleteStubsAfterTest)));
|
.addShutdownHook(
|
||||||
|
new Thread(() -> TemporaryFileStorage.cleanup(GitStubDownloader.this.deleteStubsAfterTest)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -351,9 +352,10 @@ class FileWalker extends SimpleFileVisitor<Path> {
|
|||||||
if (versions.size() > 1 && this.latestSnapshotVersion) {
|
if (versions.size() > 1 && this.latestSnapshotVersion) {
|
||||||
// 2.0.1.BUILD-SNAPSHOT, 2.0.0.BUILD-SNAPSHOT
|
// 2.0.1.BUILD-SNAPSHOT, 2.0.0.BUILD-SNAPSHOT
|
||||||
// 2.0.0.BUILD-SNAPSHOT, 2.0.0.RELEASE
|
// 2.0.0.BUILD-SNAPSHOT, 2.0.0.RELEASE
|
||||||
DefaultArtifactVersionWrapper sameVersionButSnapshot = versions.stream().filter(
|
DefaultArtifactVersionWrapper sameVersionButSnapshot = versions.stream()
|
||||||
w -> w.projectVersion.isSameWithoutSuffix(latestFoundVersion.projectVersion) && w.isSnapshot())
|
.filter(w -> w.projectVersion.isSameWithoutSuffix(latestFoundVersion.projectVersion) && w.isSnapshot())
|
||||||
.findFirst().orElse(latestFoundVersion);
|
.findFirst()
|
||||||
|
.orElse(latestFoundVersion);
|
||||||
// 2.0.0 vs 2.0.0
|
// 2.0.0 vs 2.0.0
|
||||||
// replace the RELEASE one with SNAPSHOT
|
// replace the RELEASE one with SNAPSHOT
|
||||||
if (sameVersionButSnapshot != latestFoundVersion) {
|
if (sameVersionButSnapshot != latestFoundVersion) {
|
||||||
@@ -366,17 +368,22 @@ class FileWalker extends SimpleFileVisitor<Path> {
|
|||||||
private File folderWithPredefinedName(File[] files) {
|
private File folderWithPredefinedName(File[] files) {
|
||||||
if (this.latestSnapshotVersion) {
|
if (this.latestSnapshotVersion) {
|
||||||
return Arrays.stream(files)
|
return Arrays.stream(files)
|
||||||
.filter(file -> LATEST.stream().anyMatch(s -> s.equals(file.getName().toLowerCase()))).findFirst()
|
.filter(file -> LATEST.stream().anyMatch(s -> s.equals(file.getName().toLowerCase())))
|
||||||
.orElse(null);
|
.findFirst()
|
||||||
}
|
|
||||||
return Arrays.stream(files).filter(file -> RELEASE.equals(file.getName().toLowerCase())).findFirst()
|
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
}
|
||||||
|
return Arrays.stream(files)
|
||||||
|
.filter(file -> RELEASE.equals(file.getName().toLowerCase()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DefaultArtifactVersionWrapper> pickLatestVersion(File[] files) {
|
private List<DefaultArtifactVersionWrapper> pickLatestVersion(File[] files) {
|
||||||
return Arrays.stream(files).map(DefaultArtifactVersionWrapper::new)
|
return Arrays.stream(files)
|
||||||
.filter(wrapper -> this.latestSnapshotVersion || wrapper.isNotSnapshot()).sorted()
|
.map(DefaultArtifactVersionWrapper::new)
|
||||||
.collect(Collectors.toList());
|
.filter(wrapper -> this.latestSnapshotVersion || wrapper.isNotSnapshot())
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class StubRunnerExecutor implements StubFinder {
|
|||||||
return runningStubs();
|
return runningStubs();
|
||||||
}
|
}
|
||||||
HttpServerStubConfigurer configurer = BeanUtils
|
HttpServerStubConfigurer configurer = BeanUtils
|
||||||
.instantiateClass(stubRunnerOptions.getHttpServerStubConfigurer());
|
.instantiateClass(stubRunnerOptions.getHttpServerStubConfigurer());
|
||||||
startStubServers(configurer, stubRunnerOptions, stubConfiguration, repository);
|
startStubServers(configurer, stubRunnerOptions, stubConfiguration, repository);
|
||||||
RunningStubs runningCollaborators = runningStubs();
|
RunningStubs runningCollaborators = runningStubs();
|
||||||
log.info("All stubs are now running " + runningCollaborators.toString());
|
log.info("All stubs are now running " + runningCollaborators.toString());
|
||||||
@@ -262,7 +262,7 @@ class StubRunnerExecutor implements StubFinder {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
payload = JsonOutput
|
payload = JsonOutput
|
||||||
.toJson(BodyExtractor.extractClientValueFromBody(body == null ? null : body.getClientValue()));
|
.toJson(BodyExtractor.extractClientValueFromBody(body == null ? null : body.getClientValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messageVerifierSender.send(payload, headers == null ? null : headers.asStubSideMap(),
|
this.messageVerifierSender.send(payload, headers == null ? null : headers.asStubSideMap(),
|
||||||
@@ -291,20 +291,20 @@ class StubRunnerExecutor implements StubFinder {
|
|||||||
log.debug("There are no HTTP related contracts. Won't start any servers");
|
log.debug("There are no HTTP related contracts. Won't start any servers");
|
||||||
}
|
}
|
||||||
this.stubServer = new StubServer(stubConfiguration, mappings, contracts, new NoOpHttpServerStub())
|
this.stubServer = new StubServer(stubConfiguration, mappings, contracts, new NoOpHttpServerStub())
|
||||||
.start(configuration);
|
.start(configuration);
|
||||||
return this.stubServer;
|
return this.stubServer;
|
||||||
}
|
}
|
||||||
if (!randomPort) {
|
if (!randomPort) {
|
||||||
this.stubServer = new StubServer(stubConfiguration, mappings, contracts, httpServerStub())
|
this.stubServer = new StubServer(stubConfiguration, mappings, contracts, httpServerStub())
|
||||||
.start(configuration);
|
.start(configuration);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.stubServer = this.portScanner.tryToExecuteWithFreePort(new PortCallback<StubServer>() {
|
this.stubServer = this.portScanner.tryToExecuteWithFreePort(new PortCallback<StubServer>() {
|
||||||
@Override
|
@Override
|
||||||
public StubServer call(int availablePort) {
|
public StubServer call(int availablePort) {
|
||||||
return new StubServer(stubConfiguration, mappings, contracts, httpServerStub())
|
return new StubServer(stubConfiguration, mappings, contracts, httpServerStub())
|
||||||
.start(new HttpServerStubConfiguration(configurer, stubRunnerOptions, stubConfiguration,
|
.start(new HttpServerStubConfiguration(configurer, stubRunnerOptions, stubConfiguration,
|
||||||
availablePort, true));
|
availablePort, true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class StubRunnerFactory {
|
|||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||||
File potentialStubMapping = file.toFile();
|
File potentialStubMapping = file.toFile();
|
||||||
Collection<StubGenerator> stubGenerators = this.provider
|
Collection<StubGenerator> stubGenerators = this.provider
|
||||||
.allOrDefault(new DslToWireMockClientConverter());
|
.allOrDefault(new DslToWireMockClientConverter());
|
||||||
if (stubGenerators.stream().anyMatch(s -> s.canReadStubMapping(potentialStubMapping))) {
|
if (stubGenerators.stream().anyMatch(s -> s.canReadStubMapping(potentialStubMapping))) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Deleting file [" + file.toString() + "] since it contains a valid mapping.");
|
log.debug("Deleting file [" + file.toString() + "] since it contains a valid mapping.");
|
||||||
|
|||||||
@@ -170,22 +170,23 @@ public class StubRunnerOptions {
|
|||||||
|
|
||||||
public static StubRunnerOptions fromSystemProps() {
|
public static StubRunnerOptions fromSystemProps() {
|
||||||
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
||||||
.withMinPort(Integer.valueOf(System.getProperty("stubrunner.port.range.min", "10000")))
|
.withMinPort(Integer.valueOf(System.getProperty("stubrunner.port.range.min", "10000")))
|
||||||
.withMaxPort(Integer.valueOf(System.getProperty("stubrunner.port.range.max", "15000")))
|
.withMaxPort(Integer.valueOf(System.getProperty("stubrunner.port.range.max", "15000")))
|
||||||
.withStubRepositoryRoot(ResourceResolver.resource(System.getProperty("stubrunner.repository.root", "")))
|
.withStubRepositoryRoot(ResourceResolver.resource(System.getProperty("stubrunner.repository.root", "")))
|
||||||
.withStubsMode(System.getProperty("stubrunner.stubs-mode", "LOCAL"))
|
.withStubsMode(System.getProperty("stubrunner.stubs-mode", "LOCAL"))
|
||||||
.withStubsClassifier(System.getProperty("stubrunner.classifier", "stubs"))
|
.withStubsClassifier(System.getProperty("stubrunner.classifier", "stubs"))
|
||||||
.withStubs(System.getProperty("stubrunner.ids", ""))
|
.withStubs(System.getProperty("stubrunner.ids", ""))
|
||||||
.withUsername(System.getProperty("stubrunner.username"))
|
.withUsername(System.getProperty("stubrunner.username"))
|
||||||
.withPassword(System.getProperty("stubrunner.password"))
|
.withPassword(System.getProperty("stubrunner.password"))
|
||||||
.withStubPerConsumer(Boolean.parseBoolean(System.getProperty("stubrunner.stubs-per-consumer", "false")))
|
.withStubPerConsumer(Boolean.parseBoolean(System.getProperty("stubrunner.stubs-per-consumer", "false")))
|
||||||
.withConsumerName(System.getProperty("stubrunner.consumer-name"))
|
.withConsumerName(System.getProperty("stubrunner.consumer-name"))
|
||||||
.withMappingsOutputFolder(System.getProperty("stubrunner.mappings-output-folder"))
|
.withMappingsOutputFolder(System.getProperty("stubrunner.mappings-output-folder"))
|
||||||
.withDeleteStubsAfterTest(
|
.withDeleteStubsAfterTest(
|
||||||
Boolean.parseBoolean(System.getProperty("stubrunner.delete-stubs-after-test", "true")))
|
Boolean.parseBoolean(System.getProperty("stubrunner.delete-stubs-after-test", "true")))
|
||||||
.withGenerateStubs(Boolean.parseBoolean(System.getProperty("stubrunner.generate-stubs", "false")))
|
.withGenerateStubs(Boolean.parseBoolean(System.getProperty("stubrunner.generate-stubs", "false")))
|
||||||
.withFailOnNoStubs(Boolean.parseBoolean(System.getProperty("stubrunner.fail-on-no-stubs", "false")))
|
.withFailOnNoStubs(Boolean.parseBoolean(System.getProperty("stubrunner.fail-on-no-stubs", "false")))
|
||||||
.withProperties(stubRunnerProps()).withServerId(System.getProperty("stubrunner.server-id", ""));
|
.withProperties(stubRunnerProps())
|
||||||
|
.withServerId(System.getProperty("stubrunner.server-id", ""));
|
||||||
builder = httpStubConfigurer(builder);
|
builder = httpStubConfigurer(builder);
|
||||||
String proxyHost = System.getProperty("stubrunner.proxy.host");
|
String proxyHost = System.getProperty("stubrunner.proxy.host");
|
||||||
if (proxyHost != null) {
|
if (proxyHost != null) {
|
||||||
@@ -211,10 +212,10 @@ public class StubRunnerOptions {
|
|||||||
Properties properties = System.getProperties();
|
Properties properties = System.getProperties();
|
||||||
Set<String> propertyNames = properties.stringPropertyNames();
|
Set<String> propertyNames = properties.stringPropertyNames();
|
||||||
propertyNames.stream()
|
propertyNames.stream()
|
||||||
// stubrunner.properties.foo.bar=baz
|
// stubrunner.properties.foo.bar=baz
|
||||||
.filter(s -> s.toLowerCase().startsWith("stubrunner.properties"))
|
.filter(s -> s.toLowerCase().startsWith("stubrunner.properties"))
|
||||||
// foo.bar=baz
|
// foo.bar=baz
|
||||||
.forEach(s -> map.put(s.substring("stubrunner.properties".length() + 1), System.getProperty(s)));
|
.forEach(s -> map.put(s.substring("stubrunner.properties".length() + 1), System.getProperty(s)));
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation to enable a Stub runner server.
|
* Annotation to enable a Stub runner server.
|
||||||
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Tim Ysewyn
|
* @author Tim Ysewyn
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ public class StubRunnerConfiguration {
|
|||||||
}
|
}
|
||||||
StubRunnerOptions stubRunnerOptions = stubRunnerOptions(builder);
|
StubRunnerOptions stubRunnerOptions = stubRunnerOptions(builder);
|
||||||
BatchStubRunner batchStubRunner = new BatchStubRunnerFactory(stubRunnerOptions,
|
BatchStubRunner batchStubRunner = new BatchStubRunnerFactory(stubRunnerOptions,
|
||||||
this.provider.get(stubRunnerOptions), new LazyMessageVerifier(beanFactory)).buildBatchStubRunner();
|
this.provider.get(stubRunnerOptions), new LazyMessageVerifier(beanFactory))
|
||||||
|
.buildBatchStubRunner();
|
||||||
// TODO: Consider running it in a separate thread
|
// TODO: Consider running it in a separate thread
|
||||||
RunningStubs runningStubs = batchStubRunner.runStubs();
|
RunningStubs runningStubs = batchStubRunner.runStubs();
|
||||||
registerPort(runningStubs);
|
registerPort(runningStubs);
|
||||||
@@ -101,20 +102,23 @@ public class StubRunnerConfiguration {
|
|||||||
|
|
||||||
private StubRunnerOptionsBuilder builder(StubRunnerProperties props) {
|
private StubRunnerOptionsBuilder builder(StubRunnerProperties props) {
|
||||||
return new StubRunnerOptionsBuilder()
|
return new StubRunnerOptionsBuilder()
|
||||||
.withMinMaxPort(Integer.valueOf(resolvePlaceholder(props.getMinPort(), props.getMinPort())),
|
.withMinMaxPort(Integer.valueOf(resolvePlaceholder(props.getMinPort(), props.getMinPort())),
|
||||||
Integer.valueOf(resolvePlaceholder(props.getMaxPort(), props.getMaxPort())))
|
Integer.valueOf(resolvePlaceholder(props.getMaxPort(), props.getMaxPort())))
|
||||||
.withStubRepositoryRoot(props.getRepositoryRoot())
|
.withStubRepositoryRoot(props.getRepositoryRoot())
|
||||||
.withStubsMode(resolvePlaceholder(props.getStubsMode()))
|
.withStubsMode(resolvePlaceholder(props.getStubsMode()))
|
||||||
.withStubsClassifier(resolvePlaceholder(props.getClassifier()))
|
.withStubsClassifier(resolvePlaceholder(props.getClassifier()))
|
||||||
.withStubs(resolvePlaceholder(props.getIds())).withUsername(resolvePlaceholder(props.getUsername()))
|
.withStubs(resolvePlaceholder(props.getIds()))
|
||||||
.withPassword(resolvePlaceholder(props.getPassword()))
|
.withUsername(resolvePlaceholder(props.getUsername()))
|
||||||
.withStubPerConsumer(Boolean.parseBoolean(resolvePlaceholder(props.isStubsPerConsumer())))
|
.withPassword(resolvePlaceholder(props.getPassword()))
|
||||||
.withConsumerName(consumerName(props))
|
.withStubPerConsumer(Boolean.parseBoolean(resolvePlaceholder(props.isStubsPerConsumer())))
|
||||||
.withMappingsOutputFolder(resolvePlaceholder(props.getMappingsOutputFolder()))
|
.withConsumerName(consumerName(props))
|
||||||
.withDeleteStubsAfterTest(Boolean.parseBoolean(resolvePlaceholder(props.isDeleteStubsAfterTest())))
|
.withMappingsOutputFolder(resolvePlaceholder(props.getMappingsOutputFolder()))
|
||||||
.withGenerateStubs(Boolean.parseBoolean(resolvePlaceholder(props.isGenerateStubs())))
|
.withDeleteStubsAfterTest(Boolean.parseBoolean(resolvePlaceholder(props.isDeleteStubsAfterTest())))
|
||||||
.withProperties(props.getProperties()).withHttpServerStubConfigurer(props.getHttpServerStubConfigurer())
|
.withGenerateStubs(Boolean.parseBoolean(resolvePlaceholder(props.isGenerateStubs())))
|
||||||
.withServerId(resolvePlaceholder(props.getServerId())).withFailOnNoStubs(props.isFailOnNoStubs());
|
.withProperties(props.getProperties())
|
||||||
|
.withHttpServerStubConfigurer(props.getHttpServerStubConfigurer())
|
||||||
|
.withServerId(resolvePlaceholder(props.getServerId()))
|
||||||
|
.withFailOnNoStubs(props.isFailOnNoStubs());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] resolvePlaceholder(String[] string) {
|
private String[] resolvePlaceholder(String[] string) {
|
||||||
@@ -172,7 +176,7 @@ class LazyMessageVerifier implements MessageVerifierSender, MessageVerifierRecei
|
|||||||
private MessageVerifierSender messageVerifierSender() {
|
private MessageVerifierSender messageVerifierSender() {
|
||||||
if (this.messageVerifierSender == null) {
|
if (this.messageVerifierSender == null) {
|
||||||
this.messageVerifierSender = this.beanFactory.getBeanProvider(MessageVerifierSender.class)
|
this.messageVerifierSender = this.beanFactory.getBeanProvider(MessageVerifierSender.class)
|
||||||
.getIfAvailable(NoOpStubMessages::new);
|
.getIfAvailable(NoOpStubMessages::new);
|
||||||
}
|
}
|
||||||
return this.messageVerifierSender;
|
return this.messageVerifierSender;
|
||||||
}
|
}
|
||||||
@@ -180,7 +184,7 @@ class LazyMessageVerifier implements MessageVerifierSender, MessageVerifierRecei
|
|||||||
private MessageVerifierReceiver messageVerifierReceiver() {
|
private MessageVerifierReceiver messageVerifierReceiver() {
|
||||||
if (this.messageVerifierReceiver == null) {
|
if (this.messageVerifierReceiver == null) {
|
||||||
this.messageVerifierReceiver = this.beanFactory.getBeanProvider(MessageVerifierReceiver.class)
|
this.messageVerifierReceiver = this.beanFactory.getBeanProvider(MessageVerifierReceiver.class)
|
||||||
.getIfAvailable(NoOpStubMessages::new);
|
.getIfAvailable(NoOpStubMessages::new);
|
||||||
}
|
}
|
||||||
return this.messageVerifierReceiver;
|
return this.messageVerifierReceiver;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||||||
* Conditional that checks if the user turned off the stubbed discovery mode.
|
* Conditional that checks if the user turned off the stubbed discovery mode.
|
||||||
*
|
*
|
||||||
* @author Marcin Grzejszczak
|
* @author Marcin Grzejszczak
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||||||
* is turned on by default.
|
* is turned on by default.
|
||||||
*
|
*
|
||||||
* @author Marcin Grzejszczak
|
* @author Marcin Grzejszczak
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class StubMapperProperties {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
String groupAndArtifact = this.idsToServiceIds
|
String groupAndArtifact = this.idsToServiceIds
|
||||||
.get(stubConfiguration.getGroupId() + ":" + stubConfiguration.getArtifactId());
|
.get(stubConfiguration.getGroupId() + ":" + stubConfiguration.getArtifactId());
|
||||||
if (StringUtils.hasText(groupAndArtifact)) {
|
if (StringUtils.hasText(groupAndArtifact)) {
|
||||||
return groupAndArtifact;
|
return groupAndArtifact;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class StubRunnerDiscoveryClientWrapper implements BeanPostProcessor {
|
|||||||
boolean isStubbedDiscoveryEnabled() {
|
boolean isStubbedDiscoveryEnabled() {
|
||||||
if (this.stubbedDiscoveryEnabled == null) {
|
if (this.stubbedDiscoveryEnabled == null) {
|
||||||
this.stubbedDiscoveryEnabled = Boolean.valueOf(this.beanFactory.getBean(Environment.class)
|
this.stubbedDiscoveryEnabled = Boolean.valueOf(this.beanFactory.getBean(Environment.class)
|
||||||
.getProperty("stubrunner.cloud.stubbed.discovery.enabled", "true"));
|
.getProperty("stubrunner.cloud.stubbed.discovery.enabled", "true"));
|
||||||
}
|
}
|
||||||
return this.stubbedDiscoveryEnabled;
|
return this.stubbedDiscoveryEnabled;
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ class StubRunnerDiscoveryClientWrapper implements BeanPostProcessor {
|
|||||||
boolean isCloudDelegateEnabled() {
|
boolean isCloudDelegateEnabled() {
|
||||||
if (this.cloudDelegateEnabled == null) {
|
if (this.cloudDelegateEnabled == null) {
|
||||||
this.cloudDelegateEnabled = Boolean.valueOf(this.beanFactory.getBean(Environment.class)
|
this.cloudDelegateEnabled = Boolean.valueOf(this.beanFactory.getBean(Environment.class)
|
||||||
.getProperty("stubrunner.cloud.delegate.enabled", "false"));
|
.getProperty("stubrunner.cloud.delegate.enabled", "false"));
|
||||||
}
|
}
|
||||||
return this.cloudDelegateEnabled;
|
return this.cloudDelegateEnabled;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class ConsulStubsRegistrar implements StubsRegistrar {
|
|||||||
|
|
||||||
protected String name(StubConfiguration stubConfiguration) {
|
protected String name(StubConfiguration stubConfiguration) {
|
||||||
String resolvedName = this.stubMapperProperties
|
String resolvedName = this.stubMapperProperties
|
||||||
.fromIvyNotationToId(stubConfiguration.toColonSeparatedDependencyNotation());
|
.fromIvyNotationToId(stubConfiguration.toColonSeparatedDependencyNotation());
|
||||||
if (StringUtils.hasText(resolvedName)) {
|
if (StringUtils.hasText(resolvedName)) {
|
||||||
return resolvedName;
|
return resolvedName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||||||
* Conditional that checks if Eureka is enabled.
|
* Conditional that checks if Eureka is enabled.
|
||||||
*
|
*
|
||||||
* @author Marcin Grzejszczak
|
* @author Marcin Grzejszczak
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|||||||
@@ -101,7 +101,9 @@ public class EurekaStubsRegistrar implements StubsRegistrar {
|
|||||||
EurekaClient client = new CloudEurekaClient(applicationInfoManager, this.eurekaClientConfigBean,
|
EurekaClient client = new CloudEurekaClient(applicationInfoManager, this.eurekaClientConfigBean,
|
||||||
transportClientFactories, args, this.context);
|
transportClientFactories, args, this.context);
|
||||||
EurekaRegistration registration = EurekaRegistration.builder(instance)
|
EurekaRegistration registration = EurekaRegistration.builder(instance)
|
||||||
.with(this.eurekaClientConfigBean, this.context).with(client).build();
|
.with(this.eurekaClientConfigBean, this.context)
|
||||||
|
.with(client)
|
||||||
|
.build();
|
||||||
EurekaHealthCheckHandler eurekaHealthCheckHandler = new EurekaHealthCheckHandler(
|
EurekaHealthCheckHandler eurekaHealthCheckHandler = new EurekaHealthCheckHandler(
|
||||||
StatusAggregator.getDefault());
|
StatusAggregator.getDefault());
|
||||||
eurekaHealthCheckHandler.setApplicationContext(context);
|
eurekaHealthCheckHandler.setApplicationContext(context);
|
||||||
@@ -165,7 +167,7 @@ public class EurekaStubsRegistrar implements StubsRegistrar {
|
|||||||
|
|
||||||
private String name(StubConfiguration stubConfiguration) {
|
private String name(StubConfiguration stubConfiguration) {
|
||||||
String resolvedName = this.stubMapperProperties
|
String resolvedName = this.stubMapperProperties
|
||||||
.fromIvyNotationToId(stubConfiguration.toColonSeparatedDependencyNotation());
|
.fromIvyNotationToId(stubConfiguration.toColonSeparatedDependencyNotation());
|
||||||
if (StringUtils.hasText(resolvedName)) {
|
if (StringUtils.hasText(resolvedName)) {
|
||||||
return resolvedName;
|
return resolvedName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,8 +151,8 @@ class StubbedServiceInstance implements ServiceInstance {
|
|||||||
}
|
}
|
||||||
RunningStubs runningStubs = this.stubFinder.findAllRunningStubs();
|
RunningStubs runningStubs = this.stubFinder.findAllRunningStubs();
|
||||||
String mappedServiceName = StringUtils
|
String mappedServiceName = StringUtils
|
||||||
.hasText(this.stubMapperProperties.fromServiceIdToIvyNotation(this.serviceId))
|
.hasText(this.stubMapperProperties.fromServiceIdToIvyNotation(this.serviceId))
|
||||||
? this.stubMapperProperties.fromServiceIdToIvyNotation(this.serviceId) : this.serviceId;
|
? this.stubMapperProperties.fromServiceIdToIvyNotation(this.serviceId) : this.serviceId;
|
||||||
entry = runningStubs.getEntry(mappedServiceName);
|
entry = runningStubs.getEntry(mappedServiceName);
|
||||||
CACHE.put(this.serviceId, entry);
|
CACHE.put(this.serviceId, entry);
|
||||||
return entry;
|
return entry;
|
||||||
|
|||||||
@@ -87,8 +87,12 @@ public class ZookeeperStubsRegistrar implements StubsRegistrar {
|
|||||||
|
|
||||||
protected ServiceInstance serviceInstance(StubConfiguration stubConfiguration, int port) {
|
protected ServiceInstance serviceInstance(StubConfiguration stubConfiguration, int port) {
|
||||||
try {
|
try {
|
||||||
return ServiceInstance.builder().uriSpec(new UriSpec(this.zookeeperDiscoveryProperties.getUriSpec()))
|
return ServiceInstance.builder()
|
||||||
.address("localhost").port(port).name(name(stubConfiguration)).build();
|
.uriSpec(new UriSpec(this.zookeeperDiscoveryProperties.getUriSpec()))
|
||||||
|
.address("localhost")
|
||||||
|
.port(port)
|
||||||
|
.name(name(stubConfiguration))
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
@@ -97,7 +101,7 @@ public class ZookeeperStubsRegistrar implements StubsRegistrar {
|
|||||||
|
|
||||||
private String name(StubConfiguration stubConfiguration) {
|
private String name(StubConfiguration stubConfiguration) {
|
||||||
String resolvedName = this.stubMapperProperties
|
String resolvedName = this.stubMapperProperties
|
||||||
.fromIvyNotationToId(stubConfiguration.toColonSeparatedDependencyNotation());
|
.fromIvyNotationToId(stubConfiguration.toColonSeparatedDependencyNotation());
|
||||||
if (StringUtils.hasText(resolvedName)) {
|
if (StringUtils.hasText(resolvedName)) {
|
||||||
return resolvedName;
|
return resolvedName;
|
||||||
}
|
}
|
||||||
@@ -105,8 +109,11 @@ public class ZookeeperStubsRegistrar implements StubsRegistrar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ServiceDiscovery serviceDiscovery(ServiceInstance serviceInstance) {
|
protected ServiceDiscovery serviceDiscovery(ServiceInstance serviceInstance) {
|
||||||
return ServiceDiscoveryBuilder.builder(Void.class).basePath(this.zookeeperDiscoveryProperties.getRoot())
|
return ServiceDiscoveryBuilder.builder(Void.class)
|
||||||
.client(this.curatorFramework).thisInstance(serviceInstance).build();
|
.basePath(this.zookeeperDiscoveryProperties.getRoot())
|
||||||
|
.client(this.curatorFramework)
|
||||||
|
.thisInstance(serviceInstance)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,9 +39,10 @@ public class StubRunnerRuleCustomPortJUnitTest {
|
|||||||
// tag::classrule_with_port[]
|
// tag::classrule_with_port[]
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static StubRunnerRule rule = new StubRunnerRule().repoRoot(repoRoot())
|
public static StubRunnerRule rule = new StubRunnerRule().repoRoot(repoRoot())
|
||||||
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance").withPort(35465)
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:35466");
|
.withPort(35465)
|
||||||
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:35466");
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@AfterClass
|
@AfterClass
|
||||||
@@ -67,14 +68,14 @@ public class StubRunnerRuleCustomPortJUnitTest {
|
|||||||
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")).isNotNull();
|
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")).isNotNull();
|
||||||
then(rule.findStubUrl("loanIssuance")).isNotNull();
|
then(rule.findStubUrl("loanIssuance")).isNotNull();
|
||||||
then(rule.findStubUrl("loanIssuance"))
|
then(rule.findStubUrl("loanIssuance"))
|
||||||
.isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
.isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
||||||
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
||||||
// and:
|
// and:
|
||||||
then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
|
then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
|
||||||
then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs",
|
|
||||||
"fraudDetectionServer")).isTrue();
|
|
||||||
then(rule.findAllRunningStubs()
|
then(rule.findAllRunningStubs()
|
||||||
.isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
|
.isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue();
|
||||||
|
then(rule.findAllRunningStubs()
|
||||||
|
.isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
|
||||||
// and: 'Stubs were registered'
|
// and: 'Stubs were registered'
|
||||||
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
|
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
|
||||||
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");
|
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ public class StubRunnerRuleJUnitTest {
|
|||||||
// tag::classrule[]
|
// tag::classrule[]
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static StubRunnerRule rule = new StubRunnerRule().repoRoot(repoRoot())
|
public static StubRunnerRule rule = new StubRunnerRule().repoRoot(repoRoot())
|
||||||
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer");
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer");
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@AfterClass
|
@AfterClass
|
||||||
@@ -68,14 +68,14 @@ public class StubRunnerRuleJUnitTest {
|
|||||||
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")).isNotNull();
|
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")).isNotNull();
|
||||||
then(rule.findStubUrl("loanIssuance")).isNotNull();
|
then(rule.findStubUrl("loanIssuance")).isNotNull();
|
||||||
then(rule.findStubUrl("loanIssuance"))
|
then(rule.findStubUrl("loanIssuance"))
|
||||||
.isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
.isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
||||||
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
||||||
// and:
|
// and:
|
||||||
then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
|
then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
|
||||||
then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs",
|
|
||||||
"fraudDetectionServer")).isTrue();
|
|
||||||
then(rule.findAllRunningStubs()
|
then(rule.findAllRunningStubs()
|
||||||
.isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
|
.isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue();
|
||||||
|
then(rule.findAllRunningStubs()
|
||||||
|
.isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
|
||||||
// and: 'Stubs were registered'
|
// and: 'Stubs were registered'
|
||||||
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
|
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
|
||||||
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");
|
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class ClasspathStubProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void should_return_null_if_stub_mode_is_not_classpath() {
|
public void should_return_null_if_stub_mode_is_not_classpath() {
|
||||||
StubDownloader stubDownloader = new ClasspathStubProvider()
|
StubDownloader stubDownloader = new ClasspathStubProvider()
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE).build());
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE).build());
|
||||||
|
|
||||||
then(stubDownloader).isNull();
|
then(stubDownloader).isNull();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class CompositeStubDownloaderBuilderTests {
|
|||||||
StubDownloader downloader = builder.build(new StubRunnerOptionsBuilder().withFailOnNoStubs(true).build());
|
StubDownloader downloader = builder.build(new StubRunnerOptionsBuilder().withFailOnNoStubs(true).build());
|
||||||
|
|
||||||
BDDAssertions.thenThrownBy(() -> downloader.downloadAndUnpackStubJar(new StubConfiguration("a:b:v")))
|
BDDAssertions.thenThrownBy(() -> downloader.downloadAndUnpackStubJar(new StubConfiguration("a:b:v")))
|
||||||
.isInstanceOf(IllegalArgumentException.class);
|
.isInstanceOf(IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ public class ContractProjectUpdaterTest extends AbstractGitTest {
|
|||||||
this.gitRepo.checkout(this.project, "master");
|
this.gitRepo.checkout(this.project, "master");
|
||||||
setOriginOnProjectToTmp(this.origin, this.project, true);
|
setOriginOnProjectToTmp(this.origin, this.project, true);
|
||||||
StubRunnerOptions options = new StubRunnerOptionsBuilder()
|
StubRunnerOptions options = new StubRunnerOptionsBuilder()
|
||||||
.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
|
.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
|
||||||
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE).build();
|
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
|
.build();
|
||||||
this.updater = new ContractProjectUpdater(options);
|
this.updater = new ContractProjectUpdater(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ public class ContractProjectUpdaterTest extends AbstractGitTest {
|
|||||||
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
||||||
}
|
}
|
||||||
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
||||||
.exists();
|
.exists();
|
||||||
BDDAssertions.then(this.gitRepo.gitFactory.provider).isNull();
|
BDDAssertions.then(this.gitRepo.gitFactory.provider).isNull();
|
||||||
BDDAssertions.then(this.outputCapture.toString()).contains("No custom credentials provider will be set");
|
BDDAssertions.then(this.outputCapture.toString()).contains("No custom credentials provider will be set");
|
||||||
}
|
}
|
||||||
@@ -88,13 +89,15 @@ public class ContractProjectUpdaterTest extends AbstractGitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void should_push_changes_to_current_branch_using_credentials() throws Exception {
|
public void should_push_changes_to_current_branch_using_credentials() throws Exception {
|
||||||
StubRunnerOptions options = new StubRunnerOptionsBuilder()
|
StubRunnerOptions options = new StubRunnerOptionsBuilder()
|
||||||
.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
|
.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
|
||||||
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE).withProperties(new HashMap<String, String>() {
|
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
{
|
.withProperties(new HashMap<String, String>() {
|
||||||
put("git.username", "foo");
|
{
|
||||||
put("git.password", "bar");
|
put("git.username", "foo");
|
||||||
}
|
put("git.password", "bar");
|
||||||
}).build();
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
ContractProjectUpdater updater = new ContractProjectUpdater(options);
|
ContractProjectUpdater updater = new ContractProjectUpdater(options);
|
||||||
File stubs = new File(GitRepoTests.class.getResource("/git_samples/sample_stubs").toURI());
|
File stubs = new File(GitRepoTests.class.getResource("/git_samples/sample_stubs").toURI());
|
||||||
|
|
||||||
@@ -108,16 +111,19 @@ public class ContractProjectUpdaterTest extends AbstractGitTest {
|
|||||||
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
||||||
}
|
}
|
||||||
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
||||||
.exists();
|
.exists();
|
||||||
BDDAssertions.then(this.outputCapture.toString())
|
BDDAssertions.then(this.outputCapture.toString())
|
||||||
.contains("Passed username and password - will set a custom credentials provider");
|
.contains("Passed username and password - will set a custom credentials provider");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_push_changes_to_current_branch_using_root_credentials() throws Exception {
|
public void should_push_changes_to_current_branch_using_root_credentials() throws Exception {
|
||||||
StubRunnerOptions options = new StubRunnerOptionsBuilder()
|
StubRunnerOptions options = new StubRunnerOptionsBuilder()
|
||||||
.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
|
.withStubRepositoryRoot("file://" + this.project.getAbsolutePath() + "/")
|
||||||
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE).withUsername("foo").withPassword("bar").build();
|
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
|
.withUsername("foo")
|
||||||
|
.withPassword("bar")
|
||||||
|
.build();
|
||||||
ContractProjectUpdater updater = new ContractProjectUpdater(options);
|
ContractProjectUpdater updater = new ContractProjectUpdater(options);
|
||||||
File stubs = new File(GitRepoTests.class.getResource("/git_samples/sample_stubs").toURI());
|
File stubs = new File(GitRepoTests.class.getResource("/git_samples/sample_stubs").toURI());
|
||||||
|
|
||||||
@@ -131,9 +137,9 @@ public class ContractProjectUpdaterTest extends AbstractGitTest {
|
|||||||
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
||||||
}
|
}
|
||||||
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
||||||
.exists();
|
.exists();
|
||||||
BDDAssertions.then(this.outputCapture.toString())
|
BDDAssertions.then(this.outputCapture.toString())
|
||||||
.contains("Passed username and password - will set a custom credentials provider");
|
.contains("Passed username and password - will set a custom credentials provider");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -151,7 +157,7 @@ public class ContractProjectUpdaterTest extends AbstractGitTest {
|
|||||||
then(revCommit.getShortMessage()).isEqualTo(initialCommit);
|
then(revCommit.getShortMessage()).isEqualTo(initialCommit);
|
||||||
}
|
}
|
||||||
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
BDDAssertions.then(new File(this.project, "META-INF/com.example/hello-world/0.0.2/mappings/someMapping.json"))
|
||||||
.doesNotExist();
|
.doesNotExist();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class FileStubDownloaderTests {
|
|||||||
Assertions.assertThat(expectedUnixResource).isEqualTo(fileStubDownloader.resolve(unixFileFormat, null));
|
Assertions.assertThat(expectedUnixResource).isEqualTo(fileStubDownloader.resolve(unixFileFormat, null));
|
||||||
Assertions.assertThat(expectedWindowsResource).isEqualTo(fileStubDownloader.resolve(windowsFileFormat, null));
|
Assertions.assertThat(expectedWindowsResource).isEqualTo(fileStubDownloader.resolve(windowsFileFormat, null));
|
||||||
Assertions.assertThat(expectedWindowsResource)
|
Assertions.assertThat(expectedWindowsResource)
|
||||||
.isEqualTo(fileStubDownloader.resolve(windowsFileFormatCorrectPathStart, null));
|
.isEqualTo(fileStubDownloader.resolve(windowsFileFormatCorrectPathStart, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,16 +59,16 @@ public class GitRepoTests extends AbstractGitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void should_throw_exception_when_there_is_no_repo() throws IOException, URISyntaxException {
|
public void should_throw_exception_when_there_is_no_repo() throws IOException, URISyntaxException {
|
||||||
thenThrownBy(() -> this.gitRepo.cloneProject(GitRepoTests.class.getResource("/git_samples/").toURI()))
|
thenThrownBy(() -> this.gitRepo.cloneProject(GitRepoTests.class.getResource("/git_samples/").toURI()))
|
||||||
.isInstanceOf(IllegalStateException.class)
|
.isInstanceOf(IllegalStateException.class)
|
||||||
.hasMessageContaining("Exception occurred while cloning repo");
|
.hasMessageContaining("Exception occurred while cloning repo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_throw_an_exception_when_failed_to_initialize_the_repo() throws IOException {
|
public void should_throw_an_exception_when_failed_to_initialize_the_repo() throws IOException {
|
||||||
thenThrownBy(() -> new GitRepo(this.tmpFolder, new ExceptionThrowingJGitFactory())
|
thenThrownBy(() -> new GitRepo(this.tmpFolder, new ExceptionThrowingJGitFactory())
|
||||||
.cloneProject(this.project.toURI())).isInstanceOf(IllegalStateException.class)
|
.cloneProject(this.project.toURI())).isInstanceOf(IllegalStateException.class)
|
||||||
.hasMessageContaining("Exception occurred while cloning repo")
|
.hasMessageContaining("Exception occurred while cloning repo")
|
||||||
.hasCauseInstanceOf(CustomException.class);
|
.hasCauseInstanceOf(CustomException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -49,8 +49,10 @@ public class GitStubDownloaderTests {
|
|||||||
public void should_return_a_null_downloader_for_a_classptath_mode() {
|
public void should_return_a_null_downloader_for_a_classptath_mode() {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
|
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder.build(new StubRunnerOptionsBuilder()
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.withStubsMode(StubRunnerProperties.StubsMode.CLASSPATH).withProperties(props()).build());
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.CLASSPATH)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
then(stubDownloader).isNull();
|
then(stubDownloader).isNull();
|
||||||
}
|
}
|
||||||
@@ -59,8 +61,10 @@ public class GitStubDownloaderTests {
|
|||||||
public void should_return_a_null_downloader_for_a_empty_repo() {
|
public void should_return_a_null_downloader_for_a_empty_repo() {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
|
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder.build(new StubRunnerOptionsBuilder()
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.withStubsMode(StubRunnerProperties.StubsMode.REMOTE).withProperties(props()).build());
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
then(stubDownloader).isNull();
|
then(stubDownloader).isNull();
|
||||||
}
|
}
|
||||||
@@ -70,8 +74,10 @@ public class GitStubDownloaderTests {
|
|||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
|
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.withStubRepositoryRoot("http://www.foo.com/").withProperties(props()).build());
|
.withStubRepositoryRoot("http://www.foo.com/")
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
then(stubDownloader).isNull();
|
then(stubDownloader).isNull();
|
||||||
}
|
}
|
||||||
@@ -80,51 +86,55 @@ public class GitStubDownloaderTests {
|
|||||||
public void should_pick_stubs_for_group_and_artifact_with_version_from_a_git_repo() throws Exception {
|
public void should_pick_stubs_for_group_and_artifact_with_version_from_a_git_repo() throws Exception {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
||||||
.replace(File.separator, "/");
|
.replace(File.separator, "/");
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.withStubRepositoryRoot("git://" + contractFolderLocation).withProperties(props()).build());
|
.withStubRepositoryRoot("git://" + contractFolderLocation)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("foo.bar:bazService:0.0.1-SNAPSHOT"));
|
.downloadAndUnpackStubJar(new StubConfiguration("foo.bar:bazService:0.0.1-SNAPSHOT"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath())
|
then(entry.getValue().getAbsolutePath())
|
||||||
.contains("foo.bar" + File.separator + "bazService" + File.separator + "0.0.1-SNAPSHOT");
|
.contains("foo.bar" + File.separator + "bazService" + File.separator + "0.0.1-SNAPSHOT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_pick_latest_build_snapshot_stubs_when_latest_version_set() throws URISyntaxException {
|
public void should_pick_latest_build_snapshot_stubs_when_latest_version_set() throws URISyntaxException {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
||||||
.replace(File.separator, "/");
|
.replace(File.separator, "/");
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.withStubRepositoryRoot("git://" + contractFolderLocation).withProperties(props()).build());
|
.withStubRepositoryRoot("git://" + contractFolderLocation)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:+"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:+"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external"
|
then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external"
|
||||||
+ File.separator + "1.0.0.BUILD-SNAPSHOT");
|
+ File.separator + "1.0.0.BUILD-SNAPSHOT");
|
||||||
|
|
||||||
entry = stubDownloader
|
entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:latest"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:latest"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external"
|
then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external"
|
||||||
+ File.separator + "1.0.0.BUILD-SNAPSHOT");
|
+ File.separator + "1.0.0.BUILD-SNAPSHOT");
|
||||||
|
|
||||||
entry = stubDownloader
|
entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:LATEST"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:LATEST"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external"
|
then(entry.getValue().getAbsolutePath()).contains("com.example" + File.separator + "beer-api-producer-external"
|
||||||
+ File.separator + "1.0.0.BUILD-SNAPSHOT");
|
+ File.separator + "1.0.0.BUILD-SNAPSHOT");
|
||||||
|
|
||||||
entry = stubDownloader
|
entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.issue1305:beer-api-producer-external:+"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.issue1305:beer-api-producer-external:+"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath()).contains(
|
then(entry.getValue().getAbsolutePath()).contains(
|
||||||
@@ -135,24 +145,26 @@ public class GitStubDownloaderTests {
|
|||||||
public void should_pick_latest_release_stubs_when_release_version_set() throws URISyntaxException {
|
public void should_pick_latest_release_stubs_when_release_version_set() throws URISyntaxException {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
||||||
.replace(File.separator, "/");
|
.replace(File.separator, "/");
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.withStubRepositoryRoot("git://" + contractFolderLocation).withProperties(props()).build());
|
.withStubRepositoryRoot("git://" + contractFolderLocation)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:release"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:release"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath()).contains(
|
then(entry.getValue().getAbsolutePath())
|
||||||
"com.example" + File.separator + "beer-api-producer-external" + File.separator + "1.0.0.RELEASE");
|
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "1.0.0.RELEASE");
|
||||||
|
|
||||||
entry = stubDownloader
|
entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:RELEASE"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:RELEASE"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath()).contains(
|
then(entry.getValue().getAbsolutePath())
|
||||||
"com.example" + File.separator + "beer-api-producer-external" + File.separator + "1.0.0.RELEASE");
|
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "1.0.0.RELEASE");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -160,65 +172,71 @@ public class GitStubDownloaderTests {
|
|||||||
throws URISyntaxException {
|
throws URISyntaxException {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
String contractFolderLocation = (file("/git_samples/contract-predefined-names-git/").getAbsolutePath()
|
String contractFolderLocation = (file("/git_samples/contract-predefined-names-git/").getAbsolutePath()
|
||||||
.replace("/", File.separator) + "/").replace(File.separator, "/");
|
.replace("/", File.separator) + "/").replace(File.separator, "/");
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.withStubRepositoryRoot("git://" + contractFolderLocation).withProperties(props()).build());
|
.withStubRepositoryRoot("git://" + contractFolderLocation)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:+"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:+"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath())
|
then(entry.getValue().getAbsolutePath())
|
||||||
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest");
|
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest");
|
||||||
|
|
||||||
entry = stubDownloader
|
entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:latest"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:latest"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath())
|
then(entry.getValue().getAbsolutePath())
|
||||||
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest");
|
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest");
|
||||||
|
|
||||||
entry = stubDownloader
|
entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:LATEST"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:LATEST"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath())
|
then(entry.getValue().getAbsolutePath())
|
||||||
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest");
|
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "latest");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_pick_release_folder_when_release_version_set() throws URISyntaxException {
|
public void should_pick_release_folder_when_release_version_set() throws URISyntaxException {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
String contractFolderLocation = (file("/git_samples/contract-predefined-names-git/").getAbsolutePath() + "/")
|
String contractFolderLocation = (file("/git_samples/contract-predefined-names-git/").getAbsolutePath() + "/")
|
||||||
.replace(File.separator, "/");
|
.replace(File.separator, "/");
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.withStubRepositoryRoot("git://" + contractFolderLocation).withProperties(props()).build());
|
.withStubRepositoryRoot("git://" + contractFolderLocation)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
Map.Entry<StubConfiguration, File> entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:release"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:release"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath())
|
then(entry.getValue().getAbsolutePath())
|
||||||
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "release");
|
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "release");
|
||||||
|
|
||||||
entry = stubDownloader
|
entry = stubDownloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:RELEASE"));
|
.downloadAndUnpackStubJar(new StubConfiguration("com.example:beer-api-producer-external:RELEASE"));
|
||||||
|
|
||||||
then(entry).isNotNull();
|
then(entry).isNotNull();
|
||||||
then(entry.getValue().getAbsolutePath())
|
then(entry.getValue().getAbsolutePath())
|
||||||
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "release");
|
.contains("com.example" + File.separator + "beer-api-producer-external" + File.separator + "release");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_fail_to_fetch_stubs_when_concrete_version_was_not_specified() throws URISyntaxException {
|
public void should_fail_to_fetch_stubs_when_concrete_version_was_not_specified() throws URISyntaxException {
|
||||||
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
StubDownloaderBuilder stubDownloaderBuilder = new ScmStubDownloaderBuilder();
|
||||||
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
String contractFolderLocation = (file("/git_samples/contract-git/").getAbsolutePath() + "/")
|
||||||
.replace(File.separator, "/");
|
.replace(File.separator, "/");
|
||||||
StubDownloader stubDownloader = stubDownloaderBuilder
|
StubDownloader stubDownloader = stubDownloaderBuilder
|
||||||
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.build(new StubRunnerOptionsBuilder().withStubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.withStubRepositoryRoot("git://" + contractFolderLocation).withProperties(props()).build());
|
.withStubRepositoryRoot("git://" + contractFolderLocation)
|
||||||
|
.withProperties(props())
|
||||||
|
.build());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stubDownloader.downloadAndUnpackStubJar(new StubConfiguration("foo.bar", "bazService", ""));
|
stubDownloader.downloadAndUnpackStubJar(new StubConfiguration("foo.bar", "bazService", ""));
|
||||||
|
|||||||
@@ -65,19 +65,19 @@ public class StubRunnerSliceTests {
|
|||||||
assertThat(this.loanIssuancePort).isBetween(10001, 10020);
|
assertThat(this.loanIssuancePort).isBetween(10001, 10020);
|
||||||
|
|
||||||
assertThat(this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
assertThat(this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
assertThat(this.stubFinder.findStubUrl("loanIssuance")).isNotNull();
|
assertThat(this.stubFinder.findStubUrl("loanIssuance")).isNotNull();
|
||||||
assertThat(this.stubFinder.findStubUrl("loanIssuance")).isEqualTo(
|
assertThat(this.stubFinder.findStubUrl("loanIssuance")).isEqualTo(
|
||||||
this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
||||||
assertThat(this.stubFinder.findStubUrl("loanIssuance")).isEqualTo(
|
assertThat(this.stubFinder.findStubUrl("loanIssuance"))
|
||||||
this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs:loanIssuance"));
|
.isEqualTo(this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs:loanIssuance"));
|
||||||
assertThat(this.stubFinder
|
assertThat(this.stubFinder
|
||||||
.findStubUrl("org.springframework.cloud.contract.verifier.stubs:loanIssuance:0.0.1-SNAPSHOT"))
|
.findStubUrl("org.springframework.cloud.contract.verifier.stubs:loanIssuance:0.0.1-SNAPSHOT"))
|
||||||
.isEqualTo(this.stubFinder.findStubUrl(
|
.isEqualTo(this.stubFinder
|
||||||
"org.springframework.cloud.contract.verifier.stubs:loanIssuance:0.0.1-SNAPSHOT:stubs"));
|
.findStubUrl("org.springframework.cloud.contract.verifier.stubs:loanIssuance:0.0.1-SNAPSHOT:stubs"));
|
||||||
assertThat(
|
assertThat(
|
||||||
this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"))
|
this.stubFinder.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"))
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
assertThat(this.properties.getProperties()).containsEntry("hello", "world").containsEntry("foo", "bar");
|
assertThat(this.properties.getProperties()).containsEntry("hello", "world").containsEntry("foo", "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ public class StubsStubDownloaderTests {
|
|||||||
public void should_pick_stubs_from_a_given_location() {
|
public void should_pick_stubs_from_a_given_location() {
|
||||||
String path = url.getPath();
|
String path = url.getPath();
|
||||||
StubRunnerOptions options = new StubRunnerOptionsBuilder().withStubRepositoryRoot("stubs://file://" + path)
|
StubRunnerOptions options = new StubRunnerOptionsBuilder().withStubRepositoryRoot("stubs://file://" + path)
|
||||||
.build();
|
.build();
|
||||||
StubsStubDownloader downloader = new StubsStubDownloader(options);
|
StubsStubDownloader downloader = new StubsStubDownloader(options);
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = downloader
|
Map.Entry<StubConfiguration, File> entry = downloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("lv.spring.cloud:bye"));
|
.downloadAndUnpackStubJar(new StubConfiguration("lv.spring.cloud:bye"));
|
||||||
|
|
||||||
BDDAssertions.then(entry).isNotNull();
|
BDDAssertions.then(entry).isNotNull();
|
||||||
BDDAssertions.then(entry.getValue()).exists();
|
BDDAssertions.then(entry.getValue()).exists();
|
||||||
@@ -48,11 +48,12 @@ public class StubsStubDownloaderTests {
|
|||||||
public void should_pick_stubs_from_a_given_location_for_a_find_producer_with_ga() {
|
public void should_pick_stubs_from_a_given_location_for_a_find_producer_with_ga() {
|
||||||
String path = url.getPath();
|
String path = url.getPath();
|
||||||
StubRunnerOptions options = new StubRunnerOptionsBuilder().withStubRepositoryRoot("stubs://file://" + path)
|
StubRunnerOptions options = new StubRunnerOptionsBuilder().withStubRepositoryRoot("stubs://file://" + path)
|
||||||
.withProperties(propsWithFindProducer()).build();
|
.withProperties(propsWithFindProducer())
|
||||||
|
.build();
|
||||||
StubsStubDownloader downloader = new StubsStubDownloader(options);
|
StubsStubDownloader downloader = new StubsStubDownloader(options);
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = downloader
|
Map.Entry<StubConfiguration, File> entry = downloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("lv.spring.cloud:bye"));
|
.downloadAndUnpackStubJar(new StubConfiguration("lv.spring.cloud:bye"));
|
||||||
|
|
||||||
BDDAssertions.then(entry).isNotNull();
|
BDDAssertions.then(entry).isNotNull();
|
||||||
File stub = new File(entry.getValue().getPath(), "lv/spring/cloud/bye/lv_bye.json");
|
File stub = new File(entry.getValue().getPath(), "lv/spring/cloud/bye/lv_bye.json");
|
||||||
@@ -63,11 +64,12 @@ public class StubsStubDownloaderTests {
|
|||||||
public void should_pick_stubs_from_a_given_location_for_a_find_producer_with_gav() {
|
public void should_pick_stubs_from_a_given_location_for_a_find_producer_with_gav() {
|
||||||
String path = url.getPath();
|
String path = url.getPath();
|
||||||
StubRunnerOptions options = new StubRunnerOptionsBuilder().withStubRepositoryRoot("stubs://file://" + path)
|
StubRunnerOptions options = new StubRunnerOptionsBuilder().withStubRepositoryRoot("stubs://file://" + path)
|
||||||
.withProperties(propsWithFindProducer()).build();
|
.withProperties(propsWithFindProducer())
|
||||||
|
.build();
|
||||||
StubsStubDownloader downloader = new StubsStubDownloader(options);
|
StubsStubDownloader downloader = new StubsStubDownloader(options);
|
||||||
|
|
||||||
Map.Entry<StubConfiguration, File> entry = downloader
|
Map.Entry<StubConfiguration, File> entry = downloader
|
||||||
.downloadAndUnpackStubJar(new StubConfiguration("lv.spring:cloud:bye"));
|
.downloadAndUnpackStubJar(new StubConfiguration("lv.spring:cloud:bye"));
|
||||||
|
|
||||||
BDDAssertions.then(entry).isNotNull();
|
BDDAssertions.then(entry).isNotNull();
|
||||||
File stub = new File(entry.getValue().getPath(), "lv/spring/cloud/bye/lv_bye.json");
|
File stub = new File(entry.getValue().getPath(), "lv/spring/cloud/bye/lv_bye.json");
|
||||||
|
|||||||
@@ -42,9 +42,11 @@ class StubRunnerJUnit5ExtensionCustomMessageVerifierTests {
|
|||||||
// Visible for testing
|
// Visible for testing
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension()
|
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension()
|
||||||
.stubsMode(StubRunnerProperties.StubsMode.REMOTE).repoRoot(repoRoot())
|
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService")
|
.repoRoot(repoRoot())
|
||||||
.messageVerifierSender(new MyMessageVerifier()).messageVerifierReceiver(new MyMessageVerifier());
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService")
|
||||||
|
.messageVerifierSender(new MyMessageVerifier())
|
||||||
|
.messageVerifierReceiver(new MyMessageVerifier());
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ class StubRunnerJUnit5ExtensionCustomPortTests {
|
|||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension().repoRoot(repoRoot())
|
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension().repoRoot(repoRoot())
|
||||||
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance").withPort(22345)
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:22346");
|
.withPort(22345)
|
||||||
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer:22346");
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@@ -61,23 +62,23 @@ class StubRunnerJUnit5ExtensionCustomPortTests {
|
|||||||
@Test
|
@Test
|
||||||
void should_start_wiremock_servers() throws Exception {
|
void should_start_wiremock_servers() throws Exception {
|
||||||
then(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
then(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
then(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull();
|
then(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull();
|
||||||
then(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(
|
then(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(
|
||||||
stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
||||||
then(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"))
|
then(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer"))
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
then(stubRunnerExtension.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
|
then(stubRunnerExtension.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
|
||||||
then(stubRunnerExtension.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs",
|
|
||||||
"fraudDetectionServer")).isTrue();
|
|
||||||
then(stubRunnerExtension.findAllRunningStubs()
|
then(stubRunnerExtension.findAllRunningStubs()
|
||||||
.isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
|
.isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue();
|
||||||
|
then(stubRunnerExtension.findAllRunningStubs()
|
||||||
|
.isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
|
||||||
then(httpGet(stubRunnerExtension.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
|
then(httpGet(stubRunnerExtension.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
|
||||||
then(httpGet(stubRunnerExtension.findStubUrl("fraudDetectionServer").toString() + "/name"))
|
then(httpGet(stubRunnerExtension.findStubUrl("fraudDetectionServer").toString() + "/name"))
|
||||||
.isEqualTo("fraudDetectionServer");
|
.isEqualTo("fraudDetectionServer");
|
||||||
then(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(URI.create("http://localhost:22345").toURL());
|
then(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(URI.create("http://localhost:22345").toURL());
|
||||||
then(stubRunnerExtension.findStubUrl("fraudDetectionServer"))
|
then(stubRunnerExtension.findStubUrl("fraudDetectionServer"))
|
||||||
.isEqualTo(URI.create("http://localhost:22346").toURL());
|
.isEqualTo(URI.create("http://localhost:22346").toURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String httpGet(String url) throws Exception {
|
private String httpGet(String url) throws Exception {
|
||||||
|
|||||||
@@ -34,8 +34,9 @@ public class StubRunnerJUnit5ExtensionExceptionThrowingTests {
|
|||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension()
|
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension()
|
||||||
.stubsMode(StubRunnerProperties.StubsMode.REMOTE).repoRoot(repoRoot())
|
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService");
|
.repoRoot(repoRoot())
|
||||||
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "bootService");
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ class StubRunnerJUnit5ExtensionTests {
|
|||||||
// Visible for Junit
|
// Visible for Junit
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension().repoRoot(repoRoot())
|
static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension().repoRoot(repoRoot())
|
||||||
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")
|
||||||
.withMappingsOutputFolder("target/outputmappingsforrule");
|
.withMappingsOutputFolder("target/outputmappingsforrule");
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@@ -64,12 +64,12 @@ class StubRunnerJUnit5ExtensionTests {
|
|||||||
@Test
|
@Test
|
||||||
void should_start_WireMock_servers() {
|
void should_start_WireMock_servers() {
|
||||||
assertThat(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
assertThat(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull();
|
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull();
|
||||||
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(
|
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(
|
||||||
stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
||||||
assertThat(stubRunnerExtension
|
assertThat(stubRunnerExtension
|
||||||
.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -39,10 +39,10 @@ class StubRunnerJUnit5MethodExtensionTests {
|
|||||||
// Visible for Junit
|
// Visible for Junit
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
StubRunnerExtension stubRunnerExtension = new StubRunnerExtension().repoRoot(repoRoot())
|
StubRunnerExtension stubRunnerExtension = new StubRunnerExtension().repoRoot(repoRoot())
|
||||||
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
.stubsMode(StubRunnerProperties.StubsMode.REMOTE)
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
|
||||||
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")
|
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")
|
||||||
.withMappingsOutputFolder("target/outputmappingsforrule");
|
.withMappingsOutputFolder("target/outputmappingsforrule");
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@AfterEach
|
@AfterEach
|
||||||
@@ -64,12 +64,12 @@ class StubRunnerJUnit5MethodExtensionTests {
|
|||||||
@Test
|
@Test
|
||||||
void should_start_WireMock_servers() {
|
void should_start_WireMock_servers() {
|
||||||
assertThat(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
assertThat(stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"))
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull();
|
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isNotNull();
|
||||||
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(
|
assertThat(stubRunnerExtension.findStubUrl("loanIssuance")).isEqualTo(
|
||||||
stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
stubRunnerExtension.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
|
||||||
assertThat(stubRunnerExtension
|
assertThat(stubRunnerExtension
|
||||||
.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
*/
|
*/
|
||||||
public class StubRunnerServerConfigurationTests {
|
public class StubRunnerServerConfigurationTests {
|
||||||
|
|
||||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
AutoConfigurations.of(StubRunnerConfiguration.class, StubRunnerServerConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(StubRunnerConfiguration.class, StubRunnerServerConfiguration.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateBeansByDefault() {
|
public void shouldCreateBeansByDefault() {
|
||||||
|
|||||||
@@ -79,9 +79,13 @@ public class RecursiveFilesConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void processFiles() {
|
public void processFiles() {
|
||||||
ContractFileScanner scanner = ContractFileScanner.builder().baseDir(contractsDslDir)
|
ContractFileScanner scanner = ContractFileScanner.builder()
|
||||||
.excluded(new HashSet<>(excludedFiles)).ignored(new HashSet<>()).included(new HashSet<>())
|
.baseDir(contractsDslDir)
|
||||||
.includeMatcher(includedContracts).build();
|
.excluded(new HashSet<>(excludedFiles))
|
||||||
|
.ignored(new HashSet<>())
|
||||||
|
.included(new HashSet<>())
|
||||||
|
.includeMatcher(includedContracts)
|
||||||
|
.build();
|
||||||
MultiValueMap<Path, ContractMetadata> contracts = scanner.findContractsRecursively();
|
MultiValueMap<Path, ContractMetadata> contracts = scanner.findContractsRecursively();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Found the following contracts " + contracts);
|
log.debug("Found the following contracts " + contracts);
|
||||||
@@ -115,7 +119,7 @@ public class RecursiveFilesConverter {
|
|||||||
|
|
||||||
for (StubGenerator stubGenerator : stubGenerators) {
|
for (StubGenerator stubGenerator : stubGenerators) {
|
||||||
Map<Contract, String> convertedContent = stubGenerator
|
Map<Contract, String> convertedContent = stubGenerator
|
||||||
.convertContents(last(entryKey).toString(), contract);
|
.convertContents(last(entryKey).toString(), contract);
|
||||||
if (convertedContent == null || convertedContent.isEmpty()) {
|
if (convertedContent == null || convertedContent.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ public interface StubGenerator<T> {
|
|||||||
* @return the converted stub mapping
|
* @return the converted stub mapping
|
||||||
*/
|
*/
|
||||||
default T postProcessStubMapping(T stubMapping, Contract contract) {
|
default T postProcessStubMapping(T stubMapping, Contract contract) {
|
||||||
List<StubPostProcessor> processors = StubPostProcessor.PROCESSORS.stream().filter(p -> p.isApplicable(contract))
|
List<StubPostProcessor> processors = StubPostProcessor.PROCESSORS.stream()
|
||||||
.collect(Collectors.toList());
|
.filter(p -> p.isApplicable(contract))
|
||||||
|
.collect(Collectors.toList());
|
||||||
if (processors.isEmpty()) {
|
if (processors.isEmpty()) {
|
||||||
return defaultStubMappingPostProcessing(stubMapping, contract);
|
return defaultStubMappingPostProcessing(stubMapping, contract);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ class DefaultWireMockStubPostProcessor implements WireMockStubPostProcessor {
|
|||||||
}
|
}
|
||||||
Object stubMapping = WireMockMetaData.fromMetadata(contract.getMetadata()).getStubMapping();
|
Object stubMapping = WireMockMetaData.fromMetadata(contract.getMetadata()).getStubMapping();
|
||||||
return WireMockMetaData.APPLICABLE_CLASSES.stream()
|
return WireMockMetaData.APPLICABLE_CLASSES.stream()
|
||||||
.anyMatch(aClass -> aClass.isAssignableFrom(stubMapping.getClass()));
|
.anyMatch(aClass -> aClass.isAssignableFrom(stubMapping.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,8 +78,10 @@ public class DslToWireMockClientConverter extends DslToWireMockConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Contract> httpContracts(ContractMetadata contract) {
|
private List<Contract> httpContracts(ContractMetadata contract) {
|
||||||
return contract.getConvertedContract().stream().filter(c -> c.getRequest() != null)
|
return contract.getConvertedContract()
|
||||||
.collect(Collectors.toList());
|
.stream()
|
||||||
|
.filter(c -> c.getRequest() != null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Contract, String> convertContracts(String rootName, ContractMetadata contract,
|
private Map<Contract, String> convertContracts(String rootName, ContractMetadata contract,
|
||||||
|
|||||||
@@ -65,8 +65,9 @@ public class WireMockMetaData implements SpringCloudContractMetadata {
|
|||||||
@Override
|
@Override
|
||||||
public String description() {
|
public String description() {
|
||||||
return "Metadata for extending WireMock stubs.\n\nStubMapping can be " + "one of the following classes "
|
return "Metadata for extending WireMock stubs.\n\nStubMapping can be " + "one of the following classes "
|
||||||
+ APPLICABLE_CLASSES.stream().map(aClass -> "`" + aClass.getSimpleName() + "`")
|
+ APPLICABLE_CLASSES.stream()
|
||||||
.collect(Collectors.toList())
|
.map(aClass -> "`" + aClass.getSimpleName() + "`")
|
||||||
|
.collect(Collectors.toList())
|
||||||
+ ". Please check "
|
+ ". Please check "
|
||||||
+ "the http://wiremock.org/docs/stubbing/ for more information about the StubMapping class properties.";
|
+ "the http://wiremock.org/docs/stubbing/ for more information about the StubMapping class properties.";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,17 +202,27 @@ public class WireMockToDslConverter {
|
|||||||
Iterator<JsonNode> elements = requestBodyArrayNode.elements();
|
Iterator<JsonNode> elements = requestBodyArrayNode.elements();
|
||||||
Iterable<JsonNode> iterableFields = () -> elements;
|
Iterable<JsonNode> iterableFields = () -> elements;
|
||||||
List<Map.Entry<String, JsonNode>> requestBodyObjectNodes = new ArrayList<>();
|
List<Map.Entry<String, JsonNode>> requestBodyObjectNodes = new ArrayList<>();
|
||||||
StreamSupport.stream(iterableFields.spliterator(), false).filter(f -> f instanceof ObjectNode)
|
StreamSupport.stream(iterableFields.spliterator(), false)
|
||||||
.map(f -> (ObjectNode) f).map(ObjectNode::fields)
|
.filter(f -> f instanceof ObjectNode)
|
||||||
.forEachOrdered(i -> i.forEachRemaining(requestBodyObjectNodes::add));
|
.map(f -> (ObjectNode) f)
|
||||||
requestBodyObjectNodes.stream().filter(b -> b.getKey().equals("equalTo")).findFirst()
|
.map(ObjectNode::fields)
|
||||||
.ifPresent(b -> requestBody.append("body ('").append(b.getValue().asText()).append("')"));
|
.forEachOrdered(i -> i.forEachRemaining(requestBodyObjectNodes::add));
|
||||||
requestBodyObjectNodes.stream().filter(b -> b.getKey().equals("equalToJson")).findFirst()
|
requestBodyObjectNodes.stream()
|
||||||
.ifPresent(b -> requestBody.append("body ('").append(b.getValue().asText()).append("')"));
|
.filter(b -> b.getKey().equals("equalTo"))
|
||||||
requestBodyObjectNodes.stream().filter(b -> b.getKey().equals("matches")).findFirst()
|
.findFirst()
|
||||||
.ifPresent(b -> requestBody.append("body $(consumer(regex('")
|
.ifPresent(b -> requestBody.append("body ('").append(b.getValue().asText()).append("')"));
|
||||||
.append(escapeJava(b.getValue().asText())).append("')), producer('")
|
requestBodyObjectNodes.stream()
|
||||||
.append(new Xeger(escapeJava(b.getValue().asText())).generate()).append("'))"));
|
.filter(b -> b.getKey().equals("equalToJson"))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(b -> requestBody.append("body ('").append(b.getValue().asText()).append("')"));
|
||||||
|
requestBodyObjectNodes.stream()
|
||||||
|
.filter(b -> b.getKey().equals("matches"))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(b -> requestBody.append("body $(consumer(regex('")
|
||||||
|
.append(escapeJava(b.getValue().asText()))
|
||||||
|
.append("')), producer('")
|
||||||
|
.append(new Xeger(escapeJava(b.getValue().asText())).generate())
|
||||||
|
.append("'))"));
|
||||||
}
|
}
|
||||||
return requestBody.toString();
|
return requestBody.toString();
|
||||||
}
|
}
|
||||||
@@ -250,9 +260,8 @@ public class WireMockToDslConverter {
|
|||||||
Object intermediateObjectForPrettyPrinting = OBJECT_MAPPER.reader().readValue(textNode, Object.class);
|
Object intermediateObjectForPrettyPrinting = OBJECT_MAPPER.reader().readValue(textNode, Object.class);
|
||||||
DefaultIndenter customIndenter = new DefaultIndenter(" ", "\n");
|
DefaultIndenter customIndenter = new DefaultIndenter(" ", "\n");
|
||||||
return OBJECT_MAPPER
|
return OBJECT_MAPPER
|
||||||
.writer(new PrivatePrettyPrinter().withArrayIndenter(customIndenter)
|
.writer(new PrivatePrettyPrinter().withArrayIndenter(customIndenter).withObjectIndenter(customIndenter))
|
||||||
.withObjectIndenter(customIndenter))
|
.writeValueAsString(intermediateObjectForPrettyPrinting);
|
||||||
.writeValueAsString(intermediateObjectForPrettyPrinting);
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new RuntimeException("WireMock response body could not be pretty printed");
|
throw new RuntimeException("WireMock response body could not be pretty printed");
|
||||||
@@ -267,8 +276,12 @@ public class WireMockToDslConverter {
|
|||||||
responseHeadersBuilder.append("headers {\n");
|
responseHeadersBuilder.append("headers {\n");
|
||||||
ObjectNode responseHeadersObjectNode = requestHeadersNode.deepCopy();
|
ObjectNode responseHeadersObjectNode = requestHeadersNode.deepCopy();
|
||||||
Iterator<Map.Entry<String, JsonNode>> fields = responseHeadersObjectNode.fields();
|
Iterator<Map.Entry<String, JsonNode>> fields = responseHeadersObjectNode.fields();
|
||||||
fields.forEachRemaining(c -> responseHeadersBuilder.append("header('").append(c.getKey()).append("',")
|
fields.forEachRemaining(c -> responseHeadersBuilder.append("header('")
|
||||||
.append("'").append(c.getValue().asText()).append("')\n"));
|
.append(c.getKey())
|
||||||
|
.append("',")
|
||||||
|
.append("'")
|
||||||
|
.append(c.getValue().asText())
|
||||||
|
.append("')\n"));
|
||||||
responseHeadersBuilder.append("}");
|
responseHeadersBuilder.append("}");
|
||||||
}
|
}
|
||||||
return responseHeadersBuilder.toString();
|
return responseHeadersBuilder.toString();
|
||||||
|
|||||||
@@ -153,10 +153,12 @@ class DefaultWireMockStubPostProcessorTests {
|
|||||||
then(result.getResponse().getStatus()).isEqualTo(200);
|
then(result.getResponse().getStatus()).isEqualTo(200);
|
||||||
then(result.getResponse().getBody()).isEqualTo("pong");
|
then(result.getResponse().getBody()).isEqualTo("pong");
|
||||||
then(result.getPostServeActions().stream().map(a -> a.getName()).collect(Collectors.toList()))
|
then(result.getPostServeActions().stream().map(a -> a.getName()).collect(Collectors.toList()))
|
||||||
.contains("webhook");
|
.contains("webhook");
|
||||||
PostServeActionDefinition definition = result.getPostServeActions().stream()
|
PostServeActionDefinition definition = result.getPostServeActions()
|
||||||
.filter(a -> a.getName().equals("webhook")).findFirst()
|
.stream()
|
||||||
.orElseThrow(() -> new AssertionError("No webhook action found"));
|
.filter(a -> a.getName().equals("webhook"))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new AssertionError("No webhook action found"));
|
||||||
then(definition.getParameters().getString("method")).isEqualTo("POST");
|
then(definition.getParameters().getString("method")).isEqualTo("POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ public class ConvertMojo extends AbstractMojo {
|
|||||||
throws MojoExecutionException {
|
throws MojoExecutionException {
|
||||||
File outputFolderWithOriginals = new File(this.stubsDirectory, rootPath + ORIGINAL_PATH);
|
File outputFolderWithOriginals = new File(this.stubsDirectory, rootPath + ORIGINAL_PATH);
|
||||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)
|
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)
|
||||||
.copy(contractsDirectory, outputFolderWithOriginals);
|
.copy(contractsDirectory, outputFolderWithOriginals);
|
||||||
return outputFolderWithOriginals;
|
return outputFolderWithOriginals;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ public class ConvertMojo extends AbstractMojo {
|
|||||||
File outputFolderWithContracts = this.stubsDirectory.getPath().endsWith("contracts") ? this.stubsDirectory
|
File outputFolderWithContracts = this.stubsDirectory.getPath().endsWith("contracts") ? this.stubsDirectory
|
||||||
: new File(this.stubsDirectory, rootPath + CONTRACTS_PATH);
|
: new File(this.stubsDirectory, rootPath + CONTRACTS_PATH);
|
||||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)
|
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)
|
||||||
.copy(contractsDirectory, outputFolderWithContracts);
|
.copy(contractsDirectory, outputFolderWithContracts);
|
||||||
return outputFolderWithContracts;
|
return outputFolderWithContracts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ public class ConvertMojo extends AbstractMojo {
|
|||||||
this.contractsRepositoryUrl, this.contractsMode, getLog(), this.contractsRepositoryUsername,
|
this.contractsRepositoryUrl, this.contractsMode, getLog(), this.contractsRepositoryUsername,
|
||||||
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort,
|
this.contractsRepositoryPassword, this.contractsRepositoryProxyHost, this.contractsRepositoryProxyPort,
|
||||||
this.deleteStubsAfterTest, this.contractsProperties, this.failOnNoContracts)
|
this.deleteStubsAfterTest, this.contractsProperties, this.failOnNoContracts)
|
||||||
.downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
.downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private File stubsOutputDir(String rootPath) {
|
private File stubsOutputDir(String rootPath) {
|
||||||
|
|||||||
@@ -254,8 +254,8 @@ public class GenerateTestsMojo extends AbstractMojo {
|
|||||||
+ this.skip);
|
+ this.skip);
|
||||||
}
|
}
|
||||||
if (this.mavenTestSkip) {
|
if (this.mavenTestSkip) {
|
||||||
getLog().info(
|
getLog()
|
||||||
"Skipping Spring Cloud Contract Verifier execution: maven.test.skip=" + this.mavenTestSkip);
|
.info("Skipping Spring Cloud Contract Verifier execution: maven.test.skip=" + this.mavenTestSkip);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,8 @@ public class GenerateTestsMojo extends AbstractMojo {
|
|||||||
this.contractsPath, this.contractsRepositoryUrl, this.contractsMode, getLog(),
|
this.contractsPath, this.contractsRepositoryUrl, this.contractsMode, getLog(),
|
||||||
this.contractsRepositoryUsername, this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
|
this.contractsRepositoryUsername, this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,
|
||||||
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest, this.contractsProperties,
|
this.contractsRepositoryProxyPort, this.deleteStubsAfterTest, this.contractsProperties,
|
||||||
this.failOnNoContracts).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
this.failOnNoContracts)
|
||||||
|
.downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||||
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
|
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
|
||||||
throwExceptionWhenFailOnNoContracts(contractsDirectory, this.contractsRepositoryUrl);
|
throwExceptionWhenFailOnNoContracts(contractsDirectory, this.contractsRepositoryUrl);
|
||||||
|
|
||||||
@@ -307,8 +308,8 @@ public class GenerateTestsMojo extends AbstractMojo {
|
|||||||
throws MojoExecutionException {
|
throws MojoExecutionException {
|
||||||
if (StringUtils.hasText(contractsRepository)) {
|
if (StringUtils.hasText(contractsRepository)) {
|
||||||
if (getLog().isDebugEnabled()) {
|
if (getLog().isDebugEnabled()) {
|
||||||
getLog().debug(
|
getLog()
|
||||||
"Contracts repository is set, will not throw an exception that the contracts are not found");
|
.debug("Contracts repository is set, will not throw an exception that the contracts are not found");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ class LeftOverPrevention {
|
|||||||
this.generatedDirectory = generatedDirectory;
|
this.generatedDirectory = generatedDirectory;
|
||||||
this.incrementalBuildHelper = new IncrementalBuildHelper(mojoExecution, session);
|
this.incrementalBuildHelper = new IncrementalBuildHelper(mojoExecution, session);
|
||||||
this.incrementalBuildHelper
|
this.incrementalBuildHelper
|
||||||
.beforeRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
|
.beforeRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteLeftOvers() throws MojoExecutionException {
|
void deleteLeftOvers() throws MojoExecutionException {
|
||||||
if (generatedDirectory.exists()) {
|
if (generatedDirectory.exists()) {
|
||||||
incrementalBuildHelper
|
incrementalBuildHelper
|
||||||
.afterRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
|
.afterRebuildExecution(new IncrementalBuildHelperRequest().outputDirectory(generatedDirectory));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class MavenContractsDownloader {
|
|||||||
this.log.info("Another mojo has downloaded the contracts - will reuse them from [" + downloadedContractsDir
|
this.log.info("Another mojo has downloaded the contracts - will reuse them from [" + downloadedContractsDir
|
||||||
+ "]");
|
+ "]");
|
||||||
final ContractDownloader.InclusionProperties inclusionProperties = contractDownloader()
|
final ContractDownloader.InclusionProperties inclusionProperties = contractDownloader()
|
||||||
.createNewInclusionProperties(downloadedContractsDir);
|
.createNewInclusionProperties(downloadedContractsDir);
|
||||||
config.setIncludedContracts(inclusionProperties.getIncludedContracts());
|
config.setIncludedContracts(inclusionProperties.getIncludedContracts());
|
||||||
config.setIncludedRootFolderAntPattern(inclusionProperties.getIncludedRootFolderAntPattern());
|
config.setIncludedRootFolderAntPattern(inclusionProperties.getIncludedRootFolderAntPattern());
|
||||||
return downloadedContractsDir;
|
return downloadedContractsDir;
|
||||||
@@ -111,7 +111,7 @@ class MavenContractsDownloader {
|
|||||||
final ContractDownloader contractDownloader = contractDownloader();
|
final ContractDownloader contractDownloader = contractDownloader();
|
||||||
final File downloadedContracts = contractDownloader.unpackAndDownloadContracts();
|
final File downloadedContracts = contractDownloader.unpackAndDownloadContracts();
|
||||||
final ContractDownloader.InclusionProperties inclusionProperties = contractDownloader
|
final ContractDownloader.InclusionProperties inclusionProperties = contractDownloader
|
||||||
.createNewInclusionProperties(downloadedContracts);
|
.createNewInclusionProperties(downloadedContracts);
|
||||||
config.setIncludedContracts(inclusionProperties.getIncludedContracts());
|
config.setIncludedContracts(inclusionProperties.getIncludedContracts());
|
||||||
config.setIncludedRootFolderAntPattern(inclusionProperties.getIncludedRootFolderAntPattern());
|
config.setIncludedRootFolderAntPattern(inclusionProperties.getIncludedRootFolderAntPattern());
|
||||||
this.project.getProperties().setProperty(directoryProperty(), downloadedContracts.getAbsolutePath());
|
this.project.getProperties().setProperty(directoryProperty(), downloadedContracts.getAbsolutePath());
|
||||||
@@ -147,10 +147,13 @@ class MavenContractsDownloader {
|
|||||||
|
|
||||||
StubRunnerOptions buildOptions() {
|
StubRunnerOptions buildOptions() {
|
||||||
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
||||||
.withOptions(StubRunnerOptions.fromSystemProps()).withStubsMode(this.stubsMode)
|
.withOptions(StubRunnerOptions.fromSystemProps())
|
||||||
.withUsername(this.repositoryUsername).withPassword(this.repositoryPassword)
|
.withStubsMode(this.stubsMode)
|
||||||
.withDeleteStubsAfterTest(this.deleteStubsAfterTest).withProperties(this.contractsProperties)
|
.withUsername(this.repositoryUsername)
|
||||||
.withFailOnNoStubs(this.failOnNoStubs);
|
.withPassword(this.repositoryPassword)
|
||||||
|
.withDeleteStubsAfterTest(this.deleteStubsAfterTest)
|
||||||
|
.withProperties(this.contractsProperties)
|
||||||
|
.withFailOnNoStubs(this.failOnNoStubs);
|
||||||
if (StringUtils.hasText(this.contractsRepositoryUrl)) {
|
if (StringUtils.hasText(this.contractsRepositoryUrl)) {
|
||||||
builder.withStubRepositoryRoot(this.contractsRepositoryUrl);
|
builder.withStubRepositoryRoot(this.contractsRepositoryUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,10 +122,13 @@ public class PushStubsToScmMojo extends AbstractMojo {
|
|||||||
|
|
||||||
StubRunnerOptions buildOptions() {
|
StubRunnerOptions buildOptions() {
|
||||||
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
StubRunnerOptionsBuilder builder = new StubRunnerOptionsBuilder()
|
||||||
.withOptions(StubRunnerOptions.fromSystemProps()).withStubRepositoryRoot(this.contractsRepositoryUrl)
|
.withOptions(StubRunnerOptions.fromSystemProps())
|
||||||
.withStubsMode(this.contractsMode).withUsername(this.contractsRepositoryUsername)
|
.withStubRepositoryRoot(this.contractsRepositoryUrl)
|
||||||
.withPassword(this.contractsRepositoryPassword).withDeleteStubsAfterTest(this.deleteStubsAfterTest)
|
.withStubsMode(this.contractsMode)
|
||||||
.withProperties(this.contractsProperties);
|
.withUsername(this.contractsRepositoryUsername)
|
||||||
|
.withPassword(this.contractsRepositoryPassword)
|
||||||
|
.withDeleteStubsAfterTest(this.deleteStubsAfterTest)
|
||||||
|
.withProperties(this.contractsProperties);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,15 +132,17 @@ public class RunMojo extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
BatchStubRunner batchStubRunner = null;
|
BatchStubRunner batchStubRunner = null;
|
||||||
StubRunnerOptionsBuilder optionsBuilder = new StubRunnerOptionsBuilder()
|
StubRunnerOptionsBuilder optionsBuilder = new StubRunnerOptionsBuilder()
|
||||||
.withStubsClassifier(this.stubsClassifier);
|
.withStubsClassifier(this.stubsClassifier);
|
||||||
if (!StringUtils.hasText(this.stubs)) {
|
if (!StringUtils.hasText(this.stubs)) {
|
||||||
StubRunnerOptions options = optionsBuilder.withMinMaxPort(this.httpPort, this.httpPort).build();
|
StubRunnerOptions options = optionsBuilder.withMinMaxPort(this.httpPort, this.httpPort).build();
|
||||||
StubRunner stubRunner = this.localStubRunner.run(resolveStubsDirectory().getAbsolutePath(), options);
|
StubRunner stubRunner = this.localStubRunner.run(resolveStubsDirectory().getAbsolutePath(), options);
|
||||||
batchStubRunner = new BatchStubRunner(Collections.singleton(stubRunner));
|
batchStubRunner = new BatchStubRunner(Collections.singleton(stubRunner));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StubRunnerOptions options = optionsBuilder.withStubs(this.stubs).withMinMaxPort(this.minPort, this.maxPort)
|
StubRunnerOptions options = optionsBuilder.withStubs(this.stubs)
|
||||||
.withServerId(this.serverId).build();
|
.withMinMaxPort(this.minPort, this.maxPort)
|
||||||
|
.withServerId(this.serverId)
|
||||||
|
.build();
|
||||||
batchStubRunner = this.remoteStubRunner.run(options, this.repoSession);
|
batchStubRunner = this.remoteStubRunner.run(options, this.repoSession);
|
||||||
}
|
}
|
||||||
pressAnyKeyToContinue();
|
pressAnyKeyToContinue();
|
||||||
|
|||||||
@@ -50,23 +50,27 @@ class MavenContractsDownloaderTests {
|
|||||||
MavenContractsDownloader mavenContractsDownloader = contractsDownloader(mavenProject, one,
|
MavenContractsDownloader mavenContractsDownloader = contractsDownloader(mavenProject, one,
|
||||||
this.fileForDependencyOne);
|
this.fileForDependencyOne);
|
||||||
File dependencyOneFile = mavenContractsDownloader
|
File dependencyOneFile = mavenContractsDownloader
|
||||||
.downloadAndUnpackContractsIfRequired(new ContractVerifierConfigProperties(), this.defaultFolder);
|
.downloadAndUnpackContractsIfRequired(new ContractVerifierConfigProperties(), this.defaultFolder);
|
||||||
BDDAssertions.then(dependencyOneFile).as("Location for dependency 1 should be computed since it's not cached")
|
BDDAssertions.then(dependencyOneFile)
|
||||||
.isEqualTo(this.fileForDependencyOne);
|
.as("Location for dependency 1 should be computed since it's not cached")
|
||||||
|
.isEqualTo(this.fileForDependencyOne);
|
||||||
|
|
||||||
mavenContractsDownloader = contractsDownloader(mavenProject, one, this.fileForDependencyOne);
|
mavenContractsDownloader = contractsDownloader(mavenProject, one, this.fileForDependencyOne);
|
||||||
File fileForDependencyOneAgain = mavenContractsDownloader
|
File fileForDependencyOneAgain = mavenContractsDownloader
|
||||||
.downloadAndUnpackContractsIfRequired(new ContractVerifierConfigProperties(), this.defaultFolder);
|
.downloadAndUnpackContractsIfRequired(new ContractVerifierConfigProperties(), this.defaultFolder);
|
||||||
BDDAssertions.then(dependencyOneFile).as("Location for dependency 1 should be taken from cache")
|
BDDAssertions.then(dependencyOneFile)
|
||||||
.isEqualTo(fileForDependencyOneAgain);
|
.as("Location for dependency 1 should be taken from cache")
|
||||||
|
.isEqualTo(fileForDependencyOneAgain);
|
||||||
|
|
||||||
Dependency two = dependency(2);
|
Dependency two = dependency(2);
|
||||||
mavenContractsDownloader = contractsDownloader(mavenProject, two, this.fileForDependencyTwo);
|
mavenContractsDownloader = contractsDownloader(mavenProject, two, this.fileForDependencyTwo);
|
||||||
File dependencyTwoFile = mavenContractsDownloader
|
File dependencyTwoFile = mavenContractsDownloader
|
||||||
.downloadAndUnpackContractsIfRequired(new ContractVerifierConfigProperties(), this.defaultFolder);
|
.downloadAndUnpackContractsIfRequired(new ContractVerifierConfigProperties(), this.defaultFolder);
|
||||||
|
|
||||||
BDDAssertions.then(dependencyTwoFile).as("Location for dependency 2 should be computed again")
|
BDDAssertions.then(dependencyTwoFile)
|
||||||
.isNotEqualTo(dependencyOneFile).isEqualTo(this.fileForDependencyTwo);
|
.as("Location for dependency 2 should be computed again")
|
||||||
|
.isNotEqualTo(dependencyOneFile)
|
||||||
|
.isEqualTo(this.fileForDependencyTwo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MavenContractsDownloader contractsDownloader(MavenProject mavenProject, Dependency one, File file) {
|
private MavenContractsDownloader contractsDownloader(MavenProject mavenProject, Dependency one, File file) {
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
executeMojo(basedir, "convert");
|
executeMojo(basedir, "convert");
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/mappings/Sample.json"
|
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/mappings/Sample.json"
|
||||||
.replace("/", File.separator));
|
.replace("/", File.separator));
|
||||||
assertFilesNotPresent(basedir,
|
assertFilesNotPresent(basedir,
|
||||||
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/mappings/Messaging.json"
|
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/mappings/Messaging.json"
|
||||||
.replace("/", File.separator));
|
.replace("/", File.separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Xpp3Dom defaultPackageForTests() {
|
private Xpp3Dom defaultPackageForTests() {
|
||||||
@@ -54,7 +54,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
executeMojo(basedir, "convert", newParameter("contractsDirectory", "src/test/resources/stubs"));
|
executeMojo(basedir, "convert", newParameter("contractsDirectory", "src/test/resources/stubs"));
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/mappings/Sample.json"
|
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/mappings/Sample.json"
|
||||||
.replace("/", File.separator));
|
.replace("/", File.separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,10 +63,10 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
executeMojo(basedir, "convert");
|
executeMojo(basedir, "convert");
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/contracts/Sample.groovy"
|
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/contracts/Sample.groovy"
|
||||||
.replace("/", File.separator));
|
.replace("/", File.separator));
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/contracts/Messaging.groovy"
|
"target/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/contracts/Messaging.groovy"
|
||||||
.replace("/", File.separator));
|
.replace("/", File.separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -150,8 +150,12 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldGenerateStubsByDownloadingContractsFromARepo() throws Exception {
|
public void shouldGenerateStubsByDownloadingContractsFromARepo() throws Exception {
|
||||||
File basedir = getBasedir("basic-remote-contracts");
|
File basedir = getBasedir("basic-remote-contracts");
|
||||||
executeMojo(basedir, "convert", newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class
|
executeMojo(basedir, "convert",
|
||||||
.getClassLoader().getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
newParameter("contractsRepositoryUrl",
|
||||||
|
"file://" + PluginUnitTest.class.getClassLoader()
|
||||||
|
.getResource("m2repo/repository")
|
||||||
|
.getFile()
|
||||||
|
.replace("/", File.separator)));
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/stubs/META-INF/com.example/server/0.1.BUILD-SNAPSHOT/mappings/com/example/server/client1/contracts/shouldMarkClientAsFraud.json");
|
"target/stubs/META-INF/com.example/server/0.1.BUILD-SNAPSHOT/mappings/com/example/server/client1/contracts/shouldMarkClientAsFraud.json");
|
||||||
}
|
}
|
||||||
@@ -159,8 +163,12 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldGenerateStubsByDownloadingContractsFromARepoWhenCustomPathIsProvided() throws Exception {
|
public void shouldGenerateStubsByDownloadingContractsFromARepoWhenCustomPathIsProvided() throws Exception {
|
||||||
File basedir = getBasedir("complex-remote-contracts");
|
File basedir = getBasedir("complex-remote-contracts");
|
||||||
executeMojo(basedir, "convert", newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class
|
executeMojo(basedir, "convert",
|
||||||
.getClassLoader().getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
newParameter("contractsRepositoryUrl",
|
||||||
|
"file://" + PluginUnitTest.class.getClassLoader()
|
||||||
|
.getResource("m2repo/repository")
|
||||||
|
.getFile()
|
||||||
|
.replace("/", File.separator)));
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/stubs/META-INF/com.example.foo.bar.baz/someartifact/0.1.BUILD-SNAPSHOT/mappings/com/example/server/client1/contracts/shouldMarkClientAsFraud.json");
|
"target/stubs/META-INF/com.example.foo.bar.baz/someartifact/0.1.BUILD-SNAPSHOT/mappings/com/example/server/client1/contracts/shouldMarkClientAsFraud.json");
|
||||||
assertFilesNotPresent(basedir,
|
assertFilesNotPresent(basedir,
|
||||||
@@ -189,8 +197,11 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
public void shouldGenerateTestsByDownloadingContractsFromARepo() throws Exception {
|
public void shouldGenerateTestsByDownloadingContractsFromARepo() throws Exception {
|
||||||
File basedir = getBasedir("basic-remote-contracts");
|
File basedir = getBasedir("basic-remote-contracts");
|
||||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||||
newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader()
|
newParameter("contractsRepositoryUrl",
|
||||||
.getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
"file://" + PluginUnitTest.class.getClassLoader()
|
||||||
|
.getResource("m2repo/repository")
|
||||||
|
.getFile()
|
||||||
|
.replace("/", File.separator)));
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/example/server/client1/ContractsTest.java");
|
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/example/server/client1/ContractsTest.java");
|
||||||
}
|
}
|
||||||
@@ -199,8 +210,11 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
public void shouldGenerateTestsByDownloadingContractsFromARepoWhenCustomPathIsProvided() throws Exception {
|
public void shouldGenerateTestsByDownloadingContractsFromARepoWhenCustomPathIsProvided() throws Exception {
|
||||||
File basedir = getBasedir("complex-remote-contracts");
|
File basedir = getBasedir("complex-remote-contracts");
|
||||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||||
newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader()
|
newParameter("contractsRepositoryUrl",
|
||||||
.getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
"file://" + PluginUnitTest.class.getClassLoader()
|
||||||
|
.getResource("m2repo/repository")
|
||||||
|
.getFile()
|
||||||
|
.replace("/", File.separator)));
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/example/server/client1/ContractsTest.java");
|
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/example/server/client1/ContractsTest.java");
|
||||||
assertFilesNotPresent(basedir,
|
assertFilesNotPresent(basedir,
|
||||||
@@ -218,7 +232,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
assertFilesPresent(basedir, path);
|
assertFilesPresent(basedir, path);
|
||||||
File test = new File(basedir, path);
|
File test = new File(basedir, path);
|
||||||
then(readFileToString(test, defaultCharset())).contains("extends HelloV1Base")
|
then(readFileToString(test, defaultCharset())).contains("extends HelloV1Base")
|
||||||
.contains("import hello.HelloV1Base");
|
.contains("import hello.HelloV1Base");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -231,7 +245,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
assertFilesPresent(basedir, path);
|
assertFilesPresent(basedir, path);
|
||||||
File test = new File(basedir, path);
|
File test = new File(basedir, path);
|
||||||
then(readFileToString(test, defaultCharset())).contains("extends HelloV1Base")
|
then(readFileToString(test, defaultCharset())).contains("extends HelloV1Base")
|
||||||
.contains("import hello.HelloV1Base");
|
.contains("import hello.HelloV1Base");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -244,7 +258,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
assertFilesPresent(basedir, path);
|
assertFilesPresent(basedir, path);
|
||||||
File test = new File(basedir, path);
|
File test = new File(basedir, path);
|
||||||
then(readFileToString(test, defaultCharset())).contains("extends TestBase")
|
then(readFileToString(test, defaultCharset())).contains("extends TestBase")
|
||||||
.contains("import com.example.TestBase");
|
.contains("import com.example.TestBase");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -257,7 +271,7 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
assertFilesPresent(basedir, path);
|
assertFilesPresent(basedir, path);
|
||||||
File test = new File(basedir, path);
|
File test = new File(basedir, path);
|
||||||
then(readFileToString(test, defaultCharset())).contains("extends TestBase")
|
then(readFileToString(test, defaultCharset())).contains("extends TestBase")
|
||||||
.contains("import com.example.TestBase");
|
.contains("import com.example.TestBase");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -270,8 +284,8 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
assertFilesPresent(basedir, path);
|
assertFilesPresent(basedir, path);
|
||||||
File test = new File(basedir, path);
|
File test = new File(basedir, path);
|
||||||
then(readFileToString(test, defaultCharset()))
|
then(readFileToString(test, defaultCharset()))
|
||||||
.contains("public void validate_should_post_a_user() throws Exception {")
|
.contains("public void validate_should_post_a_user() throws Exception {")
|
||||||
.contains("public void validate_withList_1() throws Exception {");
|
.contains("public void validate_withList_1() throws Exception {");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -322,8 +336,11 @@ public class PluginUnitTest extends AbstractMojoTest {
|
|||||||
File basedir = getBasedir("complex-common-repo-with-messaging");
|
File basedir = getBasedir("complex-common-repo-with-messaging");
|
||||||
|
|
||||||
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
executeMojo(basedir, "generateTests", defaultPackageForTests(),
|
||||||
newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader()
|
newParameter("contractsRepositoryUrl",
|
||||||
.getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
"file://" + PluginUnitTest.class.getClassLoader()
|
||||||
|
.getResource("m2repo/repository")
|
||||||
|
.getFile()
|
||||||
|
.replace("/", File.separator)));
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/common_repo_with_inclusion/kafka_topics/coupon_sent/src/main/resources/contracts/rule_engine_daemon/MessagingTest.java");
|
"target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/common_repo_with_inclusion/kafka_topics/coupon_sent/src/main/resources/contracts/rule_engine_daemon/MessagingTest.java");
|
||||||
assertFilesPresent(basedir,
|
assertFilesPresent(basedir,
|
||||||
|
|||||||
@@ -84,10 +84,14 @@ public class TestGenerator {
|
|||||||
|
|
||||||
public TestGenerator(ContractVerifierConfigProperties configProperties, SingleTestGenerator generator,
|
public TestGenerator(ContractVerifierConfigProperties configProperties, SingleTestGenerator generator,
|
||||||
FileSaver saver) {
|
FileSaver saver) {
|
||||||
this(configProperties, generator, saver, ContractFileScanner.builder()
|
this(configProperties, generator, saver,
|
||||||
.baseDir(configProperties.getContractsDslDir()).excluded(toSet(configProperties.getExcludedFiles()))
|
ContractFileScanner.builder()
|
||||||
.ignored(toSet(configProperties.getIgnoredFiles())).included(toSet(configProperties.getIncludedFiles()))
|
.baseDir(configProperties.getContractsDslDir())
|
||||||
.includeMatcher(configProperties.getIncludedContracts()).build());
|
.excluded(toSet(configProperties.getExcludedFiles()))
|
||||||
|
.ignored(toSet(configProperties.getIgnoredFiles()))
|
||||||
|
.included(toSet(configProperties.getIncludedFiles()))
|
||||||
|
.includeMatcher(configProperties.getIncludedContracts())
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> toSet(List<String> files) {
|
private static Set<String> toSet(List<String> files) {
|
||||||
@@ -133,8 +137,10 @@ public class TestGenerator {
|
|||||||
|
|
||||||
Set<Map.Entry<Path, List<ContractMetadata>>> inProgress = inProgress(contracts);
|
Set<Map.Entry<Path, List<ContractMetadata>>> inProgress = inProgress(contracts);
|
||||||
if (!inProgress.isEmpty() && configProperties.isFailOnInProgress()) {
|
if (!inProgress.isEmpty() && configProperties.isFailOnInProgress()) {
|
||||||
String inProgressContractsPaths = inProgress.stream().map(Map.Entry::getKey).map(Path::toString)
|
String inProgressContractsPaths = inProgress.stream()
|
||||||
.collect(Collectors.joining(","));
|
.map(Map.Entry::getKey)
|
||||||
|
.map(Path::toString)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
throw new IllegalStateException("In progress contracts found in paths [" + inProgressContractsPaths
|
throw new IllegalStateException("In progress contracts found in paths [" + inProgressContractsPaths
|
||||||
+ "] and the switch [failOnInProgress] is set to [true]. Either unmark those contracts as in progress, or set the switch to [false].");
|
+ "] and the switch [failOnInProgress] is set to [true]. Either unmark those contracts as in progress, or set the switch to [false].");
|
||||||
}
|
}
|
||||||
@@ -142,14 +148,17 @@ public class TestGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Set<Map.Entry<Path, List<ContractMetadata>>> inProgress(MultiValueMap<Path, ContractMetadata> contracts) {
|
private Set<Map.Entry<Path, List<ContractMetadata>>> inProgress(MultiValueMap<Path, ContractMetadata> contracts) {
|
||||||
return contracts.entrySet().stream()
|
return contracts.entrySet()
|
||||||
.filter(entry -> entry.getValue().stream().anyMatch(ContractMetadata::anyInProgress))
|
.stream()
|
||||||
.collect(Collectors.toSet());
|
.filter(entry -> entry.getValue().stream().anyMatch(ContractMetadata::anyInProgress))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
void processAll(MultiValueMap<Path, ContractMetadata> contracts, final String basePackageName) {
|
void processAll(MultiValueMap<Path, ContractMetadata> contracts, final String basePackageName) {
|
||||||
contracts.entrySet().stream().forEach(
|
contracts.entrySet()
|
||||||
entry -> processIncludedDirectory(relativizeContractPath(entry), entry.getValue(), basePackageName));
|
.stream()
|
||||||
|
.forEach(entry -> processIncludedDirectory(relativizeContractPath(entry), entry.getValue(),
|
||||||
|
basePackageName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String relativizeContractPath(Map.Entry<Path, List<ContractMetadata>> entry) {
|
private String relativizeContractPath(Map.Entry<Path, List<ContractMetadata>> entry) {
|
||||||
@@ -169,9 +178,9 @@ public class TestGenerator {
|
|||||||
convertIllegalPackageChars(includedDirectoryRelativePath));
|
convertIllegalPackageChars(includedDirectoryRelativePath));
|
||||||
Path classPath = saver.pathToClass(dir, convertedClassName);
|
Path classPath = saver.pathToClass(dir, convertedClassName);
|
||||||
byte[] classBytes = generator
|
byte[] classBytes = generator
|
||||||
.buildClass(configProperties, contracts, includedDirectoryRelativePath,
|
.buildClass(configProperties, contracts, includedDirectoryRelativePath,
|
||||||
new SingleTestGenerator.GeneratedClassData(convertedClassName, packageName, classPath))
|
new SingleTestGenerator.GeneratedClassData(convertedClassName, packageName, classPath))
|
||||||
.getBytes(StandardCharsets.UTF_8);
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
saver.saveClassFile(classPath, classBytes);
|
saver.saveClassFile(classPath, classBytes);
|
||||||
counter.incrementAndGet();
|
counter.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,9 @@ interface BodyMethodVisitor {
|
|||||||
*/
|
*/
|
||||||
default List<MethodVisitor> filterVisitors(List<? extends MethodVisitor> methodVisitors,
|
default List<MethodVisitor> filterVisitors(List<? extends MethodVisitor> methodVisitors,
|
||||||
SingleContractMetadata singleContractMetadata) {
|
SingleContractMetadata singleContractMetadata) {
|
||||||
return methodVisitors.stream().filter(given -> given.accept(singleContractMetadata))
|
return methodVisitors.stream()
|
||||||
.collect(Collectors.toList());
|
.filter(given -> given.accept(singleContractMetadata))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -101,8 +101,9 @@ interface BodyParser extends BodyThen {
|
|||||||
else if (bodyValue instanceof List) {
|
else if (bodyValue instanceof List) {
|
||||||
// ["a=3", "b=4"] == "a=3&b=4"
|
// ["a=3", "b=4"] == "a=3&b=4"
|
||||||
return ((List) bodyValue).stream()
|
return ((List) bodyValue).stream()
|
||||||
.map(o -> convertUnicodeEscapesIfRequired(MapConverter.getTestSideValuesForText(o).toString()))
|
.map(o -> convertUnicodeEscapesIfRequired(MapConverter.getTestSideValuesForText(o).toString()))
|
||||||
.collect(Collectors.joining("&")).toString();
|
.collect(Collectors.joining("&"))
|
||||||
|
.toString();
|
||||||
}
|
}
|
||||||
else if (bodyValue instanceof String) {
|
else if (bodyValue instanceof String) {
|
||||||
return (String) bodyValue;
|
return (String) bodyValue;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ interface CookieElementProcessor {
|
|||||||
if (value instanceof NotToEscapePattern) {
|
if (value instanceof NotToEscapePattern) {
|
||||||
verifyCookieNotNull(property);
|
verifyCookieNotNull(property);
|
||||||
return comparisonBuilder().assertThat(cookieValue(property)) + comparisonBuilder()
|
return comparisonBuilder().assertThat(cookieValue(property)) + comparisonBuilder()
|
||||||
.matches(((NotToEscapePattern) value).getServerValue().pattern().replace("\\", "\\\\"));
|
.matches(((NotToEscapePattern) value).getServerValue().pattern().replace("\\", "\\\\"));
|
||||||
}
|
}
|
||||||
else if (value instanceof String || value instanceof Pattern) {
|
else if (value instanceof String || value instanceof Pattern) {
|
||||||
verifyCookieNotNull(property);
|
verifyCookieNotNull(property);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class CustomModeGiven implements Given, BodyMethodVisitor, CustomModeAcceptor {
|
|||||||
this.blockBuilder = blockBuilder;
|
this.blockBuilder = blockBuilder;
|
||||||
this.generatedClassMetaData = generatedClassMetaData;
|
this.generatedClassMetaData = generatedClassMetaData;
|
||||||
this.requestGivens
|
this.requestGivens
|
||||||
.addAll(Collections.singletonList(new CustomModeRequestGiven(blockBuilder, generatedClassMetaData)));
|
.addAll(Collections.singletonList(new CustomModeRequestGiven(blockBuilder, generatedClassMetaData)));
|
||||||
this.bodyGivens.addAll(Arrays.asList(new CustomModeMethodWithUrlGiven(blockBuilder, bodyParser),
|
this.bodyGivens.addAll(Arrays.asList(new CustomModeMethodWithUrlGiven(blockBuilder, bodyParser),
|
||||||
new CustomModeQueryParamsGiven(blockBuilder, bodyParser),
|
new CustomModeQueryParamsGiven(blockBuilder, bodyParser),
|
||||||
new CustomModeSchemeProtocolGiven(blockBuilder), new CustomModeHeadersGiven(blockBuilder),
|
new CustomModeSchemeProtocolGiven(blockBuilder), new CustomModeHeadersGiven(blockBuilder),
|
||||||
@@ -56,10 +56,12 @@ class CustomModeGiven implements Given, BodyMethodVisitor, CustomModeAcceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addRequestGivenLine(SingleContractMetadata singleContractMetadata) {
|
private void addRequestGivenLine(SingleContractMetadata singleContractMetadata) {
|
||||||
this.requestGivens.stream().filter(given -> given.accept(singleContractMetadata)).findFirst()
|
this.requestGivens.stream()
|
||||||
.orElseThrow(() -> new IllegalStateException(
|
.filter(given -> given.accept(singleContractMetadata))
|
||||||
"No matching request building Given implementation for a custom test mode"))
|
.findFirst()
|
||||||
.apply(singleContractMetadata);
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
|
"No matching request building Given implementation for a custom test mode"))
|
||||||
|
.apply(singleContractMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class CustomModeHeadersGiven implements Given {
|
|||||||
private String string(Header header) {
|
private String string(Header header) {
|
||||||
return ".header("
|
return ".header("
|
||||||
+ ContentHelper.getTestSideForNonBodyValue(header.getName()) + ", " + ContentHelper
|
+ ContentHelper.getTestSideForNonBodyValue(header.getName()) + ", " + ContentHelper
|
||||||
.getTestSideForNonBodyValue(MapConverter.getTestSideValuesForNonBody(header.getServerValue()))
|
.getTestSideForNonBodyValue(MapConverter.getTestSideValuesForNonBody(header.getServerValue()))
|
||||||
+ ")";
|
+ ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,11 @@ class CustomModeQueryParamsGiven implements Given, CustomModeAcceptor, QueryPara
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addQueryParameters(Url buildUrl) {
|
private void addQueryParameters(Url buildUrl) {
|
||||||
List<QueryParameter> queryParameters = buildUrl.getQueryParameters().getParameters().stream()
|
List<QueryParameter> queryParameters = buildUrl.getQueryParameters()
|
||||||
.filter(this::allowedQueryParameter).collect(Collectors.toList());
|
.getParameters()
|
||||||
|
.stream()
|
||||||
|
.filter(this::allowedQueryParameter)
|
||||||
|
.collect(Collectors.toList());
|
||||||
Iterator<QueryParameter> iterator = queryParameters.iterator();
|
Iterator<QueryParameter> iterator = queryParameters.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
QueryParameter parameter = iterator.next();
|
QueryParameter parameter = iterator.next();
|
||||||
@@ -84,7 +87,7 @@ class CustomModeQueryParamsGiven implements Given, CustomModeAcceptor, QueryPara
|
|||||||
|
|
||||||
private String addQueryParameter(QueryParameter queryParam) {
|
private String addQueryParameter(QueryParameter queryParam) {
|
||||||
return "." + "queryParam(" + this.bodyParser.quotedLongText(queryParam.getName()) + "," + this.bodyParser
|
return "." + "queryParam(" + this.bodyParser.quotedLongText(queryParam.getName()) + "," + this.bodyParser
|
||||||
.quotedLongText(resolveParamValue(MapConverter.getTestSideValuesForNonBody(queryParam))) + ")";
|
.quotedLongText(resolveParamValue(MapConverter.getTestSideValuesForNonBody(queryParam))) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ class CustomModeStatusCodeThen implements Then {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
||||||
Response response = metadata.getContract().getResponse();
|
Response response = metadata.getContract().getResponse();
|
||||||
this.blockBuilder.addIndented(
|
this.blockBuilder
|
||||||
this.comparisonBuilder.assertThat("response.statusCode()", response.getStatus().getServerValue()))
|
.addIndented(
|
||||||
.addEndingIfNotPresent();
|
this.comparisonBuilder.assertThat("response.statusCode()", response.getStatus().getServerValue()))
|
||||||
|
.addEndingIfNotPresent();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,12 @@ class CustomModeWhen implements When, BodyMethodVisitor, CustomModeAcceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addResponseWhenLine(SingleContractMetadata singleContractMetadata) {
|
private void addResponseWhenLine(SingleContractMetadata singleContractMetadata) {
|
||||||
this.responseWhens.stream().filter(when -> when.accept(singleContractMetadata)).findFirst().orElseThrow(
|
this.responseWhens.stream()
|
||||||
() -> new IllegalStateException("No matching request building When implementation for Rest Assured"))
|
.filter(when -> when.accept(singleContractMetadata))
|
||||||
.apply(singleContractMetadata);
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
|
"No matching request building When implementation for Rest Assured"))
|
||||||
|
.apply(singleContractMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -41,8 +41,10 @@ class DefaultJsonStaticImports implements Imports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.listOfFiles.stream().anyMatch(metadata -> metadata
|
return this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.getConvertedContractWithMetadata().stream().anyMatch(SingleContractMetadata::isJson));
|
.anyMatch(metadata -> metadata.getConvertedContractWithMetadata()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(SingleContractMetadata::isJson));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,9 @@ class GeneratedClassMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Collection<SingleContractMetadata> toSingleContractMetadata() {
|
Collection<SingleContractMetadata> toSingleContractMetadata() {
|
||||||
return this.listOfFiles.stream().flatMap(metadata -> metadata.getConvertedContractWithMetadata().stream())
|
return this.listOfFiles.stream()
|
||||||
.collect(Collectors.toList());
|
.flatMap(metadata -> metadata.getConvertedContractWithMetadata().stream())
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAnyJson() {
|
boolean isAnyJson() {
|
||||||
|
|||||||
@@ -126,11 +126,14 @@ class GeneratedTestClassBuilder {
|
|||||||
*/
|
*/
|
||||||
GeneratedTestClass build() {
|
GeneratedTestClass build() {
|
||||||
// picks a matching class meta data
|
// picks a matching class meta data
|
||||||
ClassMetaData classMetaData = this.metaData.stream().filter(Acceptor::accept).findFirst()
|
ClassMetaData classMetaData = this.metaData.stream()
|
||||||
.orElseThrow(() -> new IllegalStateException("There is no matching class meta data"));
|
.filter(Acceptor::accept)
|
||||||
classMetaData.setupLineEnding().setupLabelPrefix()
|
.findFirst()
|
||||||
// package com.example
|
.orElseThrow(() -> new IllegalStateException("There is no matching class meta data"));
|
||||||
.packageDefinition();
|
classMetaData.setupLineEnding()
|
||||||
|
.setupLabelPrefix()
|
||||||
|
// package com.example
|
||||||
|
.packageDefinition();
|
||||||
// \n
|
// \n
|
||||||
this.blockBuilder.addEmptyLine();
|
this.blockBuilder.addEmptyLine();
|
||||||
// import ... \n
|
// import ... \n
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ class GenericHttpBodyThen implements Then, BodyMethodVisitor {
|
|||||||
this.bodyParser = bodyParser;
|
this.bodyParser = bodyParser;
|
||||||
this.comparisonBuilder = comparisonBuilder;
|
this.comparisonBuilder = comparisonBuilder;
|
||||||
this.templateProcessor = new HandlebarsTemplateProcessor();
|
this.templateProcessor = new HandlebarsTemplateProcessor();
|
||||||
this.thens.addAll(
|
this.thens
|
||||||
Arrays.asList(new GenericBinaryBodyThen(blockBuilder, metaData, this.bodyParser, comparisonBuilder),
|
.addAll(Arrays.asList(new GenericBinaryBodyThen(blockBuilder, metaData, this.bodyParser, comparisonBuilder),
|
||||||
new GenericTextBodyThen(blockBuilder, metaData, this.bodyParser, this.comparisonBuilder),
|
new GenericTextBodyThen(blockBuilder, metaData, this.bodyParser, this.comparisonBuilder),
|
||||||
new GenericJsonBodyThen(blockBuilder, metaData, this.bodyParser, this.comparisonBuilder),
|
new GenericJsonBodyThen(blockBuilder, metaData, this.bodyParser, this.comparisonBuilder),
|
||||||
new GenericXmlBodyThen(blockBuilder, this.bodyParser)));
|
new GenericXmlBodyThen(blockBuilder, this.bodyParser)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ class JUnit4IgnoreImports implements Imports {
|
|||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.configProperties.getTestFramework() == TestFramework.JUNIT
|
return this.generatedClassMetaData.configProperties.getTestFramework() == TestFramework.JUNIT
|
||||||
&& this.generatedClassMetaData.listOfFiles.stream()
|
&& this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.anyMatch(metadata -> metadata.isIgnored() || metadata.getConvertedContractWithMetadata()
|
.anyMatch(metadata -> metadata.isIgnored() || metadata.getConvertedContractWithMetadata()
|
||||||
.stream().anyMatch(m -> m.isIgnored() || m.isInProgress()));
|
.stream()
|
||||||
|
.anyMatch(m -> m.isIgnored() || m.isInProgress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ class JUnit5IgnoreImports implements Imports {
|
|||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.configProperties.getTestFramework() == TestFramework.JUNIT5
|
return this.generatedClassMetaData.configProperties.getTestFramework() == TestFramework.JUNIT5
|
||||||
&& this.generatedClassMetaData.listOfFiles.stream()
|
&& this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.anyMatch(metadata -> metadata.isIgnored() || metadata.getConvertedContractWithMetadata()
|
.anyMatch(metadata -> metadata.isIgnored() || metadata.getConvertedContractWithMetadata()
|
||||||
.stream().anyMatch(m -> m.isIgnored() || m.isInProgress()));
|
.stream()
|
||||||
|
.anyMatch(m -> m.isIgnored() || m.isInProgress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class JavaMultipartGiven implements Given, RestAssuredAcceptor {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
||||||
getMultipartParameters(metadata).entrySet()
|
getMultipartParameters(metadata).entrySet()
|
||||||
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,11 @@ class JaxRsRequestCookiesWhen implements When {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void appendCookies(Request request) {
|
private void appendCookies(Request request) {
|
||||||
Iterator<Cookie> iterator = request.getCookies().getEntries().stream()
|
Iterator<Cookie> iterator = request.getCookies()
|
||||||
.filter(cookie -> !cookieOfAbsentType(cookie)).iterator();
|
.getEntries()
|
||||||
|
.stream()
|
||||||
|
.filter(cookie -> !cookieOfAbsentType(cookie))
|
||||||
|
.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Cookie cookie = iterator.next();
|
Cookie cookie = iterator.next();
|
||||||
String value = ".cookie(" + this.bodyParser.quotedShortText(cookie.getKey()) + ", "
|
String value = ".cookie(" + this.bodyParser.quotedShortText(cookie.getKey()) + ", "
|
||||||
|
|||||||
@@ -44,8 +44,11 @@ class JaxRsRequestHeadersWhen implements When {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void appendHeaders(Request request) {
|
private void appendHeaders(Request request) {
|
||||||
Iterator<Header> iterator = request.getHeaders().getEntries().stream().filter(header -> !headerToIgnore(header))
|
Iterator<Header> iterator = request.getHeaders()
|
||||||
.iterator();
|
.getEntries()
|
||||||
|
.stream()
|
||||||
|
.filter(header -> !headerToIgnore(header))
|
||||||
|
.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Header header = iterator.next();
|
Header header = iterator.next();
|
||||||
String text = ".header(\"" + header.getName() + "\", " + headerValue(header) + ")";
|
String text = ".header(\"" + header.getName() + "\", " + headerValue(header) + ")";
|
||||||
|
|||||||
@@ -53,8 +53,12 @@ class JaxRsRequestWhen implements When, JaxRsAcceptor, QueryParamsResolver {
|
|||||||
if (request.getHeaders() == null || request.getHeaders().getEntries() == null) {
|
if (request.getHeaders() == null || request.getHeaders().getEntries() == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
Header foundHeader = request.getHeaders().getEntries().stream().filter(header -> name.equals(header.getName()))
|
Header foundHeader = request.getHeaders()
|
||||||
.findFirst().orElse(null);
|
.getEntries()
|
||||||
|
.stream()
|
||||||
|
.filter(header -> name.equals(header.getName()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
if (foundHeader == null) {
|
if (foundHeader == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ class JaxRsStatusCodeThen implements Then {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
||||||
Response response = metadata.getContract().getResponse();
|
Response response = metadata.getContract().getResponse();
|
||||||
this.blockBuilder.addIndented(
|
this.blockBuilder
|
||||||
this.comparisonBuilder.assertThat("response.getStatus()", response.getStatus().getServerValue()))
|
.addIndented(
|
||||||
.addEndingIfNotPresent();
|
this.comparisonBuilder.assertThat("response.getStatus()", response.getStatus().getServerValue()))
|
||||||
|
.addEndingIfNotPresent();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,10 @@ class JaxRsUrlPathWhen implements When, JaxRsAcceptor, QueryParamsResolver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.blockBuilder.addEmptyLine();
|
this.blockBuilder.addEmptyLine();
|
||||||
Iterator<QueryParameter> iterator = queryParameters.getParameters().stream().filter(this::allowedQueryParameter)
|
Iterator<QueryParameter> iterator = queryParameters.getParameters()
|
||||||
.iterator();
|
.stream()
|
||||||
|
.filter(this::allowedQueryParameter)
|
||||||
|
.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
QueryParameter param = iterator.next();
|
QueryParameter param = iterator.next();
|
||||||
String queryParamValue = getQueryParamValue(param);
|
String queryParamValue = getQueryParamValue(param);
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ class JaxRsWhen implements When, BodyMethodVisitor, JaxRsAcceptor {
|
|||||||
this.generatedClassMetaData = generatedClassMetaData;
|
this.generatedClassMetaData = generatedClassMetaData;
|
||||||
this.bodyParser = bodyParser;
|
this.bodyParser = bodyParser;
|
||||||
this.whens
|
this.whens
|
||||||
.addAll(Arrays.asList(new JaxRsUrlPathWhen(this.blockBuilder, this.generatedClassMetaData, bodyParser),
|
.addAll(Arrays.asList(new JaxRsUrlPathWhen(this.blockBuilder, this.generatedClassMetaData, bodyParser),
|
||||||
new JaxRsRequestWhen(this.blockBuilder, this.generatedClassMetaData),
|
new JaxRsRequestWhen(this.blockBuilder, this.generatedClassMetaData),
|
||||||
new JaxRsRequestHeadersWhen(this.blockBuilder, bodyParser),
|
new JaxRsRequestHeadersWhen(this.blockBuilder, bodyParser),
|
||||||
new JaxRsRequestCookiesWhen(this.blockBuilder, bodyParser),
|
new JaxRsRequestCookiesWhen(this.blockBuilder, bodyParser),
|
||||||
new JaxRsRequestMethodWhen(this.blockBuilder, this.generatedClassMetaData),
|
new JaxRsRequestMethodWhen(this.blockBuilder, this.generatedClassMetaData),
|
||||||
new JaxRsRequestInvokerWhen(this.blockBuilder)));
|
new JaxRsRequestInvokerWhen(this.blockBuilder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class JsonBodyVerificationBuilder implements BodyMethodGeneration, ClassVerifier
|
|||||||
convertedResponseBody = MapConverter.transformValues(convertedResponseBody,
|
convertedResponseBody = MapConverter.transformValues(convertedResponseBody,
|
||||||
returnReferencedEntries(templateModel), parsingFunction);
|
returnReferencedEntries(templateModel), parsingFunction);
|
||||||
JsonPaths jsonPaths = new JsonToJsonPathsConverter(assertJsonSize)
|
JsonPaths jsonPaths = new JsonToJsonPathsConverter(assertJsonSize)
|
||||||
.transformToJsonPathWithTestsSideValues(convertedResponseBody, parsingFunction, includeEmptyCheck);
|
.transformToJsonPathWithTestsSideValues(convertedResponseBody, parsingFunction, includeEmptyCheck);
|
||||||
|
|
||||||
DocumentContext finalParsedRequestBody = parsedRequestBody;
|
DocumentContext finalParsedRequestBody = parsedRequestBody;
|
||||||
jsonPaths.forEach(it -> {
|
jsonPaths.forEach(it -> {
|
||||||
@@ -214,12 +214,10 @@ class JsonBodyVerificationBuilder implements BodyMethodGeneration, ClassVerifier
|
|||||||
Object object = parsedRequestBody.read(jsonPathEntry);
|
Object object = parsedRequestBody.read(jsonPathEntry);
|
||||||
if (!(object instanceof String)) {
|
if (!(object instanceof String)) {
|
||||||
return method
|
return method
|
||||||
.replace('"' + contractTemplate.escapedOpeningTemplate(),
|
.replace('"' + contractTemplate.escapedOpeningTemplate(), contractTemplate.escapedOpeningTemplate())
|
||||||
contractTemplate.escapedOpeningTemplate())
|
.replace(contractTemplate.escapedClosingTemplate() + '"', contractTemplate.escapedClosingTemplate())
|
||||||
.replace(contractTemplate.escapedClosingTemplate() + '"',
|
.replace('"' + contractTemplate.openingTemplate(), contractTemplate.openingTemplate())
|
||||||
contractTemplate.escapedClosingTemplate())
|
.replace(contractTemplate.closingTemplate() + '"', contractTemplate.closingTemplate());
|
||||||
.replace('"' + contractTemplate.openingTemplate(), contractTemplate.openingTemplate())
|
|
||||||
.replace(contractTemplate.closingTemplate() + '"', contractTemplate.closingTemplate());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return method;
|
return method;
|
||||||
|
|||||||
@@ -41,8 +41,10 @@ class JsonPathImports implements Imports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.listOfFiles.stream().anyMatch(metadata -> metadata
|
return this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.getConvertedContractWithMetadata().stream().anyMatch(SingleContractMetadata::isJson));
|
.anyMatch(metadata -> metadata.getConvertedContractWithMetadata()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(SingleContractMetadata::isJson));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class MessagingAssertThatThen implements Then {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
||||||
this.blockBuilder
|
this.blockBuilder
|
||||||
.addLineWithEnding(metadata.getContract().getOutputMessage().getAssertThat().getExecutionCommand());
|
.addLineWithEnding(metadata.getContract().getOutputMessage().getAssertThat().getExecutionCommand());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,9 @@ class MessagingBodyThen implements Then, BodyMethodVisitor {
|
|||||||
public MethodVisitor<Then> apply(SingleContractMetadata singleContractMetadata) {
|
public MethodVisitor<Then> apply(SingleContractMetadata singleContractMetadata) {
|
||||||
endBodyBlock(this.blockBuilder);
|
endBodyBlock(this.blockBuilder);
|
||||||
startBodyBlock(this.blockBuilder, "and:");
|
startBodyBlock(this.blockBuilder, "and:");
|
||||||
this.thens.stream().filter(then -> then.accept(singleContractMetadata))
|
this.thens.stream()
|
||||||
.forEach(then -> then.apply(singleContractMetadata));
|
.filter(then -> then.accept(singleContractMetadata))
|
||||||
|
.forEach(then -> then.apply(singleContractMetadata));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,10 @@ class MessagingFields implements Field {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.listOfFiles.stream().anyMatch(metadata -> metadata
|
return this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.getConvertedContractWithMetadata().stream().anyMatch(SingleContractMetadata::isMessaging));
|
.anyMatch(metadata -> metadata.getConvertedContractWithMetadata()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(SingleContractMetadata::isMessaging));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ class MessagingHeadersThen implements Then, BodyMethodVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void appendLineWithHeaderNotNull(String property) {
|
private void appendLineWithHeaderNotNull(String property) {
|
||||||
this.blockBuilder.addLineWithEnding(
|
this.blockBuilder
|
||||||
this.comparisonBuilder.assertThatIsNotNull("response.getHeader(\"" + property + "\")"));
|
.addLineWithEnding(this.comparisonBuilder.assertThatIsNotNull("response.getHeader(\"" + property + "\")"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processHeaderElement(String property, Object value) {
|
private void processHeaderElement(String property, Object value) {
|
||||||
@@ -79,8 +79,8 @@ class MessagingHeadersThen implements Then, BodyMethodVisitor {
|
|||||||
|
|
||||||
private void processHeaderElement(String property, Number value) {
|
private void processHeaderElement(String property, Number value) {
|
||||||
appendLineWithHeaderNotNull(property);
|
appendLineWithHeaderNotNull(property);
|
||||||
blockBuilder.addLineWithEnding(
|
blockBuilder
|
||||||
this.comparisonBuilder.assertThat("response.getHeader(\"" + property + "\")", value));
|
.addLineWithEnding(this.comparisonBuilder.assertThat("response.getHeader(\"" + property + "\")", value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processHeaderElement(String property, Pattern pattern) {
|
private void processHeaderElement(String property, Pattern pattern) {
|
||||||
|
|||||||
@@ -44,8 +44,10 @@ class MessagingImports implements Imports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.listOfFiles.stream().anyMatch(metadata -> metadata
|
return this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.getConvertedContractWithMetadata().stream().anyMatch(SingleContractMetadata::isMessaging));
|
.anyMatch(metadata -> metadata.getConvertedContractWithMetadata()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(SingleContractMetadata::isMessaging));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,11 +43,14 @@ class MessagingReceiveMessageThen implements Then, BodyMethodVisitor {
|
|||||||
OutputMessage outputMessage = singleContractMetadata.getContract().getOutputMessage();
|
OutputMessage outputMessage = singleContractMetadata.getContract().getOutputMessage();
|
||||||
this.bodyReader.storeContractAsYaml(singleContractMetadata);
|
this.bodyReader.storeContractAsYaml(singleContractMetadata);
|
||||||
this.blockBuilder
|
this.blockBuilder
|
||||||
.addIndented("ContractVerifierMessage response = contractVerifierMessaging.receive("
|
.addIndented("ContractVerifierMessage response = contractVerifierMessaging.receive("
|
||||||
+ sentToValue(outputMessage.getSentTo().getServerValue()) + ",")
|
+ sentToValue(outputMessage.getSentTo().getServerValue()) + ",")
|
||||||
.addEmptyLine().indent()
|
.addEmptyLine()
|
||||||
.addIndented("contract(this, \"" + singleContractMetadata.methodName() + ".yml\"))").unindent()
|
.indent()
|
||||||
.addEndingIfNotPresent().addEmptyLine();
|
.addIndented("contract(this, \"" + singleContractMetadata.methodName() + ".yml\"))")
|
||||||
|
.unindent()
|
||||||
|
.addEndingIfNotPresent()
|
||||||
|
.addEmptyLine();
|
||||||
this.blockBuilder.addLineWithEnding(this.comparisonBuilder.assertThatIsNotNull("response"));
|
this.blockBuilder.addLineWithEnding(this.comparisonBuilder.assertThatIsNotNull("response"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ class MessagingStaticImports implements Imports {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.listOfFiles.stream().anyMatch(metadata -> metadata
|
return this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.getConvertedContractWithMetadata().stream().anyMatch(SingleContractMetadata::isMessaging));
|
.anyMatch(metadata -> metadata.getConvertedContractWithMetadata()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(SingleContractMetadata::isMessaging));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class MessagingTriggeredByWhen implements When {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<When> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<When> apply(SingleContractMetadata metadata) {
|
||||||
this.blockBuilder.addIndented(metadata.getContract().getInput().getTriggeredBy().getExecutionCommand())
|
this.blockBuilder.addIndented(metadata.getContract().getInput().getTriggeredBy().getExecutionCommand())
|
||||||
.addEndingIfNotPresent();
|
.addEndingIfNotPresent();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class MockMvcHeadersGiven implements Given {
|
|||||||
private String string(Header header) {
|
private String string(Header header) {
|
||||||
return ".header("
|
return ".header("
|
||||||
+ ContentHelper.getTestSideForNonBodyValue(header.getName()) + ", " + ContentHelper
|
+ ContentHelper.getTestSideForNonBodyValue(header.getName()) + ", " + ContentHelper
|
||||||
.getTestSideForNonBodyValue(MapConverter.getTestSideValuesForNonBody(header.getServerValue()))
|
.getTestSideForNonBodyValue(MapConverter.getTestSideValuesForNonBody(header.getServerValue()))
|
||||||
+ ")";
|
+ ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,8 +60,11 @@ class MockMvcQueryParamsWhen implements When, MockMvcAcceptor, QueryParamsResolv
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addQueryParameters(Url buildUrl) {
|
private void addQueryParameters(Url buildUrl) {
|
||||||
List<QueryParameter> queryParameters = buildUrl.getQueryParameters().getParameters().stream()
|
List<QueryParameter> queryParameters = buildUrl.getQueryParameters()
|
||||||
.filter(this::allowedQueryParameter).collect(Collectors.toList());
|
.getParameters()
|
||||||
|
.stream()
|
||||||
|
.filter(this::allowedQueryParameter)
|
||||||
|
.collect(Collectors.toList());
|
||||||
Iterator<QueryParameter> iterator = queryParameters.iterator();
|
Iterator<QueryParameter> iterator = queryParameters.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
QueryParameter parameter = iterator.next();
|
QueryParameter parameter = iterator.next();
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ class RestAssuredGiven implements Given, BodyMethodVisitor, RestAssuredAcceptor
|
|||||||
new ExplicitRequestGiven(blockBuilder, generatedClassMetaData),
|
new ExplicitRequestGiven(blockBuilder, generatedClassMetaData),
|
||||||
new WebTestClientRequestGiven(blockBuilder, generatedClassMetaData)));
|
new WebTestClientRequestGiven(blockBuilder, generatedClassMetaData)));
|
||||||
this.bodyGivens
|
this.bodyGivens
|
||||||
.addAll(Arrays.asList(new MockMvcHeadersGiven(blockBuilder), new MockMvcCookiesGiven(blockBuilder),
|
.addAll(Arrays.asList(new MockMvcHeadersGiven(blockBuilder), new MockMvcCookiesGiven(blockBuilder),
|
||||||
new MockMvcBodyGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
new MockMvcBodyGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
||||||
new JavaMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
new JavaMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
||||||
new SpockMockMvcMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
new SpockMockMvcMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
||||||
new SpockExplicitMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
new SpockExplicitMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser),
|
||||||
new SpockWebTestClientMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser)));
|
new SpockWebTestClientMultipartGiven(blockBuilder, generatedClassMetaData, bodyParser)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,9 +58,12 @@ class RestAssuredGiven implements Given, BodyMethodVisitor, RestAssuredAcceptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addRequestGivenLine(SingleContractMetadata singleContractMetadata) {
|
private void addRequestGivenLine(SingleContractMetadata singleContractMetadata) {
|
||||||
this.requestGivens.stream().filter(given -> given.accept(singleContractMetadata)).findFirst().orElseThrow(
|
this.requestGivens.stream()
|
||||||
() -> new IllegalStateException("No matching request building Given implementation for Rest Assured"))
|
.filter(given -> given.accept(singleContractMetadata))
|
||||||
.apply(singleContractMetadata);
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
|
"No matching request building Given implementation for Rest Assured"))
|
||||||
|
.apply(singleContractMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ class RestAssuredStatusCodeThen implements Then {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
|
||||||
Response response = metadata.getContract().getResponse();
|
Response response = metadata.getContract().getResponse();
|
||||||
this.blockBuilder.addIndented(
|
this.blockBuilder
|
||||||
this.comparisonBuilder.assertThat("response.statusCode()", response.getStatus().getServerValue()))
|
.addIndented(
|
||||||
.addEndingIfNotPresent();
|
this.comparisonBuilder.assertThat("response.statusCode()", response.getStatus().getServerValue()))
|
||||||
|
.addEndingIfNotPresent();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,12 @@ class RestAssuredWhen implements When, BodyMethodVisitor, RestAssuredAcceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addResponseWhenLine(SingleContractMetadata singleContractMetadata) {
|
private void addResponseWhenLine(SingleContractMetadata singleContractMetadata) {
|
||||||
this.responseWhens.stream().filter(when -> when.accept(singleContractMetadata)).findFirst().orElseThrow(
|
this.responseWhens.stream()
|
||||||
() -> new IllegalStateException("No matching request building When implementation for Rest Assured"))
|
.filter(when -> when.accept(singleContractMetadata))
|
||||||
.apply(singleContractMetadata);
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
|
"No matching request building When implementation for Rest Assured"))
|
||||||
|
.apply(singleContractMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -90,29 +90,29 @@ class SingleMethodBuilder {
|
|||||||
|
|
||||||
SingleMethodBuilder restAssured() {
|
SingleMethodBuilder restAssured() {
|
||||||
return given(new JavaRestAssuredGiven(this.blockBuilder, this.generatedClassMetaData))
|
return given(new JavaRestAssuredGiven(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.given(new SpockRestAssuredGiven(this.blockBuilder, this.generatedClassMetaData))
|
.given(new SpockRestAssuredGiven(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.when(new JavaRestAssuredWhen(this.blockBuilder, this.generatedClassMetaData))
|
.when(new JavaRestAssuredWhen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.when(new SpockRestAssuredWhen(this.blockBuilder, this.generatedClassMetaData))
|
.when(new SpockRestAssuredWhen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.then(new JavaRestAssuredThen(this.blockBuilder, this.generatedClassMetaData))
|
.then(new JavaRestAssuredThen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.then(new SpockRestAssuredThen(this.blockBuilder, this.generatedClassMetaData))
|
.then(new SpockRestAssuredThen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.methodPostProcessor(new TemplateUpdatingMethodPostProcessor(this.blockBuilder));
|
.methodPostProcessor(new TemplateUpdatingMethodPostProcessor(this.blockBuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleMethodBuilder customMode() {
|
SingleMethodBuilder customMode() {
|
||||||
return given(new CustomModeGiven(this.blockBuilder, this.generatedClassMetaData, CustomModeBodyParser.INSTANCE))
|
return given(new CustomModeGiven(this.blockBuilder, this.generatedClassMetaData, CustomModeBodyParser.INSTANCE))
|
||||||
.when(new CustomModeWhen(this.blockBuilder, this.generatedClassMetaData))
|
.when(new CustomModeWhen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.then(new CustomModeThen(this.blockBuilder, this.generatedClassMetaData, CustomModeBodyParser.INSTANCE,
|
.then(new CustomModeThen(this.blockBuilder, this.generatedClassMetaData, CustomModeBodyParser.INSTANCE,
|
||||||
ComparisonBuilder.JAVA_HTTP_INSTANCE))
|
ComparisonBuilder.JAVA_HTTP_INSTANCE))
|
||||||
.methodPostProcessor(new TemplateUpdatingMethodPostProcessor(this.blockBuilder));
|
.methodPostProcessor(new TemplateUpdatingMethodPostProcessor(this.blockBuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleMethodBuilder jaxRs() {
|
SingleMethodBuilder jaxRs() {
|
||||||
return given(new JaxRsGiven(this.generatedClassMetaData))
|
return given(new JaxRsGiven(this.generatedClassMetaData))
|
||||||
.when(new JavaJaxRsWhen(this.blockBuilder, this.generatedClassMetaData))
|
.when(new JavaJaxRsWhen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.when(new SpockJaxRsWhen(this.blockBuilder, this.generatedClassMetaData))
|
.when(new SpockJaxRsWhen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.then(new JavaJaxRsThen(this.blockBuilder, this.generatedClassMetaData))
|
.then(new JavaJaxRsThen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.then(new SpockJaxRsThen(this.blockBuilder, this.generatedClassMetaData))
|
.then(new SpockJaxRsThen(this.blockBuilder, this.generatedClassMetaData))
|
||||||
.methodPostProcessor(new TemplateUpdatingMethodPostProcessor(this.blockBuilder));
|
.methodPostProcessor(new TemplateUpdatingMethodPostProcessor(this.blockBuilder));
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleMethodBuilder messaging() {
|
SingleMethodBuilder messaging() {
|
||||||
@@ -205,14 +205,17 @@ class SingleMethodBuilder {
|
|||||||
|
|
||||||
private boolean shouldStopProcessing(SingleContractMetadata metaData) {
|
private boolean shouldStopProcessing(SingleContractMetadata metaData) {
|
||||||
List<MethodPreProcessor> matchingPreProcessors = this.methodPreProcessors.stream()
|
List<MethodPreProcessor> matchingPreProcessors = this.methodPreProcessors.stream()
|
||||||
.filter(m -> m.accept(metaData)).collect(Collectors.toCollection(LinkedList::new));
|
.filter(m -> m.accept(metaData))
|
||||||
|
.collect(Collectors.toCollection(LinkedList::new));
|
||||||
matchingPreProcessors.forEach(m -> m.apply(metaData));
|
matchingPreProcessors.forEach(m -> m.apply(metaData));
|
||||||
return matchingPreProcessors.stream().anyMatch(m -> !m.shouldContinue());
|
return matchingPreProcessors.stream().anyMatch(m -> !m.shouldContinue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodMetadata pickMetadatum() {
|
private MethodMetadata pickMetadatum() {
|
||||||
return this.methodMetadata.stream().filter(Acceptor::accept).findFirst()
|
return this.methodMetadata.stream()
|
||||||
.orElseThrow(() -> new IllegalStateException("No matching method metadata found"));
|
.filter(Acceptor::accept)
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalStateException("No matching method metadata found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean visit(List<? extends MethodVisitor> list, SingleContractMetadata metaData) {
|
private boolean visit(List<? extends MethodVisitor> list, SingleContractMetadata metaData) {
|
||||||
@@ -220,8 +223,9 @@ class SingleMethodBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean visit(List<? extends MethodVisitor> list, SingleContractMetadata metaData, boolean addLineEnding) {
|
private boolean visit(List<? extends MethodVisitor> list, SingleContractMetadata metaData, boolean addLineEnding) {
|
||||||
List<? extends MethodVisitor> visitors = list.stream().filter(o -> o.accept(metaData))
|
List<? extends MethodVisitor> visitors = list.stream()
|
||||||
.collect(Collectors.toList());
|
.filter(o -> o.accept(metaData))
|
||||||
|
.collect(Collectors.toList());
|
||||||
Iterator<? extends MethodVisitor> iterator = visitors.iterator();
|
Iterator<? extends MethodVisitor> iterator = visitors.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
MethodVisitor visitor = iterator.next();
|
MethodVisitor visitor = iterator.next();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class SpockExplicitMultipartGiven implements Given, ExplicitAcceptor {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
||||||
getMultipartParameters(metadata).entrySet()
|
getMultipartParameters(metadata).entrySet()
|
||||||
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ class SpockIgnoreImports implements Imports {
|
|||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
return this.generatedClassMetaData.configProperties.getTestFramework() == TestFramework.SPOCK
|
return this.generatedClassMetaData.configProperties.getTestFramework() == TestFramework.SPOCK
|
||||||
&& this.generatedClassMetaData.listOfFiles.stream()
|
&& this.generatedClassMetaData.listOfFiles.stream()
|
||||||
.anyMatch(metadata -> metadata.isIgnored() || metadata.getConvertedContractWithMetadata()
|
.anyMatch(metadata -> metadata.isIgnored() || metadata.getConvertedContractWithMetadata()
|
||||||
.stream().anyMatch(m -> m.isIgnored() || m.isInProgress()));
|
.stream()
|
||||||
|
.anyMatch(m -> m.isIgnored() || m.isInProgress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class SpockMockMvcMultipartGiven implements Given, MockMvcAcceptor {
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
||||||
getMultipartParameters(metadata).entrySet()
|
getMultipartParameters(metadata).entrySet()
|
||||||
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class SpockWebTestClientMultipartGiven implements Given, WebTestClientAcc
|
|||||||
@Override
|
@Override
|
||||||
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
|
||||||
getMultipartParameters(metadata).entrySet()
|
getMultipartParameters(metadata).entrySet()
|
||||||
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
.forEach(entry -> this.blockBuilder.addLine(getMultipartParameterLine(metadata, entry)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,19 +133,22 @@ public class TestSideRequestTemplateModel {
|
|||||||
if (!headersEntriesPresent) {
|
if (!headersEntriesPresent) {
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
return new HashMap<>(request.getHeaders().getEntries().stream()
|
return new HashMap<>(request.getHeaders()
|
||||||
.collect(Collectors.groupingBy(Header::getName,
|
.getEntries()
|
||||||
Collectors.mapping((Function<Object, String>) o -> MapConverter.getTestSideValues(o).toString(),
|
.stream()
|
||||||
Collectors.toList()))));
|
.collect(Collectors.groupingBy(Header::getName,
|
||||||
|
Collectors.mapping((Function<Object, String>) o -> MapConverter.getTestSideValues(o).toString(),
|
||||||
|
Collectors.toList()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String fullUrl(String url, Map<String, List<Object>> query, boolean queryParamsPresent) {
|
private static String fullUrl(String url, Map<String, List<Object>> query, boolean queryParamsPresent) {
|
||||||
if (queryParamsPresent) {
|
if (queryParamsPresent) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
String joinedParams = query.entrySet().stream().map(
|
String joinedParams = query.entrySet()
|
||||||
entry -> entry.getValue().stream().map(s -> entry.getKey() + "=" + s).collect(Collectors.joining("&")))
|
.stream()
|
||||||
.collect(Collectors.joining("&"));
|
.map(entry -> entry.getValue().stream().map(s -> entry.getKey() + "=" + s).collect(Collectors.joining("&")))
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
return url + "?" + joinedParams;
|
return url + "?" + joinedParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +156,10 @@ public class TestSideRequestTemplateModel {
|
|||||||
if (queryParameters == null) {
|
if (queryParameters == null) {
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
return new HashMap<>(queryParameters.getParameters().stream().collect(Collectors.groupingBy(
|
return new HashMap<>(queryParameters.getParameters()
|
||||||
QueryParameter::getName, Collectors.mapping(MapConverter::getTestSideValues, Collectors.toList()))));
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(QueryParameter::getName,
|
||||||
|
Collectors.mapping(MapConverter::getTestSideValues, Collectors.toList()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> buildPathsFromUrl(String url) {
|
private static List<String> buildPathsFromUrl(String url) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user