From 2c4df8e21945d339d9408a391f141b242d6d5209 Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Mon, 5 Jan 2026 12:42:24 -0800 Subject: [PATCH 1/2] Add convenience methods for conditionalizing upgrade checks --- src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java | 10 ++++++++++ src/org/labkey/test/util/VersionRange.java | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java b/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java index 33fe474029..c500191f4a 100644 --- a/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java +++ b/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java @@ -70,6 +70,16 @@ public List getAssociatedModules() return Arrays.asList(); } + protected boolean isUpgradingFromBefore(String version) + { + return !isUpgradingFrom(version, null); + } + + protected boolean isUpgradingFrom(String earliestVersion, String latestVersion) + { + return previousVersion != null && VersionRange.versionRange(earliestVersion, latestVersion).contains(previousVersion); + } + /** * Annotates test methods that should only run when upgrading from particular LabKey versions, as specified in * {@code webtest.upgradePreviousVersion}.
diff --git a/src/org/labkey/test/util/VersionRange.java b/src/org/labkey/test/util/VersionRange.java index 0fe8220e5a..d185ad14b8 100644 --- a/src/org/labkey/test/util/VersionRange.java +++ b/src/org/labkey/test/util/VersionRange.java @@ -9,6 +9,12 @@ public VersionRange(Version eariestVersion, Version latestVersion) { this.eariestVersion = eariestVersion; this.latestVersion = latestVersion; + + if (eariestVersion == null && latestVersion == null) + throw new IllegalArgumentException("Version range requires at least one version"); + if (eariestVersion != null && latestVersion != null && eariestVersion.compareTo(latestVersion) > 0) + throw new IllegalArgumentException("%s is after %s".formatted(eariestVersion, latestVersion)); + } public static VersionRange from(String version) From d57cdb2c2c8c35fca0d03fdd4e9536f643d0964a Mon Sep 17 00:00:00 2001 From: labkey-tchad Date: Tue, 6 Jan 2026 10:43:42 -0800 Subject: [PATCH 2/2] Add javadoc --- .../test/tests/upgrade/BaseUpgradeTest.java | 32 ++++++++---- src/org/labkey/test/util/VersionRange.java | 50 ++++++++++++++++--- 2 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java b/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java index c500191f4a..a7e3b20568 100644 --- a/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java +++ b/src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java @@ -35,8 +35,9 @@ public abstract class BaseUpgradeTest extends BaseWebDriverTest { protected static final boolean isUpgradeSetupPhase = TestProperties.getBooleanProperty("webtest.upgradeSetup", true); - protected static final Version previousVersion = Optional.ofNullable(trimToNull(System.getProperty("webtest.upgradePreviousVersion"))) - .map(Version::new).orElse(TestProperties.getProductVersion()); + protected static final Version setupVersion = isUpgradeSetupPhase ? TestProperties.getProductVersion() : + Optional.ofNullable(trimToNull(System.getProperty("webtest.upgradePreviousVersion"))).map(Version::new) + .orElse(TestProperties.getProductVersion()); @Override protected boolean skipCleanup(boolean afterTest) @@ -70,14 +71,27 @@ public List getAssociatedModules() return Arrays.asList(); } - protected boolean isUpgradingFromBefore(String version) + /** + * Checks if the setup for the current test was performed in a version prior to the specified version. + * + * @param version The version to check against. + * @return {@code true} if the setup version is earlier than the specified version. + */ + protected boolean wasSetupBefore(String version) { - return !isUpgradingFrom(version, null); + return !wasSetupWithin(version, null); } - protected boolean isUpgradingFrom(String earliestVersion, String latestVersion) + /** + * Checks if the setup for the current test was performed within the specified version range (inclusive). + * + * @param earliestVersion The earliest version in the range (inclusive). + * @param latestVersion The latest version in the range (inclusive). + * @return {@code true} if the setup version is within the specified range. + */ + protected boolean wasSetupWithin(String earliestVersion, String latestVersion) { - return previousVersion != null && VersionRange.versionRange(earliestVersion, latestVersion).contains(previousVersion); + return VersionRange.versionRange(earliestVersion, latestVersion).contains(setupVersion); } /** @@ -114,7 +128,7 @@ private static class UpgradeVersionCheck implements TestRule String latestVersion = Optional.ofNullable(description.getAnnotation(LatestVersion.class)) .map(LatestVersion::value).orElse(null); - if (isUpgradeSetupPhase || previousVersion == null || (earliestVersion == null && latestVersion == null)) + if (isUpgradeSetupPhase || setupVersion == null || (earliestVersion == null && latestVersion == null)) { return base; // Run the test normally } @@ -124,8 +138,8 @@ private static class UpgradeVersionCheck implements TestRule @Override public void evaluate() throws Throwable { - Assume.assumeTrue("Test not valid when upgrading from version: " + previousVersion, - VersionRange.versionRange(earliestVersion, latestVersion).contains(previousVersion) + Assume.assumeTrue("Test not valid when upgrading from version: " + setupVersion, + VersionRange.versionRange(earliestVersion, latestVersion).contains(setupVersion) ); base.evaluate(); } diff --git a/src/org/labkey/test/util/VersionRange.java b/src/org/labkey/test/util/VersionRange.java index d185ad14b8..865974783e 100644 --- a/src/org/labkey/test/util/VersionRange.java +++ b/src/org/labkey/test/util/VersionRange.java @@ -1,32 +1,62 @@ package org.labkey.test.util; +/** + * Represents a range of LabKey versions. + * Used for checking if a specific version falls within an inclusive range. + */ public class VersionRange { - private final Version eariestVersion; + private final Version earliestVersion; private final Version latestVersion; - public VersionRange(Version eariestVersion, Version latestVersion) + /** + * Constructs a version range. + * + * @param earliestVersion The earliest version in the range (inclusive). If null, there is no lower bound. + * @param latestVersion The latest version in the range (inclusive). If null, there is no upper bound. + * @throws IllegalArgumentException if both versions are null, or if earliestVersion is after latestVersion. + */ + public VersionRange(Version earliestVersion, Version latestVersion) { - this.eariestVersion = eariestVersion; + this.earliestVersion = earliestVersion; this.latestVersion = latestVersion; - if (eariestVersion == null && latestVersion == null) + if (earliestVersion == null && latestVersion == null) throw new IllegalArgumentException("Version range requires at least one version"); - if (eariestVersion != null && latestVersion != null && eariestVersion.compareTo(latestVersion) > 0) - throw new IllegalArgumentException("%s is after %s".formatted(eariestVersion, latestVersion)); + if (earliestVersion != null && latestVersion != null && earliestVersion.compareTo(latestVersion) > 0) + throw new IllegalArgumentException("%s is after %s".formatted(earliestVersion, latestVersion)); } + /** + * Creates a version range starting from the specified version with no upper bound. + * + * @param version The earliest version (inclusive). + * @return A new {@link VersionRange}. + */ public static VersionRange from(String version) { return new VersionRange(new Version(version), null); } + /** + * Creates a version range ending at the specified version with no lower bound. + * + * @param version The latest version (inclusive). + * @return A new {@link VersionRange}. + */ public static VersionRange until(String version) { return new VersionRange(null, new Version(version)); } + /** + * Creates a version range with specified bounds. + * + * @param earliestVersion The earliest version (inclusive). If null, there is no lower bound. + * @param latestVersion The latest version (inclusive). If null, there is no upper bound. + * @return A new {@link VersionRange}. + */ public static VersionRange versionRange(String earliestVersion, String latestVersion) { Version earliest = earliestVersion == null ? null : new Version(earliestVersion); @@ -34,9 +64,15 @@ public static VersionRange versionRange(String earliestVersion, String latestVer return new VersionRange(earliest, latest); } + /** + * Checks if the specified version is within this range (inclusive). + * + * @param version The version to check. + * @return {@code true} if the version is within the range. + */ public boolean contains(Version version) { - return (eariestVersion == null || eariestVersion.compareTo(version) <= 0) && + return (earliestVersion == null || earliestVersion.compareTo(version) <= 0) && (latestVersion == null || latestVersion.compareTo(version) >= 0); } }