Verifies current boot version is in CompatibilityVerifierProperties.

Also fixes support for wildcard 2.2.x beyond boot 2.1.x

fixes gh-715
This commit is contained in:
Spencer Gibb
2020-03-18 17:31:29 -04:00
parent d679add055
commit 7dd88a6e7f
3 changed files with 35 additions and 7 deletions

View File

@@ -87,7 +87,8 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
if (log.isDebugEnabled()) {
log.debug("Version found in Boot manifest [" + version + "]");
}
return StringUtils.hasText(version) && version.startsWith(s);
return StringUtils.hasText(version)
&& version.startsWith(stripWildCardFromVersion(s));
}
String getVersionFromManifest() {
@@ -216,7 +217,7 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
else {
// 2.0, 2.1
CompatibilityPredicate predicate = this.ACCEPTED_VERSIONS
.get(acceptedVersionWithoutX(acceptedVersion));
.get(stripWildCardFromVersion(acceptedVersion));
if (predicate != null && predicate.isCompatible()) {
if (log.isDebugEnabled()) {
log.debug("Predicate [" + predicate + "] was matched");
@@ -228,11 +229,11 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
return false;
}
private String acceptedVersionWithoutX(String acceptedVersion) {
if (acceptedVersion.endsWith(".x")) {
return acceptedVersion.substring(0, acceptedVersion.indexOf(".x"));
static String stripWildCardFromVersion(String version) {
if (version.endsWith(".x")) {
return version.substring(0, version.indexOf(".x"));
}
return acceptedVersion;
return version;
}
}

View File

@@ -20,13 +20,17 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.BDDAssertions.then;
import static org.springframework.cloud.configuration.SpringBootVersionVerifier.stripWildCardFromVersion;
/**
* @author Marcin Grzejszczak
@@ -38,11 +42,29 @@ public class CompatibilityVerifierAutoConfigurationTests {
@Autowired
MyCompatibilityVerifier myMismatchVerifier;
@Autowired
CompatibilityVerifierProperties verifierProperties;
@Test
public void contextLoads() {
then(this.myMismatchVerifier.called).isTrue();
}
@Test
public void verifierPropertiesContainsCurrentBootVersion() {
String version = SpringBootVersion.getVersion();
assertThat(version).isNotBlank();
for (String compatibleVersion : verifierProperties.getCompatibleBootVersions()) {
if (version.startsWith(stripWildCardFromVersion(compatibleVersion))) {
// success we found the current boot version in our list of compatible
// versions.
return;
}
}
fail(version + " not found in " + verifierProperties.getCompatibleBootVersions());
}
@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
static class TestConfiguration {

View File

@@ -144,7 +144,12 @@ public class SpringBootDependencyTests {
@Test
public void should_match_against_current_manifest() {
List<String> acceptedVersions = Collections.singletonList("2.3");
verifyCurrentVersionFromManifest("2.3");
verifyCurrentVersionFromManifest("2.3.x");
}
private void verifyCurrentVersionFromManifest(String version) {
List<String> acceptedVersions = Collections.singletonList(version);
SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier(
acceptedVersions);
versionVerifier.ACCEPTED_VERSIONS.clear();