diff --git a/src/org/labkey/test/params/assay/AssayDesign.java b/src/org/labkey/test/params/assay/AssayDesign.java index b2e67dc107..984ffc82f8 100644 --- a/src/org/labkey/test/params/assay/AssayDesign.java +++ b/src/org/labkey/test/params/assay/AssayDesign.java @@ -32,6 +32,7 @@ public abstract class AssayDesign> { + final String _name; final String _providerName; final List> _transformers = new ArrayList<>(); @@ -39,6 +40,7 @@ protected AssayDesign(String providerName, String name) { _providerName = providerName; _transformers.add(p -> p.setName(name)); + _name = name; } public static AssayDesign of(String providerName, String name) @@ -76,15 +78,15 @@ public T setFields(String domainName, List 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; } diff --git a/src/org/labkey/test/tests/DataClassFolderExportImportTest.java b/src/org/labkey/test/tests/DataClassFolderExportImportTest.java index dae91fb581..2ceb6350a8 100644 --- a/src/org/labkey/test/tests/DataClassFolderExportImportTest.java +++ b/src/org/labkey/test/tests/DataClassFolderExportImportTest.java @@ -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 runNames = sourceRunsTable.getColumnDataAsText("Name"); clickAndWait(Locator.linkWithText(testDataClass)); @@ -158,7 +158,7 @@ public void testExportImportSimpleDataClass() throws Exception importFolderFromZip(exportedFolderFile, false, 1); goToProjectFolder(IMPORT_PROJECT_NAME, importFolder); - List importedRunNames = DataRegionTable.DataRegion(getDriver()).withName("Runs").waitFor() + List importedRunNames = DataRegionTable.DataRegion(getDriver()).inWebPart("Experiment Runs").waitFor() .getColumnDataAsText("Name"); for (String sourceRun : runNames) { @@ -172,7 +172,7 @@ public void testExportImportSimpleDataClass() throws Exception List> destRowData = destTable.getTableData(); // now ensure expected data in the sampleType made it to the destination folder - for (Map exportedRow : sourceRowData) + for (Map exportedRow : sourceRowData) { // find the map from the exported project with the same name Map matchingMap = destRowData.stream().filter(a-> a.get("Name").equals(exportedRow.get("Name"))) @@ -289,7 +289,7 @@ public void testExportImportMissingValueDataClass() throws Exception List> destRowData = importTable.getTableData(); // now ensure expected data in the sampleType made it to the destination folder - for (Map exportedRow : sourceRowData) + for (Map exportedRow : sourceRowData) { // find the map from the exported project with the same name Map matchingMap = destRowData.stream().filter(a-> a.get("Name").equals(exportedRow.get("Name"))) diff --git a/src/org/labkey/test/tests/SampleTypeFolderExportImportTest.java b/src/org/labkey/test/tests/SampleTypeFolderExportImportTest.java index 8e478a4508..eaef546e67 100644 --- a/src/org/labkey/test/tests/SampleTypeFolderExportImportTest.java +++ b/src/org/labkey/test/tests/SampleTypeFolderExportImportTest.java @@ -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; @@ -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; @@ -141,17 +140,9 @@ protected boolean areDataListEqual(List> list01, List o1, Map o2)-> - { - return o1.get("Name").compareTo(o2.get("Name")); - } - ); + list01.sort(Comparator.comparing((Map o) -> o.get("Name"))); - Collections.sort(list02, (Map o1, Map o2)-> - { - return o1.get("Name").compareTo(o2.get("Name")); - } - ); + list02.sort(Comparator.comparing((Map o) -> o.get("Name"))); boolean areEqual = true; @@ -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 runNames = sourceRunsTable.getColumnDataAsText("Name"); clickAndWait(Locator.linkWithText(testSamples)); @@ -510,7 +502,7 @@ public void testExportImportDerivedSamples() throws Exception importFolderFromZip(exportedFolderFile, false, 1); goToProjectFolder(IMPORT_PROJECT_NAME, importFolder); - List importedRunNames = DataRegionTable.DataRegion(getDriver()).withName("Runs").waitFor() + List importedRunNames = DataRegionTable.DataRegion(getDriver()).inWebPart("Experiment Runs").waitFor() .getColumnDataAsText("Name"); for (String sourceRun : runNames) { @@ -530,7 +522,7 @@ public void testExportImportDerivedSamples() throws Exception List> destRowData = destSamplesTable.getTableData(); // now ensure expected data in the sampleType made it to the destination folder - for (Map exportedRow : sourceRowData) + for (Map exportedRow : sourceRowData) { // find the map from the exported project with the same name Map matchingMap = destRowData.stream().filter(a-> a.get("Name").equals(exportedRow.get("Name"))) @@ -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 sourceParents = Arrays.asList(exportedRow.get("Inputs/Materials/parentSamples").toString() + List 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 sourceDataParents = Arrays.asList(exportedRow.get("Inputs/Data/parentDataClass").toString() + List 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)); @@ -761,7 +753,7 @@ public void testExportImportSampleTypesWithAssayRuns() throws Exception importData.add(importedDataTable.getRowDataAsMap(i)); } - for (Map exportedRow : exportData) + for (Map exportedRow : exportData) { // find the map from the exported project with the same name Map matchingMap = importData.stream().filter(a -> a.get("sampleId").equals(exportedRow.get("sampleId"))) @@ -797,14 +789,14 @@ private FieldDefinition getFieldByNamePart(List 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 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 ***************"); diff --git a/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java b/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java index b1b7b43f15..c77367b77b 100644 --- a/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java +++ b/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java @@ -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; @@ -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"); @@ -112,7 +114,7 @@ private void doSetup() - private void createSampleTypes() + private void createSampleTypes() throws IOException { SampleTypeHelper sampleHelper = new SampleTypeHelper(this); @@ -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( @@ -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) diff --git a/src/org/labkey/test/util/DataRegionTable.java b/src/org/labkey/test/util/DataRegionTable.java index 0693e05443..4da1974f64 100644 --- a/src/org/labkey/test/util/DataRegionTable.java +++ b/src/org/labkey/test/util/DataRegionTable.java @@ -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() { @@ -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()