Skip to content

Commit 7205dfb

Browse files
authored
Provide warnings for unknown fields for cross sample type import (#2862)
- Test fixes for change from quoted values to bold in error messages
1 parent a224169 commit 7205dfb

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/org/labkey/test/LabKeySiteWrapper.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,23 +1721,29 @@ protected void deletePipelineJob(@LoggedParam String jobDescription, @LoggedPara
17211721

17221722
public String getConversionErrorMessage(Object value, String fieldName, Class<?> targetClass)
17231723
{
1724-
return getConversionErrorMessage(value, fieldName, targetClass, true);
1724+
return getConversionErrorMessage(value, fieldName, targetClass, true, false);
17251725
}
17261726

17271727
// Note: Keep in sync with ConvertHelper.getStandardConversionErrorMessage()
17281728
// Example: "Could not convert value '2.34' (Double) for Boolean field 'Medical History.Dep Diagnosed in Last 18 Months'"
1729-
public String getConversionErrorMessage(Object value, String fieldName, Class<?> targetClass, boolean useUSDateParsing)
1729+
public String getConversionErrorMessage(Object value, String fieldName, Class<?> targetClass, boolean useUSDateParsing, boolean withoutSingleQuotes)
17301730
{
1731+
String errorMessage;
17311732
String fieldType = targetClass.getSimpleName();
1733+
String quote = withoutSingleQuotes ? "" : "'";
17321734

17331735
// Issue 50768: Need a better error message if date value is not in the expected format.
17341736
if (fieldType.equalsIgnoreCase("date") || fieldType.equalsIgnoreCase("datetime") || fieldType.equalsIgnoreCase("timestamp"))
17351737
{
17361738
String parsingMode = useUSDateParsing ? "U.S. date parsing (MDY)" : "Non-U.S. date parsing (DMY)";
1737-
return "'" + value + "' is not a valid " + fieldType + " for " + fieldName + " using " + parsingMode;
1739+
errorMessage = quote + value + quote + " is not a valid " + fieldType + " for " + fieldName + " using " + parsingMode;
1740+
}
1741+
else
1742+
{
1743+
errorMessage = "Could not convert value " + quote + value + quote + " (" + value.getClass().getSimpleName() + ") for " + fieldType + " field " + quote + fieldName + quote;
17381744
}
17391745

1740-
return "Could not convert value '" + value + "' (" + value.getClass().getSimpleName() + ") for " + fieldType + " field '" + fieldName + "'" ;
1746+
return errorMessage;
17411747
}
17421748

17431749
private ProductKey getProductConfiguration() throws IOException, CommandException

src/org/labkey/test/tests/InlineImagesListTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public final void testList() throws Exception
372372
importFilePathError(listImportPage, "1", PDF_FILE.getName());
373373
importFilePathError(listImportPage, "5", PDF_FILE.getName());
374374

375-
String attachmentError = "Can't upload '%s' to field %s with type Attachment.";
375+
String attachmentError = "Cannot upload '%s' to Attachment type field '%s'.";
376376
String attachmentPdfError = String.format(attachmentError, PDF_FILE.getName(), LIST_ATTACHMENT01_NAME);
377377
String attachmentAbsentError = String.format(attachmentError, "Absent.txt", LIST_ATTACHMENT01_NAME);
378378
verifyQueryAPI("lists", LIST_NAME, Map.of(LIST_KEY_NAME, 5, LIST_ATTACHMENT01_NAME, PDF_FILE.getName()), true, "Row 1: " + attachmentPdfError);
@@ -397,7 +397,7 @@ private void importFilePathError(ImportDataPage listImportPage, String key, Stri
397397
listImportPage.submitExpectingError();
398398
try
399399
{
400-
String expectedError = "Row 1: Can't upload '" + attachmentValue + "' to field " + LIST_ATTACHMENT01_NAME + " with type Attachment.";
400+
String expectedError = "Row 1: Cannot upload '" + attachmentValue + "' to Attachment type field '" + LIST_ATTACHMENT01_NAME + "'.";
401401
checker().withScreenshot("import_error").verifyTrue("Invalid attachment error not as expected", isElementPresent(Locator.tagWithClass("div", "labkey-error").withText(expectedError)));
402402
}
403403
catch(NoSuchElementException nse)

src/org/labkey/test/tests/SampleTypeTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,11 +1883,11 @@ public void testAmountsAndUnitsWithDisplayUnit()
18831883

18841884
log("verify error when inserting a row with an amount but no unit");
18851885
sampleHelper.insertRow(Map.of("Name", "AU-ERR-1", "StoredAmount", "0.0"));
1886-
assertTextPresent("No Units value provided for Amount 0.0.");
1886+
assertTextPresent("No 'Units' value provided for Amount '0.0'.");
18871887
clickButton("Cancel");
18881888
log("verify error when inserting a row with a unit but no amount");
18891889
sampleHelper.insertRow(Map.of("Name", "AU-ERR-2", "Units", "mL"));
1890-
assertTextPresent("No Amount value provided for Units mL.");
1890+
assertTextPresent("No 'Amount' value provided for Units 'mL'.");
18911891
clickButton("Cancel");
18921892

18931893
log("verify error when inserting a row with incompatible units");
@@ -1962,11 +1962,11 @@ public void testAmountsAndUnitsWithoutDisplayUnit()
19621962
log("verify that inserting a row with an amount or unit requires both fields to be filled in");
19631963
// insert row with amount but not unit (error expected)
19641964
sampleHelper.insertRow(Map.of("Name", "AU-ERR-1", "StoredAmount", "5.0"));
1965-
assertTextPresent("No Units value provided for Amount 5.0.");
1965+
assertTextPresent("No 'Units' value provided for Amount '5.0'.");
19661966
clickButton("Cancel");
19671967
// insert row with unit but not amount (error expected)
19681968
sampleHelper.insertRow(Map.of("Name", "AU-ERR-2", "Units", "mg"));
1969-
assertTextPresent("No Amount value provided for Units mg.");
1969+
assertTextPresent("No 'Amount' value provided for Units 'mg'.");
19701970
clickButton("Cancel");
19711971
// insert row with both amount and unit (success)
19721972
sampleHelper.insertRow(Map.of("Name", "AU-SUCCESS-1", "StoredAmount", "5.0", "Units", "mg"));
@@ -1975,11 +1975,11 @@ public void testAmountsAndUnitsWithoutDisplayUnit()
19751975
log("verify that updating a row with an amount or unit requires both fields to be filled in");
19761976
// update row with amount but not unit (error expected)
19771977
sampleHelper.updateRow(0, Map.of("Units", ""));
1978-
assertTextPresent("No Units value provided for Amount 5.0.");
1978+
assertTextPresent("No 'Units' value provided for Amount '5.0'.");
19791979
clickButton("Cancel");
19801980
// update row with unit but not amount (error expected)
19811981
sampleHelper.updateRow(0, Map.of("StoredAmount", ""));
1982-
assertTextPresent("No Amount value provided for Units mg.");
1982+
assertTextPresent("No 'Amount' value provided for Units 'mg'.");
19831983
clickButton("Cancel");
19841984
// update row with both amount and unit (success)
19851985
sampleHelper.updateRow(0, Map.of("StoredAmount", "10.0123", "Units", "g"));
@@ -1988,11 +1988,11 @@ public void testAmountsAndUnitsWithoutDisplayUnit()
19881988
log("verify that bulk import with an amount or unit requires both fields to be filled in");
19891989
// bulk import with amount but not unit (error expected)
19901990
sampleHelper.bulkImportExpectingError(List.of(Map.of("Name", "AU-BULK-ERR-1", "StoredAmount", "0")), SampleTypeHelper.IMPORT_OPTION);
1991-
assertTextPresent("A Units value must be provided when Amounts are provided");
1991+
assertTextPresent("A 'Units' value must be provided when 'Amounts' are provided");
19921992
clickButton("Cancel");
19931993
// bulk import with unit but not amount (error expected)
19941994
sampleHelper.bulkImportExpectingError(List.of(Map.of("Name", "AU-BULK-ERR-2", "Units", "mL")), SampleTypeHelper.IMPORT_OPTION);
1995-
assertTextPresent("An Amount value must be provided when Units are provided.");
1995+
assertTextPresent("An 'Amount' value must be provided when 'Units' are provided.");
19961996
clickButton("Cancel");
19971997
// bulk import with both amount and unit (success expected)
19981998
sampleHelper.bulkImport(List.of(Map.of("Name", "AU-BULK-SUCCESS-1", "StoredAmount", "0", "Units", "L")));

0 commit comments

Comments
 (0)