Skip to content

Commit 91b01a4

Browse files
SONAR-27393 Fix tests for community
1 parent d7db541 commit 91b01a4

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/DbVersionPackageConsistencyTest.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import java.nio.file.Path;
2626
import java.nio.file.Paths;
2727
import java.util.Collection;
28+
import java.util.OptionalInt;
2829
import java.util.Properties;
2930
import java.util.stream.Stream;
31+
import org.junit.jupiter.api.Assumptions;
3032
import org.junit.jupiter.api.DynamicTest;
3133
import org.junit.jupiter.api.TestFactory;
3234

@@ -37,7 +39,9 @@ class DbVersionPackageConsistencyTest {
3739

3840
@TestFactory
3941
Collection<DynamicTest> each_version_package_should_not_exceed_current_commercial_version() throws IOException {
40-
int currentVersion = readCurrentVersion();
42+
OptionalInt currentVersion = readCurrentVersion();
43+
Assumptions.assumeTrue(currentVersion.isPresent(), "private/gradle.properties not found — skipping (open-source build)");
44+
int version = currentVersion.getAsInt();
4145

4246
Path versionDir = Paths.get("src/main/java/org/sonar/server/platform/db/migration/version");
4347
assertThat(versionDir).exists();
@@ -47,21 +51,21 @@ Collection<DynamicTest> each_version_package_should_not_exceed_current_commercia
4751
.filter(Files::isDirectory)
4852
.map(p -> p.getFileName().toString())
4953
.filter(name -> name.matches("v\\d+"))
50-
.map(name -> dynamicTest(name + " must not exceed current version " + currentVersion, () -> assertThat(Integer.parseInt(name.substring(1)))
54+
.map(name -> dynamicTest(name + " must not exceed current version " + version, () -> assertThat(Integer.parseInt(name.substring(1)))
5155
.describedAs(
5256
"Package '%s' references a version beyond the current version %d (from private/gradle.properties). "
5357
+ "Package names under 'version/' must not reference a future release.",
54-
name, currentVersion)
55-
.isLessThanOrEqualTo(currentVersion)))
58+
name, version)
59+
.isLessThanOrEqualTo(version)))
5660
.toList();
5761
}
5862
}
5963

60-
private static int readCurrentVersion() throws IOException {
64+
private static OptionalInt readCurrentVersion() throws IOException {
6165
Path gradleProperties = Paths.get("../../private/gradle.properties");
62-
assertThat(gradleProperties)
63-
.describedAs("private/gradle.properties not found — this test requires an enterprise/commercial build")
64-
.exists();
66+
if (!Files.exists(gradleProperties)) {
67+
return OptionalInt.empty();
68+
}
6569
Properties properties = new Properties();
6670
try (InputStream is = Files.newInputStream(gradleProperties)) {
6771
properties.load(is);
@@ -71,7 +75,9 @@ private static int readCurrentVersion() throws IOException {
7175
.describedAs("commercialVersion not found in private/gradle.properties")
7276
.isNotNull();
7377
String[] parts = commercialVersion.split("\\.");
74-
assertThat(parts).hasSize(2);
75-
return Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]);
78+
assertThat(parts)
79+
.describedAs("commercialVersion in private/gradle.properties must have format 'MAJOR.MINOR'")
80+
.hasSize(2);
81+
return OptionalInt.of(Integer.parseInt(parts[0]) * 100 + Integer.parseInt(parts[1]));
7682
}
7783
}

0 commit comments

Comments
 (0)