diff --git a/src/org/labkey/test/TestFileUtils.java b/src/org/labkey/test/TestFileUtils.java index 2a9af3401c..807a928b10 100644 --- a/src/org/labkey/test/TestFileUtils.java +++ b/src/org/labkey/test/TestFileUtils.java @@ -38,6 +38,7 @@ import org.bouncycastle.openpgp.operator.jcajce.JcePBEDataDecryptorFactoryBuilder; import org.bouncycastle.util.io.Streams; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.openqa.selenium.NotFoundException; import java.io.BufferedInputStream; @@ -73,6 +74,10 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import static org.labkey.test.util.TestDataGenerator.CHARSET_STRING; +import static org.labkey.test.util.TestDataGenerator.randomInt; +import static org.labkey.test.util.TestDataGenerator.randomName; + /** * Static methods for finding and reading test-related files */ @@ -783,4 +788,17 @@ else if (ch == '-' && return new String(ret); } + + public static String randomFileName(@NotNull String part, @Nullable String extension) + { + return randomFileName(part, extension, null, null); + } + + public static String randomFileName(@NotNull String part, @Nullable String extension, @Nullable Integer numStartChars, @Nullable Integer numEndChars) + { + String baseName = makeLegalFileName(randomName(part, numStartChars == null ? randomInt(0, 5) : numStartChars, numEndChars == null ? randomInt(0, 5) : numEndChars, CHARSET_STRING, null).name()); + if (extension != null) + return baseName + extension; + return baseName; + } } diff --git a/src/org/labkey/test/categories/API.java b/src/org/labkey/test/categories/API.java new file mode 100644 index 0000000000..95784add58 --- /dev/null +++ b/src/org/labkey/test/categories/API.java @@ -0,0 +1,5 @@ +package org.labkey.test.categories; + +public abstract class API extends Test +{ +} diff --git a/src/org/labkey/test/util/AuditLogHelper.java b/src/org/labkey/test/util/AuditLogHelper.java index c5db9db012..a5483f2793 100644 --- a/src/org/labkey/test/util/AuditLogHelper.java +++ b/src/org/labkey/test/util/AuditLogHelper.java @@ -90,6 +90,7 @@ public enum AuditEvent { ASSAY_AUDIT_EVENT("AssayAuditEvent"), // available with SampleManagement module ASSAY_RESULT_AUDIT_EVENT("AssayResultAuditEvent"), // available with SampleManagement module + ATTACHMENT_AUDIT_EVENT("AttachmentAuditEvent"), EXPERIMENT_AUDIT_EVENT("ExperimentAuditEvent"), FILE_SYSTEM_EVENT("FileSystem"), INVENTORY_AUDIT_EVENT("InventoryAuditEvent"), diff --git a/src/org/labkey/test/util/PermissionsHelper.java b/src/org/labkey/test/util/PermissionsHelper.java index ff84ba8be0..64c4ff6b7b 100644 --- a/src/org/labkey/test/util/PermissionsHelper.java +++ b/src/org/labkey/test/util/PermissionsHelper.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import static org.junit.Assert.fail; @@ -45,6 +46,13 @@ public abstract class PermissionsHelper public static final String AUTHOR_ROLE = "Author"; public static final String SUBMITTER_ROLE = "Submitter"; + public static final Set AUDIT_LOG_VIEWER_ROLES = Set.of(SITE_ADMIN_ROLE, APP_ADMIN_ROLE, PROJECT_ADMIN_ROLE, FOLDER_ADMIN_ROLE); + + public static boolean canSeeAuditLogs(String roleName) + { + return AUDIT_LOG_VIEWER_ROLES.contains(roleName); + } + public static String toRole(final String name) { if (name.contains(".")) diff --git a/src/org/labkey/test/util/TestDataGenerator.java b/src/org/labkey/test/util/TestDataGenerator.java index 06dbb13728..bdb3d5220c 100644 --- a/src/org/labkey/test/util/TestDataGenerator.java +++ b/src/org/labkey/test/util/TestDataGenerator.java @@ -33,6 +33,7 @@ import org.labkey.remoteapi.domain.DomainResponse; import org.labkey.remoteapi.domain.PropertyDescriptor; import org.labkey.remoteapi.query.Filter; +import org.labkey.remoteapi.query.ImportDataResponse; import org.labkey.remoteapi.query.RowsResponse; import org.labkey.remoteapi.query.SelectRowsResponse; import org.labkey.remoteapi.query.Sort; @@ -81,7 +82,6 @@ public class TestDataGenerator public static final char REPEAT_PLACEHOLDER = '\u22EF'; // '⋯' - Used to indicate that the char will be repeated public static final char ALL_CHARS_PLACEHOLDER = '\u2211'; // '∑' - Used to indicate that all characters from the charset should be used public static final String NON_LATIN_STRING = "\u0438\u0418\uC548\u306F"; // "иИ안は" - // chose a Character random from this String public static final String CHARSET_STRING = "ABCDEFG01234abcdefvxyz~!@#$%^&*()-+=_{}[]|\\:;\"',.<>" + NON_LATIN_STRING + WIDE_PLACEHOLDER; public static final String ALPHANUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvxyz"; public static final String DOMAIN_SPECIAL_STRING = "+- _.:&()/"; @@ -936,6 +936,26 @@ public RowsResponse insertRows(Connection cn, List> rows) th return getQueryHelper(cn).insertRows(rows); } + public ImportDataResponse importRows() throws IOException, CommandException + { + return importRows(false); + } + + public ImportDataResponse importRows(boolean lookupByAlternateKey) throws IOException, CommandException + { + return importRows(WebTestHelper.getRemoteApiConnection(), lookupByAlternateKey); + } + + public ImportDataResponse importRows(Connection cn, boolean lookupByAlternateKey) throws IOException, CommandException + { + return importRows(cn, getRows(), lookupByAlternateKey); + } + + public ImportDataResponse importRows(Connection cn, List> rows, boolean lookupByAlternateKey) throws IOException, CommandException + { + return getQueryHelper(cn).importData(TestDataUtils.stringFromRows(TestDataUtils.rowListsFromMaps(rows)), lookupByAlternateKey); + } + public static List shuffleSelect(List allFields, int selectCount) { List shuffled = new ArrayList<>(allFields); diff --git a/src/org/labkey/test/util/query/QueryApiHelper.java b/src/org/labkey/test/util/query/QueryApiHelper.java index 2ad532c595..077d6d695e 100644 --- a/src/org/labkey/test/util/query/QueryApiHelper.java +++ b/src/org/labkey/test/util/query/QueryApiHelper.java @@ -128,18 +128,30 @@ public MoveRowsResponse moveRows(MoveRowsCommand moveRowsCommand) throws IOExcep } public ImportDataResponse importData(String text) throws IOException, CommandException + { + return importData(text, false); + } + + public ImportDataResponse importData(String text, boolean lookupByAlternateKey) throws IOException, CommandException { ImportDataCommand importDataCommand = new ImportDataCommand(_schema, _query); importDataCommand.setText(text); importDataCommand.setTimeout(_insertTimeout); + importDataCommand.setImportLookupByAlternateKey(lookupByAlternateKey); return importDataCommand.execute(_connection, _containerPath); } public ImportDataResponse importData(File file) throws IOException, CommandException + { + return importData(file, false); + } + + public ImportDataResponse importData(File file, boolean importByAlternateKey) throws IOException, CommandException { ImportDataCommand importDataCommand = new ImportDataCommand(_schema, _query); importDataCommand.setFile(file); importDataCommand.setTimeout(_insertTimeout); + importDataCommand.setImportLookupByAlternateKey(importByAlternateKey); return importDataCommand.execute(_connection, _containerPath); }