Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/org/labkey/test/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.labkey.serverapi.reader.Readers;
import org.labkey.test.util.CspLogUtil;
import org.labkey.test.util.TestLogger;
import org.labkey.test.util.Version;
import org.openqa.selenium.Dimension;

import java.io.File;
Expand Down Expand Up @@ -73,6 +74,31 @@ public abstract class TestProperties
TestLogger.error("Failed to load " + propFile.getName() + " file. Running with hard-coded defaults");
ioe.printStackTrace(System.err);
}

final List<String> gradleProperties = List.of("labkeyVersion");
final File serverPropFile = new File(TestFileUtils.getLabKeyRoot(), "gradle.properties");
if (serverPropFile.exists())
{
try (Reader propReader = Readers.getReader(serverPropFile))
{
TestLogger.log("Loading properties from " + serverPropFile.getName());
Properties properties = new Properties();
properties.load(propReader);
for (String key : gradleProperties)
{
if (properties.containsKey(key))
{
System.setProperty(key, properties.getProperty(key));
}
}
}
catch (IOException ioe)
{
TestLogger.error("Failed to load " + serverPropFile.getName() + " file.");
ioe.printStackTrace(System.err);
}
}

}

private static ZoneId browserZoneId = null;
Expand All @@ -83,6 +109,19 @@ public static void load()
CspLogUtil.init();
}

/// Get the local enlistment version, stripping everything past the minor version.
/// - `"25.11.0"` -> `"25.11"`
/// - `"25.11-SNAPSHOT"` -> `"25.11"`
/// @return Enlistment Version or `null` if unable to determine
public static Version getProductVersion()
{
Version version = new Version(System.getProperty("labkeyVersion", "1"));
if (version.size() >= 2)
return version.trim(2);
else
return null;
}

public static boolean isTestCleanupSkipped()
{
return !getBooleanProperty("clean", false);
Expand Down
4 changes: 2 additions & 2 deletions src/org/labkey/test/tests/upgrade/BaseUpgradeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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(null);
.map(Version::new).orElse(TestProperties.getProductVersion());

@Override
protected boolean skipCleanup(boolean afterTest)
Expand Down Expand Up @@ -114,7 +114,7 @@ private static class UpgradeVersionCheck implements TestRule
@Override
public void evaluate() throws Throwable
{
Assume.assumeTrue("Test doesn't support upgrading from version: " + previousVersion,
Assume.assumeTrue("Test not valid when upgrading from version: " + previousVersion,
VersionRange.versionRange(earliestVersion, latestVersion).contains(previousVersion)
);
base.evaluate();
Expand Down
10 changes: 3 additions & 7 deletions src/org/labkey/test/util/ArtifactCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,18 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;

import static org.labkey.test.TestProperties.isTestRunningOnTeamCity;
import static org.labkey.test.WebTestHelper.isLocalServer;

public class ArtifactCollector
{
private static final Map<String, AtomicInteger> _shotCounters = new HashMap<>();
private static final Pattern _illegalFileCharactersPattern = SystemUtils.IS_OS_WINDOWS
? Pattern.compile("[\\\\/:*?|\"<>]")
: Pattern.compile("/");
private static final Map<String, AtomicInteger> _shotCounters = new ConcurrentHashMap<>();

private final WebDriverWrapper _driver;
private final String _dumpDirName;
Expand Down Expand Up @@ -172,7 +168,7 @@ public static void dumpThreads()

private String buildBaseName(@NotNull String suffix)
{
return getAndIncrementShotCounter() + "_" + _illegalFileCharactersPattern.matcher(suffix).replaceAll("_");
return TestFileUtils.makeLegalFileName(getAndIncrementShotCounter() + "_" + suffix);
}

private int getAndIncrementShotCounter()
Expand Down
26 changes: 24 additions & 2 deletions src/org/labkey/test/util/AuditLogHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,16 @@ public DataRegionTable goToAuditEventView(String eventType)
*/
public SelectRowsResponse getAuditLogsFromLKS(String containerPath, AuditEvent auditEventName, List<String> columnNames,
@Nullable List<Filter> filters, @Nullable Integer maxRows, @Nullable ContainerFilter containerFilter) throws IOException, CommandException
{
return getAuditLogsFromLKS(containerPath, _wrapper.getCurrentProject(), auditEventName, columnNames, filters, maxRows, containerFilter);
}

public SelectRowsResponse getAuditLogsFromLKS(String containerPath, @NotNull String projectName, AuditEvent auditEventName, List<String> columnNames,
@Nullable List<Filter> filters, @Nullable Integer maxRows, @Nullable ContainerFilter containerFilter) throws IOException, CommandException
{
SelectRowsCommand cmd = new SelectRowsCommand("auditLog", auditEventName.getName());
cmd.setColumns(columnNames);
cmd.addFilter("ProjectId/Name", _wrapper.getCurrentProject(), Filter.Operator.EQUAL);
cmd.addFilter("ProjectId/Name", projectName, Filter.Operator.EQUAL);
if (filters != null)
filters.forEach(cmd::addFilter);
if (maxRows != null)
Expand All @@ -208,7 +214,7 @@ public List<Map<String, Object>> getAuditLogsForTransactionId(String containerPa
}

public List<Map<String, Object>> getAuditLogsForTransactionId(String containerPath, AuditEvent auditEventName, List<String> columnNames,
Integer transactionId, List<Filter> eventFilters, @Nullable ContainerFilter containerFilter) throws IOException, CommandException
Integer transactionId, @Nullable List<Filter> eventFilters, @Nullable ContainerFilter containerFilter) throws IOException, CommandException
{
List<Filter> transactionFilter = new ArrayList<>();
if (transactionId != null)
Expand All @@ -218,6 +224,22 @@ public List<Map<String, Object>> getAuditLogsForTransactionId(String containerPa
return getAuditLogsFromLKS(containerPath, auditEventName, columnNames, transactionFilter, null, containerFilter).getRows();
}

public List<Map<String, Object>> getAuditLogsForTransactionId(String containerPath,
AuditEvent auditEventName,
List<String> columnNames,
String projectName,
Integer transactionId,
List<Filter> eventFilters,
@Nullable ContainerFilter containerFilter) throws IOException, CommandException
{
List<Filter> transactionFilter = new ArrayList<>();
if (transactionId != null)
transactionFilter.add(new Filter("TransactionId", transactionId, Filter.Operator.EQUAL));
if (eventFilters != null && !eventFilters.isEmpty())
transactionFilter.addAll(eventFilters);
return getAuditLogsFromLKS(containerPath, projectName, auditEventName, columnNames, transactionFilter, null, containerFilter).getRows();
}

public void checkAuditEventValuesForTransactionId(String containerPath, AuditEvent auditEventName, Integer transactionId, int rowCount, Map<String, Object> expectedValues) throws IOException, CommandException
{
checkAuditEventValuesForTransactionId(containerPath, auditEventName, transactionId, null, rowCount, expectedValues);
Expand Down
29 changes: 25 additions & 4 deletions src/org/labkey/test/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,32 @@ public class Version implements Comparable<Version>
{
private final List<Integer> _version;

public Version(Integer... version)
private Version(List<Integer> version)
{
_version = validate(version);
}

public Version(Integer... version)
{
this(List.of(version));
}

public Version(String version)
{
this(Arrays.stream(version.split("\\.")).map(Integer::parseInt).toArray(Integer[]::new));
this(Arrays.stream(version
.split("-", 2)[0] // Remove snapshot suffix
.split("\\.")) // Split the version into major, minor, patch, etc. parts
.map(Integer::parseInt).toList());
}

public Version(Double version)
{
this(version.toString());
}

private static List<Integer> validate(Integer... versionParts)
private static List<Integer> validate(List<Integer> versionParts)
{
List<Integer> partList = List.of(versionParts);
List<Integer> partList = List.copyOf(versionParts);
if (partList.isEmpty())
{
throw new IllegalArgumentException("Version must have at least one part");
Expand All @@ -47,6 +55,19 @@ private static List<Integer> validate(Integer... versionParts)
return partList;
}

public Version trim(int maxParts)
{
if (maxParts == _version.size())
return this;
else
return new Version(_version.subList(0, maxParts));
}

public int size()
{
return _version.size();
}

@Override
public int compareTo(@NotNull Version o)
{
Expand Down