Skip to content

Commit ffe8155

Browse files
authored
Update AzureSpringBootVersionVerifier's log (Azure#30370)
* update AzureSpringBootVersionVerifier
1 parent 5d2eae8 commit ffe8155

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifier.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
public class AzureSpringBootVersionVerifier {
1919
private static final Logger LOGGER = LoggerFactory.getLogger(AzureSpringBootVersionVerifier.class);
2020

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

23-
static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_6 = "org.springframework.boot.autoconfigure.data.redis.ClientResourcesBuilderCustomizer";
24+
static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_6 = "org.springframework.boot.autoconfigure.data.redis"
25+
+ ".ClientResourcesBuilderCustomizer";
26+
27+
static final String SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_7 = "org.springframework.boot.autoconfigure.amqp"
28+
+ ".RabbitStreamTemplateConfigurer";
2429

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

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

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

9094
String getVersionFromManifest() {
@@ -95,14 +99,16 @@ private boolean springBootVersionMatches() {
9599
for (String acceptedVersion : acceptedVersions) {
96100
try {
97101
if (this.matchSpringBootVersionFromManifest(acceptedVersion)) {
102+
LOGGER.debug("The current Spring Boot version matches Spring Cloud Azure accepted version [{}].",
103+
acceptedVersion);
98104
return true;
99105
}
100106
} catch (FileNotFoundException e) {
101107
String versionString = stripWildCardFromVersion(acceptedVersion);
102108
String fullyQualifiedClassName = this.supportedVersions.get(versionString);
103109

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

114120
private boolean matchSpringBootVersionFromManifest(String acceptedVersion) throws FileNotFoundException {
115121
String version = this.getVersionFromManifest();
116-
LOGGER.debug("Version found in Boot manifest [{}]", version);
122+
LOGGER.debug("Currently running on Spring Boot version [{}], trying to match it with Spring Cloud Azure "
123+
+ "accepted version [{}].", version, acceptedVersion);
117124
if (!StringUtils.hasText(version)) {
118-
LOGGER.info("Cannot check Boot version from manifest");
119125
throw new FileNotFoundException("Spring Boot version not found");
120126
} else {
121127
return version.startsWith(stripWildCardFromVersion(acceptedVersion));

sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/compatibility/AzureSpringBootVersionVerifierTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33

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

6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.extension.ExtendWith;
68
import org.junit.jupiter.params.ParameterizedTest;
79
import org.junit.jupiter.params.provider.ValueSource;
10+
import org.springframework.boot.test.system.CapturedOutput;
11+
import org.springframework.boot.test.system.OutputCaptureExtension;
812

13+
import java.util.Arrays;
914
import java.util.Collections;
1015
import java.util.List;
1116

1217
import static com.azure.spring.cloud.autoconfigure.implementation.compatibility.AzureSpringBootVersionVerifier.SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_5;
1318
import static com.azure.spring.cloud.autoconfigure.implementation.compatibility.AzureSpringBootVersionVerifier.SPRINGBOOT_CONDITIONAL_CLASS_NAME_OF_2_6;
14-
import static org.junit.jupiter.api.Assertions.assertEquals;
15-
import static org.junit.jupiter.api.Assertions.assertThrows;
19+
import static org.junit.jupiter.api.Assertions.*;
1620
import static org.mockito.Mockito.mock;
1721
import static org.mockito.Mockito.when;
1822

23+
@ExtendWith({OutputCaptureExtension.class})
1924
class AzureSpringBootVersionVerifierTest {
2025

2126
@ParameterizedTest
@@ -145,4 +150,23 @@ String getVersionFromManifest() {
145150

146151
assertThrows(AzureCompatibilityNotMetException.class, versionVerifier::verify);
147152
}
153+
154+
@Test
155+
public void testVersionVerifierLog(CapturedOutput capturedOutput) {
156+
List<String> acceptedVersions = Arrays.asList("2.5.x", "2.6.x", "2.7.x");
157+
ClassNameResolverPredicate mockResolver = mock(ClassNameResolverPredicate.class);
158+
159+
AzureSpringBootVersionVerifier versionVerifier = new AzureSpringBootVersionVerifier(acceptedVersions,
160+
mockResolver) {
161+
String getVersionFromManifest() {
162+
return "2.6.2";
163+
}
164+
};
165+
versionVerifier.verify();
166+
String allOutput = capturedOutput.getAll();
167+
String log1 = "Currently running on Spring Boot version [2.6.2], trying to match it with Spring Cloud Azure accepted version [2.5.x].";
168+
String log2 = "Currently running on Spring Boot version [2.6.2], trying to match it with Spring Cloud Azure accepted version [2.6.x].";
169+
String log3 = "The current Spring Boot version matches Spring Cloud Azure accepted version [2.6.x].";
170+
assertTrue(allOutput.contains(log1) && allOutput.contains(log2) && allOutput.contains(log3));
171+
}
148172
}

0 commit comments

Comments
 (0)