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
53 changes: 53 additions & 0 deletions src/org/labkey/test/BaseWebDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.labkey.test.teamcity.TeamCityUtils;
import org.labkey.test.util.APIAssayHelper;
import org.labkey.test.util.APIContainerHelper;
import org.labkey.test.util.APITestHelper;
import org.labkey.test.util.AbstractAssayHelper;
import org.labkey.test.util.AbstractContainerHelper;
import org.labkey.test.util.ApiPermissionsHelper;
Expand All @@ -80,6 +81,7 @@
import org.labkey.test.util.DataRegionTable;
import org.labkey.test.util.DebugUtils;
import org.labkey.test.util.DeferredErrorCollector;
import org.labkey.test.util.EscapeUtil;
import org.labkey.test.util.Ext4Helper;
import org.labkey.test.util.FileBrowserHelper;
import org.labkey.test.util.ListHelper;
Expand Down Expand Up @@ -147,6 +149,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.labkey.test.TestProperties.isHeapDumpCollectionEnabled;
Expand Down Expand Up @@ -2739,6 +2742,56 @@ public void dismissReleaseBanner(String productName, boolean dismiss)
executeScript("localStorage.removeItem('" + dismissBannerKey + "')");
}

protected void verifyQueryAPI(String schema, String dataType, Map<String, Object> row, boolean isInsert, String... errorMsg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Seems better to use SelectRowsCommand for this sort of thing rather than relying on browser/JavaScript.

{
String action = isInsert ? "insertRows" : "updateRows";
String updateScript = "LABKEY.Query." + action + "({ schemaName: \"" + schema + "\", "+
"queryName: " + EscapeUtil.toJSONStr(dataType) + ", " +
"success: callback," +
"failure: callback," +
"rows: [" + EscapeUtil.toJSONRow(row) + "]" +
"})";
executeAndVerifyScript(updateScript, errorMsg);
}

protected void executeAndVerifyScript(String script, @Nullable String... altErrors)
{
List<String> errors = new ArrayList<>();
if (altErrors != null)
errors = Arrays.stream(altErrors).filter(Objects::nonNull).toList();

Map<String, Object> result = (Map<String, Object>)executeAsyncScript(script);

String failureResult = APITestHelper.parseScriptResult(result);

if (altErrors == null || errors.isEmpty())
{
assertNull(failureResult); // null here means there was an unhandled server-side exception
checker().verifyNull("Unexpected error message", result.get("exception"));
}
else
{
Object exception = result.get("exception");
checker().verifyNotNull("Error is empty", exception);

if (exception instanceof String exceptionStr)
{
if (errors.size() == 1)
checker().verifyEquals("Unexpected error message", errors.get(0), exception);
else
{
for (String error : altErrors)
{
if (exceptionStr.equals(error))
return;

}
checker().error("Unexpected error message: " + exception);
}
}
}
}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
Expand Down
17 changes: 17 additions & 0 deletions src/org/labkey/test/tests/InlineImagesListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,30 @@ public final void testList() throws Exception
ImportDataPage listImportPage = _listHelper.clickImportData();
importFilePathError(listImportPage, "5", "absent.txt");
importFilePathError(listImportPage, "5", PDF_FILE.getName());
importFilePathError(listImportPage, "5", "123");
listImportPage.setCopyPasteMerge(false, true);
importFilePathError(listImportPage, "1", "absent.txt");
importFilePathError(listImportPage, "1", PDF_FILE.getName());
importFilePathError(listImportPage, "1", "true");
listImportPage.setCopyPasteMerge(true, true);
importFilePathError(listImportPage, "1", "absent.txt");
importFilePathError(listImportPage, "1", PDF_FILE.getName());
importFilePathError(listImportPage, "5", PDF_FILE.getName());

String attachmentError = "Can't upload '%s' to field %s with type Attachment.";
String attachmentPdfError = String.format(attachmentError, PDF_FILE.getName(), LIST_ATTACHMENT01_NAME);
String attachmentAbsentError = String.format(attachmentError, "Absent.txt", LIST_ATTACHMENT01_NAME);
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 5, LIST_ATTACHMENT01_NAME, PDF_FILE.getName()), true, "Row 1: " + attachmentPdfError);
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 5, LIST_ATTACHMENT01_NAME, "Absent.txt"), true, "Row 1: " + attachmentAbsentError);
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 5, LIST_ATTACHMENT01_NAME, 123), true, "Row 1: " + String.format(attachmentError, "123", LIST_ATTACHMENT01_NAME));
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 5, LIST_ATTACHMENT01_NAME, 123.456), true, "Row 1: " + String.format(attachmentError, "123.456", LIST_ATTACHMENT01_NAME));
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 5, LIST_ATTACHMENT01_NAME, true), true, "Row 1: " + String.format(attachmentError, "true", LIST_ATTACHMENT01_NAME));
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 1, LIST_ATTACHMENT01_NAME, PDF_FILE.getName()), false, attachmentPdfError);
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 1, LIST_ATTACHMENT01_NAME, "Absent.txt"), false, attachmentAbsentError);
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 1, LIST_ATTACHMENT01_NAME, 123), false, String.format(attachmentError, "123", LIST_ATTACHMENT01_NAME));
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 1, LIST_ATTACHMENT01_NAME, 123.456), false, String.format(attachmentError, "123.456", LIST_ATTACHMENT01_NAME));
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 1, LIST_ATTACHMENT01_NAME, true), false, String.format(attachmentError, "true", LIST_ATTACHMENT01_NAME));
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 1, LIST_ATTACHMENT01_NAME, ""/*can remove attachment*/), false);
}

private void importFilePathError(ImportDataPage listImportPage, String key, String attachmentValue)
Expand Down
9 changes: 8 additions & 1 deletion src/org/labkey/test/util/EscapeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ static public String toJSONStr(String str)
return "\"" + escaped + "\"";
}

static public String toJSONStr(Object value)
{
if (value instanceof String strVal)
return toJSONStr(strVal);
return String.valueOf(value);
}

static public String toJSONRow(Map<String, Object> row)
{
StringBuilder sb = new StringBuilder("{");
Expand All @@ -63,7 +70,7 @@ static public String toJSONRow(Map<String, Object> row)
sb.append(comma);
Object value = entry.getValue();
sb.append(EscapeUtil.toJSONStr(entry.getKey()))
.append(": ").append(value instanceof String ? EscapeUtil.toJSONStr((String) entry.getValue()) : value);
.append(": ").append(toJSONStr(value));
comma = ",";
}
sb.append("}");
Expand Down