Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.labkey.test.tests;

import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -39,8 +40,11 @@ public class TextChoiceImportExportAndOtherDomainsTest extends TextChoiceTest
private static final String LIST_NAME = "Simple_TC_List";
private static final String LIST_TC_FIELD = "LTC_Field";
private static final String LIST_TEXT_FIELD = "Str";
private static final String LIST_MVTC_FIELD = "LMVTC_Field";
private static final List<String> LIST_VALUES = Arrays.asList("L1", "L2|withPipes|", "L3", "L4");
private static final List<String> LIST_MVTC_VALUES = Arrays.asList("M1&", "M2;b", "M3 %");
private static final List<Map<String, String>> listData = new ArrayList<>();
private static final List<List<String>> listMvtcData = new ArrayList<>();

// Issue names, etc...
private static final String ISSUE_DESIGN_NAME = "Simple_TC_Issue";
Expand Down Expand Up @@ -97,24 +101,41 @@ private void doSetup()
* <p>
* This test will:
* <ul>
* <li>Create a list design with a TextChoice field.</li>
* <li>Create a list design with a TextChoice field and optionally a MultiValueTextChoice field.</li>
* <li>Import list data in bulk.</li>
* <li>Add a new list item using the UI.</li>
* </ul>
* </p>
*
* @param includeMvtc If true, include a {@link FieldDefinition.ColumnType#MultiValueTextChoice} field
* in the list and populate it. Only supported on PostgreSQL.
*/
private void verifyTextChoiceInList()
private void verifyTextChoiceInList(boolean includeMvtc)
{

FieldDefinition tcField = new FieldDefinition(LIST_TC_FIELD, FieldDefinition.ColumnType.TextChoice);
tcField.setTextChoiceValues(LIST_VALUES);

FieldDefinition txtField = new FieldDefinition(LIST_TEXT_FIELD, FieldDefinition.ColumnType.String);

log(String.format("Create a list named '%s' with a string field '%s' and a TextChoice field '%s'.",
LIST_NAME, LIST_TEXT_FIELD, LIST_TC_FIELD));
final String allMVTCValues = StringUtils.join(LIST_MVTC_VALUES, ", ");
if (includeMvtc)
{
FieldDefinition mvtcField = new FieldDefinition(LIST_MVTC_FIELD, FieldDefinition.ColumnType.MultiValueTextChoice);
mvtcField.setMultiChoiceValues(LIST_MVTC_VALUES);

log(String.format("Create a list named '%s' with a string field '%s', a TextChoice field '%s', and a MultiValueTextChoice field '%s'.",
LIST_NAME, LIST_TEXT_FIELD, LIST_TC_FIELD, LIST_MVTC_FIELD));

_listHelper.createList(getCurrentContainerPath(), LIST_NAME, "Key", tcField, txtField);
_listHelper.createList(getCurrentContainerPath(), LIST_NAME, "Key", tcField, txtField, mvtcField);
}
else
{
log(String.format("Create a list named '%s' with a string field '%s' and a TextChoice field '%s'.",
LIST_NAME, LIST_TEXT_FIELD, LIST_TC_FIELD));

_listHelper.createList(getCurrentContainerPath(), LIST_NAME, "Key", tcField, txtField);
}

log("Bulk upload data into the list.");

Expand All @@ -124,10 +145,23 @@ private void verifyTextChoiceInList()
listData.add(Map.of(LIST_TC_FIELD, LIST_VALUES.get(2), LIST_TEXT_FIELD, "Is"));

StringBuilder sb = new StringBuilder();
sb.append(String.format("%s\t%s\n", LIST_TC_FIELD, LIST_TEXT_FIELD));
for(Map<String, String> row : listData)
if (includeMvtc)
{
sb.append(String.format("%s\t%s\n", row.get(LIST_TC_FIELD), row.get(LIST_TEXT_FIELD)));
sb.append(String.format("%s\t%s\t%s\n", LIST_TC_FIELD, LIST_TEXT_FIELD, LIST_MVTC_FIELD));
for (int i = 0; i < listData.size(); i++)
{
Map<String, String> row = listData.get(i);
sb.append(String.format("%s\t%s\t%s\n", row.get(LIST_TC_FIELD), row.get(LIST_TEXT_FIELD), allMVTCValues));
listMvtcData.add(LIST_MVTC_VALUES);
}
}
else
{
sb.append(String.format("%s\t%s\n", LIST_TC_FIELD, LIST_TEXT_FIELD));
for (Map<String, String> row : listData)
{
sb.append(String.format("%s\t%s\n", row.get(LIST_TC_FIELD), row.get(LIST_TEXT_FIELD)));
}
}

_listHelper.uploadData(sb.toString());
Expand All @@ -137,6 +171,9 @@ private void verifyTextChoiceInList()
// Add the new row to the expected data.
listData.add(newRow);

if (includeMvtc)
listMvtcData.add(List.of()); // No MVTC value for the UI-inserted row.

log("Add a new row to the list using the UI.");
_listHelper.insertNewRow(newRow);

Expand Down Expand Up @@ -208,6 +245,8 @@ private void verifyTextChoiceInIssueDesign()
@Test
public void testOtherDomainsExportAndImport() throws IOException, CommandException
{
boolean isPg = WebTestHelper.getDatabaseType() == WebTestHelper.DatabaseType.PostgreSQL;

goToProjectHome();

log("Create a sample type, assay design and an assay run. These will be used to validate export/import.");
Expand All @@ -220,7 +259,7 @@ public void testOtherDomainsExportAndImport() throws IOException, CommandExcepti
Map<String, String> assayResultRowData = createAssayRun();

log("Create a list with a TextChoice field. The list will also be validated after import.");
verifyTextChoiceInList();
verifyTextChoiceInList(isPg);

log("Create an issue design with a TextChoice field and create an issue that uses it. Issue designs are not exported.");
verifyTextChoiceInIssueDesign();
Expand All @@ -238,7 +277,7 @@ public void testOtherDomainsExportAndImport() throws IOException, CommandExcepti

_containerHelper.createProject(IMPORTED_PROJ_NAME, null);

importFolderFromZip(exportFile);
importFolderFromZip(exportFile, false, 1);

// Not sure if I need this either.
Assert.assertEquals("Import caused server side errors.", 0, getServerErrorCount());
Expand All @@ -254,21 +293,37 @@ public void testOtherDomainsExportAndImport() throws IOException, CommandExcepti

Connection cn = WebTestHelper.getRemoteApiConnection();
SelectRowsCommand cmd = new SelectRowsCommand("lists", LIST_NAME);
cmd.setColumns(Arrays.asList(LIST_TC_FIELD, LIST_TEXT_FIELD));
List<String> selectColumns = new ArrayList<>(Arrays.asList(LIST_TC_FIELD, LIST_TEXT_FIELD));
if (isPg)
selectColumns.add(LIST_MVTC_FIELD);
cmd.setColumns(selectColumns);

SelectRowsResponse response = cmd.execute(cn, getCurrentContainerPath());

List<Map<String, String>> importedListData = new ArrayList<>();
List<List<String>> importedListMvtcData = new ArrayList<>();
for (Map<String, Object> row : response.getRows())
{
importedListData.add(
Map.of(LIST_TC_FIELD, row.get(LIST_TC_FIELD).toString(),
LIST_TEXT_FIELD, row.get(LIST_TEXT_FIELD).toString()));

if (isPg)
{
Object mvtcRaw = row.get(LIST_MVTC_FIELD);
List<String> mvtcValues = mvtcRaw instanceof List<?> list
? list.stream().map(Object::toString).toList()
: List.of();
importedListMvtcData.add(mvtcValues);
}
}

checker().withScreenshot("Imported_List_Error")
.verifyEquals("Imported data for the list not as expected.", listData, importedListData);

if (isPg)
checker().verifyEquals("Imported MultiValueTextChoice data for the list not as expected.", listMvtcData, importedListMvtcData);

log("Validate the assay data.");
goToProjectHome(IMPORTED_PROJ_NAME);
waitAndClickAndWait(Locator.linkWithText(ASSAY_NAME));
Expand Down
Loading