Skip to content

Commit

Permalink
Update AzureSpringBootVersionVerifier's log (Azure#30370)
Browse files Browse the repository at this point in the history
* update AzureSpringBootVersionVerifier
  • Loading branch information
Netyyyy authored Sep 7, 2022
1 parent 5d2eae8 commit ffe8155
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
public class AzureSpringBootVersionVerifier {
private static final Logger LOGGER = LoggerFactory.getLogger(AzureSpringBootVersionVerifier.class);

static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_5 = "org.springframework.boot.context.properties.bind.Bindable.BindRestriction";
static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_5 = "org.springframework.boot.context.properties.bind"
+ ".Bindable.BindRestriction";

static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_6 = "org.springframework.boot.autoconfigure.data.redis.ClientResourcesBuilderCustomizer";
static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_6 = "org.springframework.boot.autoconfigure.data.redis"
+ ".ClientResourcesBuilderCustomizer";

static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_7 = "org.springframework.boot.autoconfigure.amqp"
+ ".RabbitStreamTemplateConfigurer";

static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_7 = "org.springframework.boot.autoconfigure.amqp.RabbitStreamTemplateConfigurer";
/**
* Versions supported by Spring Cloud Azure, for present is [2.5, 2.6]. Update this value if needed.
* Versions supported by Spring Cloud Azure, for present is [2.5, 2.6, 2.7]. Update this value if needed.
*/
private final Map<String, String> supportedVersions = new HashMap<>();

Expand Down Expand Up @@ -71,20 +75,20 @@ public VerificationResult verify() {
private String errorDescription() {
String versionFromManifest = this.getVersionFromManifest();
return StringUtils.hasText(versionFromManifest) ? String.format("Spring Boot [%s] is not compatible with this"
+ " Spring Cloud Azure release", versionFromManifest) : "Spring Boot is not compatible with this "
+ "Spring Cloud Azure release";
+ " Spring Cloud Azure version.", versionFromManifest) : "Spring Boot is not compatible with this "
+ "Spring Cloud Azure version.";
}

private String action() {
return String.format("Change Spring Boot version to one of the following versions %s.%n"
+ "You can find the latest Spring Boot versions here [%s]. %n"
+ "You can find the latest Spring Boot versions here [%s].%n"
+ "If you want to learn more about the Spring Cloud Azure compatibility, "
+ "you can visit this page [%s] and check the [Which Version of Spring Cloud Azure Should I Use] section.%n"
+ "If you want to disable this check, "
+ "just set the property [spring.cloud.azure.compatibility-verifier.enabled=false]",
+ "you can visit this page [%s] and check the [Which Version of Spring Cloud Azure Should I Use] "
+ "section.%n If you want to disable this check, "
+ "just set the property [spring.cloud.azure.compatibility-verifier.enabled=false].",
this.acceptedVersions,
"https://spring.io/projects/spring-boot#learn",
"https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Versions-Mapping");
"https://aka.ms/spring/versions");
}

String getVersionFromManifest() {
Expand All @@ -95,14 +99,16 @@ private boolean springBootVersionMatches() {
for (String acceptedVersion : acceptedVersions) {
try {
if (this.matchSpringBootVersionFromManifest(acceptedVersion)) {
LOGGER.debug("The current Spring Boot version matches Spring Cloud Azure accepted version [{}].",
acceptedVersion);
return true;
}
} catch (FileNotFoundException e) {
String versionString = stripWildCardFromVersion(acceptedVersion);
String fullyQualifiedClassName = this.supportedVersions.get(versionString);

if (classNameResolver.resolve(fullyQualifiedClassName)) {
LOGGER.debug("Predicate for Spring Boot Version of [{}] was matched", versionString);
LOGGER.debug("Predicate for Spring Boot Version of [{}] was matched.", versionString);
return true;
}
}
Expand All @@ -113,9 +119,9 @@ private boolean springBootVersionMatches() {

private boolean matchSpringBootVersionFromManifest(String acceptedVersion) throws FileNotFoundException {
String version = this.getVersionFromManifest();
LOGGER.debug("Version found in Boot manifest [{}]", version);
LOGGER.debug("Currently running on Spring Boot version [{}], trying to match it with Spring Cloud Azure "
+ "accepted version [{}].", version, acceptedVersion);
if (!StringUtils.hasText(version)) {
LOGGER.info("Cannot check Boot version from manifest");
throw new FileNotFoundException("Spring Boot version not found");
} else {
return version.startsWith(stripWildCardFromVersion(acceptedVersion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@

package com.azure.spring.cloud.autoconfigure.implementation.compatibility;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static com.azure.spring.cloud.autoconfigure.implementation.compatibility.AzureSpringBootVersionVerifier.SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_5;
import static com.azure.spring.cloud.autoconfigure.implementation.compatibility.AzureSpringBootVersionVerifier.SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_6;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith({OutputCaptureExtension.class})
class AzureSpringBootVersionVerifierTest {

@ParameterizedTest
Expand Down Expand Up @@ -145,4 +150,23 @@ String getVersionFromManifest() {

assertThrows(AzureCompatibilityNotMetException.class, versionVerifier::verify);
}

@Test
public void testVersionVerifierLog(CapturedOutput capturedOutput) {
List<String> acceptedVersions = Arrays.asList("2.5.x", "2.6.x", "2.7.x");
ClassNameResolverPredicate mockResolver = mock(ClassNameResolverPredicate.class);

AzureSpringBootVersionVerifier versionVerifier = new AzureSpringBootVersionVerifier(acceptedVersions,
mockResolver) {
String getVersionFromManifest() {
return "2.6.2";
}
};
versionVerifier.verify();
String allOutput = capturedOutput.getAll();
String log1 = "Currently running on Spring Boot version [2.6.2], trying to match it with Spring Cloud Azure accepted version [2.5.x].";
String log2 = "Currently running on Spring Boot version [2.6.2], trying to match it with Spring Cloud Azure accepted version [2.6.x].";
String log3 = "The current Spring Boot version matches Spring Cloud Azure accepted version [2.6.x].";
assertTrue(allOutput.contains(log1) && allOutput.contains(log2) && allOutput.contains(log3));
}
}

0 comments on commit ffe8155

Please sign in to comment.