From ffe81553e221b0a5601f71f1be0bd7d5d55b03da Mon Sep 17 00:00:00 2001 From: Muyao Feng <92105726+Netyyyy@users.noreply.github.com> Date: Wed, 7 Sep 2022 10:16:21 +0800 Subject: [PATCH] Update AzureSpringBootVersionVerifier's log (#30370) * update AzureSpringBootVersionVerifier --- .../AzureSpringBootVersionVerifier.java | 34 +++++++++++-------- .../AzureSpringBootVersionVerifierTest.java | 28 +++++++++++++-- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifier.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifier.java index 5e8a885532851..74560f3666182 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifier.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifier.java @@ -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 supportedVersions = new HashMap<>(); @@ -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() { @@ -95,6 +99,8 @@ 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) { @@ -102,7 +108,7 @@ private boolean springBootVersionMatches() { 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; } } @@ -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)); diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifierTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifierTest.java index a2215925cf51b..6a3c1fd5fc252 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifierTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifierTest.java @@ -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 @@ -145,4 +150,23 @@ String getVersionFromManifest() { assertThrows(AzureCompatibilityNotMetException.class, versionVerifier::verify); } + + @Test + public void testVersionVerifierLog(CapturedOutput capturedOutput) { + List 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)); + } }