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
8 changes: 5 additions & 3 deletions src/org/labkey/test/params/assay/AssayDesign.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@

public abstract class AssayDesign<T extends AssayDesign<T>>
{
final String _name;
final String _providerName;
final List<Consumer<Protocol>> _transformers = new ArrayList<>();

protected AssayDesign(String providerName, String name)
{
_providerName = providerName;
_transformers.add(p -> p.setName(name));
_name = name;
}

public static AssayDesign<?> of(String providerName, String name)
Expand Down Expand Up @@ -76,15 +78,15 @@ public T setFields(String domainName, List<PropertyDescriptor> fields, boolean k

public Protocol createAssay(String containerPath, Connection connection) throws IOException, CommandException
{
TestLogger.info(String.format("Creating %s assay in '%s'", _providerName, containerPath));
TestLogger.info("Creating %s assay '%s' in '%s'".formatted(_providerName, _name, containerPath));

GetProtocolCommand getProtocolCommand = new GetProtocolCommand(_providerName);
ProtocolResponse getProtocolResponse = getProtocolCommand.execute(connection, containerPath);

Protocol protocol = updateProtocol(containerPath, connection, getProtocolResponse.getProtocol());

TestLogger.info(String.format("Successfully created %s assay '%s' in '%s':\n%s", _providerName,
protocol.getName(), containerPath, protocol.toJSONObject().toString(2)));
TestLogger.log().debug(() -> String.format("Successfully created %s assay '%s':\n%s", _providerName,
protocol.getName(), protocol.toJSONObject().toString(2)));

return protocol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void testExportImportSimpleDataClass() throws Exception
ph.addWebPart("Experiment Runs");
});

DataRegionTable sourceRunsTable = DataRegionTable.DataRegion(getDriver()).withName("Runs").waitFor();
DataRegionTable sourceRunsTable = DataRegionTable.DataRegion(getDriver()).inWebPart("Experiment Runs").waitFor();
List<String> runNames = sourceRunsTable.getColumnDataAsText("Name");

clickAndWait(Locator.linkWithText(testDataClass));
Expand All @@ -158,7 +158,7 @@ public void testExportImportSimpleDataClass() throws Exception
importFolderFromZip(exportedFolderFile, false, 1);
goToProjectFolder(IMPORT_PROJECT_NAME, importFolder);

List<String> importedRunNames = DataRegionTable.DataRegion(getDriver()).withName("Runs").waitFor()
List<String> importedRunNames = DataRegionTable.DataRegion(getDriver()).inWebPart("Experiment Runs").waitFor()
.getColumnDataAsText("Name");
for (String sourceRun : runNames)
{
Expand All @@ -172,7 +172,7 @@ public void testExportImportSimpleDataClass() throws Exception
List<Map<String, String>> destRowData = destTable.getTableData();

// now ensure expected data in the sampleType made it to the destination folder
for (Map exportedRow : sourceRowData)
for (Map<String, String> exportedRow : sourceRowData)
{
// find the map from the exported project with the same name
Map<String, String> matchingMap = destRowData.stream().filter(a-> a.get("Name").equals(exportedRow.get("Name")))
Expand Down Expand Up @@ -289,7 +289,7 @@ public void testExportImportMissingValueDataClass() throws Exception
List<Map<String, String>> destRowData = importTable.getTableData();

// now ensure expected data in the sampleType made it to the destination folder
for (Map exportedRow : sourceRowData)
for (Map<String, String> exportedRow : sourceRowData)
{
// find the map from the exported project with the same name
Map<String, String> matchingMap = destRowData.stream().filter(a-> a.get("Name").equals(exportedRow.get("Name")))
Expand Down
38 changes: 15 additions & 23 deletions src/org/labkey/test/tests/SampleTypeFolderExportImportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.remoteapi.CommandException;
Expand Down Expand Up @@ -60,7 +59,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -141,17 +140,9 @@ protected boolean areDataListEqual(List<Map<String, String>> list01, List<Map<St
return false;

// Order the two lists so compare can be done by index and not by searching the two lists.
Collections.sort(list01, (Map<String, String> o1, Map<String, String> o2)->
{
return o1.get("Name").compareTo(o2.get("Name"));
}
);
list01.sort(Comparator.comparing((Map<String, String> o) -> o.get("Name")));

Collections.sort(list02, (Map<String, String> o1, Map<String, String> o2)->
{
return o1.get("Name").compareTo(o2.get("Name"));
}
);
list02.sort(Comparator.comparing((Map<String, String> o) -> o.get("Name")));

boolean areEqual = true;

Expand Down Expand Up @@ -485,11 +476,12 @@ public void testExportImportDerivedSamples() throws Exception
"ParentAlias", "Parent3, Parent2", "SelfParent", "Child5", "DataClassParent", "data2, data3"));
testDgen.insertRows();

PortalHelper portalHelper = new PortalHelper(this);
portalHelper.addWebPart("Sample Types");
portalHelper.addWebPart("Experiment Runs");
new PortalHelper(this).doInAdminMode(portalHelper -> {
portalHelper.addWebPart("Sample Types");
portalHelper.addWebPart("Experiment Runs");
});

DataRegionTable sourceRunsTable = DataRegionTable.DataRegion(getDriver()).withName("Runs").waitFor();
DataRegionTable sourceRunsTable = DataRegionTable.DataRegion(getDriver()).inWebPart("Experiment Runs").waitFor();
List<String> runNames = sourceRunsTable.getColumnDataAsText("Name");

clickAndWait(Locator.linkWithText(testSamples));
Expand All @@ -510,7 +502,7 @@ public void testExportImportDerivedSamples() throws Exception
importFolderFromZip(exportedFolderFile, false, 1);
goToProjectFolder(IMPORT_PROJECT_NAME, importFolder);

List<String> importedRunNames = DataRegionTable.DataRegion(getDriver()).withName("Runs").waitFor()
List<String> importedRunNames = DataRegionTable.DataRegion(getDriver()).inWebPart("Experiment Runs").waitFor()
.getColumnDataAsText("Name");
for (String sourceRun : runNames)
{
Expand All @@ -530,7 +522,7 @@ public void testExportImportDerivedSamples() throws Exception
List<Map<String, String>> destRowData = destSamplesTable.getTableData();

// now ensure expected data in the sampleType made it to the destination folder
for (Map exportedRow : sourceRowData)
for (Map<String, String> exportedRow : sourceRowData)
{
// find the map from the exported project with the same name
Map<String, String> matchingMap = destRowData.stream().filter(a-> a.get("Name").equals(exportedRow.get("Name")))
Expand All @@ -550,11 +542,11 @@ public void testExportImportDerivedSamples() throws Exception
assertThat("expect export and import values to be equivalent",
exportedRow.get(decimalColFieldKey), equalTo(matchingMap.get(decimalColFieldKey)));

List<String> sourceParents = Arrays.asList(exportedRow.get("Inputs/Materials/parentSamples").toString()
List<String> sourceParents = Arrays.asList(exportedRow.get("Inputs/Materials/parentSamples")
.replace(" ", "").split(","));
String[] importedParents = matchingMap.get("Inputs/Materials/parentSamples").replace(" ", "").split(",");
assertThat("expect parent sampleType derivation to round trip with equivalent values", sourceParents, hasItems(importedParents));
List<String> sourceDataParents = Arrays.asList(exportedRow.get("Inputs/Data/parentDataClass").toString()
List<String> sourceDataParents = Arrays.asList(exportedRow.get("Inputs/Data/parentDataClass")
.replace(" ", "").split(","));
String[] importedDataParents = matchingMap.get("Inputs/Data/parentDataClass").replace(" ", "").split(",");
assertThat("expect parent dataClass derivation to round trip with equivalent values", sourceDataParents, hasItems(importedDataParents));
Expand Down Expand Up @@ -761,7 +753,7 @@ public void testExportImportSampleTypesWithAssayRuns() throws Exception
importData.add(importedDataTable.getRowDataAsMap(i));
}

for (Map exportedRow : exportData)
for (Map<String, String> exportedRow : exportData)
{
// find the map from the exported project with the same name
Map<String, String> matchingMap = importData.stream().filter(a -> a.get("sampleId").equals(exportedRow.get("sampleId")))
Expand Down Expand Up @@ -797,14 +789,14 @@ private FieldDefinition getFieldByNamePart(List<FieldDefinition> fields, String
if (field.isNamePartMatch(namePart))
return field;
}
return null;
throw new RuntimeException("Field " + namePart + " not found: " + fields.stream().map(FieldDefinition::getName).toList());
}

private StringBuilder checkDisplayFields(String displayField, List<String> columnLabels)
{
StringBuilder tmpString = new StringBuilder();

if(!columnLabels.contains("Name"))
if(!columnLabels.contains(displayField))
{
String errorMsg = "Did not find the 'Name' column.";
log("\n*************** ERROR ***************\n" + errorMsg + "\n*************** ERROR ***************");
Expand Down
29 changes: 14 additions & 15 deletions src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.params.experiment.SampleTypeDefinition;
import org.labkey.test.util.DataRegionTable;
import org.labkey.test.util.DomainUtils;
import org.labkey.test.util.OptionalFeatureHelper;
import org.labkey.test.util.PortalHelper;
import org.labkey.test.util.SampleTypeHelper;
import org.labkey.test.util.StudyHelper;
import org.labkey.test.util.TestDataGenerator;
import org.labkey.test.util.data.TestDataUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -82,7 +84,7 @@ public static void setupProject() throws IOException
init.doSetup();
}

private void doSetup()
private void doSetup() throws IOException
{
_containerHelper.createProject(getProjectName(), null);
_containerHelper.createProject(VISIT_BASED_STUDY, "Study");
Expand Down Expand Up @@ -112,7 +114,7 @@ private void doSetup()



private void createSampleTypes()
private void createSampleTypes() throws IOException
{
SampleTypeHelper sampleHelper = new SampleTypeHelper(this);

Expand All @@ -130,11 +132,12 @@ private void createSampleTypes()
new FieldDefinition("ParticipantId", FieldDefinition.ColumnType.Subject))), data1);

goToProjectHome(SAMPLE_TYPE_PROJECT);
String data2 = "Name\tVisitLabel\tVisitDate\tParticipantId\n" +
"First\t" + visitLabel1 + "\t" + now + "\tP1\n" +
"Second\t" + visitLabel2 + "\t" + now + "\tP2\n" +
"Third\t" + visitLabel1 + "\t" + now + "\tP3\n" +
"Fourth\t" + visitLabel2 + "\t" + now + "\tP4\n";
File data2 = TestDataUtils.writeRowsToFile("samples.tsv", List.of(
List.of("Name", "VisitLabel", "VisitDate", "ParticipantId"),
List.of("First", visitLabel1, now, "P1"),
List.of("Second", visitLabel2, now, "P2"),
List.of("Third", visitLabel1, now, "P3"),
List.of("Fourth", visitLabel2, now, "P4")));

sampleHelper.createSampleType(new SampleTypeDefinition(SAMPLE_TYPE2)
.setFields(List.of(
Expand Down Expand Up @@ -777,14 +780,10 @@ public void testVisitLabelAutoLinkToStudy()
public void preTest() throws Exception
{
//deleting the datasets from study folders.
if (TestDataGenerator.doesDomainExists(DATE_BASED_STUDY, "study", "Sample type 1"))
TestDataGenerator.deleteDomain(DATE_BASED_STUDY, "study", "Sample type 1");
if (TestDataGenerator.doesDomainExists(DATE_BASED_STUDY, "study", "Sample type 2"))
TestDataGenerator.deleteDomain(DATE_BASED_STUDY, "study", "Sample type 2");
if (TestDataGenerator.doesDomainExists(VISIT_BASED_STUDY, "study", "Sample type 1"))
TestDataGenerator.deleteDomain(VISIT_BASED_STUDY, "study", "Sample type 1");
if (TestDataGenerator.doesDomainExists(VISIT_BASED_STUDY, "study", "Sample type 2"))
TestDataGenerator.deleteDomain(VISIT_BASED_STUDY, "study", "Sample type 2");
DomainUtils.ensureDeleted(DATE_BASED_STUDY, "study", "Sample type 1");
DomainUtils.ensureDeleted(DATE_BASED_STUDY, "study", "Sample type 2");
DomainUtils.ensureDeleted(VISIT_BASED_STUDY, "study", "Sample type 1");
DomainUtils.ensureDeleted(VISIT_BASED_STUDY, "study", "Sample type 2");
}

private void createNewVisits(String label, String startRange, String endRange)
Expand Down
15 changes: 14 additions & 1 deletion src/org/labkey/test/util/DataRegionTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ public DataRegionFinder withName(String name)
return this;
}

public DataRegionFinder inWebPart(String webPartTitle)
{
_loc = PortalHelper.Locators.webPart(webPartTitle).append(Locators.dataRegion());
return this;
}

@Override
protected Locator locator()
{
Expand All @@ -233,15 +239,22 @@ protected DataRegionTable construct(WebElement el, WebDriver driver)
}
}

/**
* @deprecated Use {@link DataRegionFinder} directly
*/
@Deprecated
public static DataRegionTable findDataRegion(WebDriverWrapper test)
{
return DataRegion(test.getDriver()).find();
}

/**
* @deprecated Use {@link DataRegionFinder#inWebPart(String)}
*/
@Deprecated
public static DataRegionTable findDataRegionWithinWebpart(WebDriverWrapper test, String webPartTitle)
{
return DataRegion(test.getDriver()).find(new RefindingWebElement(PortalHelper.Locators.webPart(webPartTitle), test.getDriver()));
return DataRegion(test.getDriver()).inWebPart(webPartTitle).find();
}

public int getColumnCount()
Expand Down