Skip to content

Commit a9cd30a

Browse files
Adopt FileLike for more pipeline APIs (#614)
1 parent 4d0ef5d commit a9cd30a

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

nirc_ehr/test/src/org.labkey.test/tests.nirc_ehr/NIRC_EHRTest.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
import org.apache.commons.io.FileUtils;
2020
import org.apache.commons.lang3.StringUtils;
21+
import org.jetbrains.annotations.NotNull;
2122
import org.jetbrains.annotations.Nullable;
2223
import org.junit.Assert;
2324
import org.junit.BeforeClass;
2425
import org.junit.Test;
2526
import org.junit.experimental.categories.Category;
2627
import org.labkey.api.reader.Readers;
28+
import org.labkey.api.util.FileUtil;
2729
import org.labkey.remoteapi.CommandException;
2830
import org.labkey.remoteapi.SimplePostCommand;
2931
import org.labkey.remoteapi.core.SaveModulePropertiesCommand;
@@ -100,8 +102,8 @@ public class NIRC_EHRTest extends AbstractGenericEHRTest implements PostgresOnly
100102
private static final String departedAnimalId = "H6767";
101103
private static final String aliveAnimalId = "A4545";
102104

103-
private String[] weightFields = {"Id", "date", "enddate", "project", "weight", FIELD_QCSTATELABEL, FIELD_OBJECTID, FIELD_LSID, "_recordid", "performedby"};
104-
private Object[] weightData1 = {getExpectedAnimalIDCasing("TESTSUBJECT1"), EHRClientAPIHelper.DATE_SUBSTITUTION, null, null, "12", EHRQCState.IN_PROGRESS.label, null, null, "_recordID", 1004};
105+
private final String[] weightFields = {"Id", "date", "enddate", "project", "weight", FIELD_QCSTATELABEL, FIELD_OBJECTID, FIELD_LSID, "_recordid", "performedby"};
106+
private final Object[] weightData1 = {getExpectedAnimalIDCasing("TESTSUBJECT1"), EHRClientAPIHelper.DATE_SUBSTITUTION, null, null, "12", EHRQCState.IN_PROGRESS.label, null, null, "_recordID", 1004};
105107

106108
DateTimeFormatter _dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd");
107109

@@ -115,7 +117,7 @@ public static void setupProject() throws Exception
115117
@Override
116118
public void importStudy()
117119
{
118-
File path = new File(TestFileUtils.getLabKeyRoot(), getModulePath() + "/resources/referenceStudy");
120+
File path = FileUtil.appendPath(TestFileUtils.getLabKeyRoot(), org.labkey.api.util.Path.parse(getModulePath() + "/resources/referenceStudy"));
119121
importFolderByPath(path, getContainerPath(), 1);
120122
path = TestFileUtils.getSampleData("nirc_ehr/study");
121123
importFolderByPath(path, getContainerPath(), 2);
@@ -278,7 +280,7 @@ private void doSetup() throws Exception
278280
private void populateEHRTables()
279281
{
280282
goToEHRFolder();
281-
File fileName = new File(TestFileUtils.getLabKeyRoot(), getModulePath() + "/resources/data/observation_types.tsv");
283+
File fileName = FileUtil.appendPath(TestFileUtils.getLabKeyRoot(), org.labkey.api.util.Path.parse(getModulePath() + "/resources/data/observation_types.tsv"));
282284
ImportDataCommand command = new ImportDataCommand("ehr", "observation_types");
283285
command.setFile(fileName);
284286
try
@@ -697,7 +699,7 @@ public void testClinicalObservation()
697699

698700
goToEHRFolder();
699701
waitAndClickAndWait(Locator.linkWithText("Active Clinical Cases"));
700-
ParticipantViewPage reportPage = new AnimalHistoryPage(getDriver()).clickCategoryTab("Clinical")
702+
ParticipantViewPage<?> reportPage = new AnimalHistoryPage<>(getDriver()).clickCategoryTab("Clinical")
701703
.clickReportTab("All Clinical Cases");
702704
table = reportPage.getActiveReportDataRegion();
703705
Assert.assertEquals("Case not closed correctly ", LocalDateTime.now().format(_dateFormat) + " 00:00", table.getDataAsText(0, "enddate"));
@@ -893,7 +895,7 @@ public void testDeathNecropsyForm() throws IOException, CommandException
893895
// The 'button' is actually a link tag.
894896
WebElement submitButton = Locator.tagWithText("a", "Submit").findWhenNeeded(submitForReview);
895897
scrollIntoView(submitButton);
896-
doAndWaitForPageToLoad(() -> submitButton.click());
898+
doAndWaitForPageToLoad(submitButton::click);
897899

898900
stopImpersonating();
899901

@@ -918,7 +920,7 @@ public void testDeathNecropsyForm() throws IOException, CommandException
918920
verifyRowCreated("study", "weight", aliveAnimalId, 1);
919921

920922
log("Verify animal is marked as dead");
921-
AnimalHistoryPage historyPage = AnimalHistoryPage.beginAt(this);
923+
AnimalHistoryPage<?> historyPage = AnimalHistoryPage.beginAt(this);
922924
historyPage.searchSingleAnimal(aliveAnimalId);
923925
waitForText(WAIT_FOR_PAGE, "Dead");
924926
waitForText("23 kg"); //checking latest weight is updated.
@@ -997,15 +999,15 @@ public void testClinicalCasesWorkflow()
997999
_ext4Helper.selectComboBoxItem(Ext4Helper.Locators.formItemWithLabelContaining("Ordered By:"), NIRC_VET_NAME);
9981000
waitAndClick(bulkEditWindow.append(Ext4Helper.Locators.ext4Button("Submit")));
9991001

1000-
Window msgWindow = new Window.WindowFinder(this.getDriver()).withTitle("Set Values").waitFor();
1002+
Window<?> msgWindow = new Window.WindowFinder(this.getDriver()).withTitle("Set Values").waitFor();
10011003
msgWindow.clickButton("Yes", 0);
10021004

10031005
submitForm("Submit Final", "Finalize Form");
10041006

10051007
log("Completing today's Medication Schedule");
10061008
goToEHRFolder();
10071009
waitAndClickAndWait(Locator.linkWithText("Today's Medication/Treatment Schedule"));
1008-
AnimalHistoryPage animalHistoryPage = new AnimalHistoryPage<>(getDriver());
1010+
AnimalHistoryPage<?> animalHistoryPage = new AnimalHistoryPage<>(getDriver());
10091011
DataRegionTable scheduleTable = animalHistoryPage.getActiveReportDataRegion();
10101012
Assert.assertEquals("Incorrect number of rows", 4, scheduleTable.getDataRowCount());
10111013
scheduleTable.link(0, "treatmentRecord").click();
@@ -1026,7 +1028,7 @@ public void testClinicalCasesWorkflow()
10261028
clickAndWait(Locator.linkWithText("Active Clinical Cases"));
10271029

10281030
//Click on 'Case Update' link
1029-
AnimalHistoryPage historyPage = new AnimalHistoryPage<>(getDriver());
1031+
AnimalHistoryPage<?> historyPage = new AnimalHistoryPage<>(getDriver());
10301032
DataRegionTable activeClinicalCases = historyPage.getActiveReportDataRegion();
10311033
activeClinicalCases.link(0, "caseCheck").click();
10321034
switchToWindow(2);
@@ -1089,7 +1091,7 @@ public void testLookupPage() throws Exception
10891091

10901092
EHRLookupPage ehrLookupPage = new EHRLookupPage(this);
10911093
QueryGrid grid = ehrLookupPage.getQueryGrid();
1092-
checker().verifyEquals("Missing look up tables", countLines(TestFileUtils.getLabKeyRoot() + getModulePath() + "/resources/data/editable_lookups.tsv") - 1, grid.getRecordCount());
1094+
checker().verifyEquals("Missing look up tables", countLines(FileUtil.appendPath(TestFileUtils.getLabKeyRoot(), org.labkey.api.util.Path.parse(getModulePath() + "/resources/data/editable_lookups.tsv"))) - 1, grid.getRecordCount());
10931095

10941096
clickAndWait(Locator.linkWithText("Age Class"));
10951097
checker().verifyEquals("Navigated to incorrect schema", "ehr_lookups", getUrlParam("schemaName"));
@@ -1163,7 +1165,7 @@ public void testBehavioralCases()
11631165
log("Verify reports and schedule");
11641166
goToEHRFolder();
11651167
waitAndClickAndWait(Locator.linkWithText("Active Behavior Cases"));
1166-
AnimalHistoryPage animalHistoryPage = new AnimalHistoryPage<>(getDriver());
1168+
AnimalHistoryPage<?> animalHistoryPage = new AnimalHistoryPage<>(getDriver());
11671169
DataRegionTable activeCase = animalHistoryPage.getActiveReportDataRegion();
11681170
Assert.assertEquals("Behavioral case did not get created", 2, activeCase.getDataRowCount());
11691171

@@ -1230,9 +1232,9 @@ public void testBehavioralCases()
12301232
Assert.assertEquals("Case was not closed", 1, activeCase.getDataRowCount());
12311233
}
12321234

1233-
private int countLines(String filePath) throws Exception
1235+
private int countLines(File file) throws Exception
12341236
{
1235-
try (BufferedReader reader = Readers.getReader(new File(filePath)))
1237+
try (BufferedReader reader = Readers.getReader(file))
12361238
{
12371239
int count = 0;
12381240
while (reader.readLine() != null)
@@ -1262,7 +1264,7 @@ private void verifyOrchardFileGenerated(String animalId)
12621264
Files.walkFileTree(orchardFileLocation.toPath(), new SimpleFileVisitor<>()
12631265
{
12641266
@Override
1265-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
1267+
public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs)
12661268
{
12671269
// Check if the file name starts with "orchardFile"
12681270
if (file.getFileName().toString().startsWith(prefix))
@@ -1281,7 +1283,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
12811283
}
12821284
catch (IOException e)
12831285
{
1284-
e.printStackTrace();
1286+
log("Error while traversing the directory: " + e.getMessage());
12851287
}
12861288

12871289
if (largestTimestamp[0].equals("0"))
@@ -1290,7 +1292,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
12901292
}
12911293

12921294
File orchardFile = new File(orchardFileLocation + "/orchardFile" + largestTimestamp[0] + ".txt");
1293-
waitFor(() -> orchardFile.exists(), WAIT_FOR_PAGE);
1295+
waitFor(orchardFile::exists, WAIT_FOR_PAGE);
12941296
Assert.assertTrue("Edited animal is not present in the orchard file",
12951297
TestFileUtils.getFileContents(orchardFile).contains(animalId));
12961298
}

0 commit comments

Comments
 (0)