-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ public abstract class ExtractionTest extends UnitTest { | |
private static final List<IBaseDataObject> NO_ATTACHMENTS = Collections.emptyList(); | ||
private static final byte[] INCORRECT_VIEW_MESSAGE = "This is the incorrect view, the place should not have processed this view".getBytes(); | ||
|
||
private boolean skipAttCountValidation = false; | ||
private boolean skipExtractCountValidation = false; | ||
|
||
protected KffDataObjectHandler kff = | ||
new KffDataObjectHandler(KffDataObjectHandler.TRUNCATE_KNOWN_DATA, KffDataObjectHandler.SET_FORM_WHEN_KNOWN, | ||
KffDataObjectHandler.SET_FILE_TYPE); | ||
|
@@ -78,7 +81,7 @@ public static Stream<? extends Arguments> data() { | |
|
||
/** | ||
* Allow overriding the initial form in extensions to this test. | ||
* | ||
* | ||
* By default, get the initial form from the filename in the form {@code [email protected]} where {@code INITIAL_FORM} | ||
* will be the initial form. | ||
* | ||
|
@@ -173,6 +176,18 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< | |
throws DataConversionException { | ||
|
||
int numAtt = JDOMUtil.getChildIntValue(el, "numAttachments"); | ||
long numAttElements = el.getChildren().stream().filter(c -> c.getName().startsWith("att")).count(); | ||
if (numAtt > -1 || numAttElements > 0) { | ||
if (!skipAttCountValidation) { | ||
assertEquals(Math.max(numAtt, 0), Math.toIntExact(numAttElements), | ||
"Expected numAttachments in " + tname + " not equal to number of <att#> elements"); | ||
} else { | ||
if (Math.toIntExact(numAttElements) != numAtt) { | ||
logger.warn("Expected numAttachments and actual <att#> count in {} not equal. Expected: {} Actual: {}", tname, | ||
Math.max(numAtt, 0), numAttElements); | ||
} | ||
} | ||
} | ||
if (numAtt > -1) { | ||
assertEquals(numAtt, attachments != null ? attachments.size() : 0, "Number of attachments in " + tname); | ||
} | ||
|
@@ -280,15 +295,29 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< | |
|
||
|
||
// Check each extract | ||
String extractCountStr = el.getChildTextTrim("extractCount"); | ||
int extractCount = JDOMUtil.getChildIntValue(el, "extractCount"); | ||
long numExtractElements = | ||
el.getChildren().stream().filter(c -> c.getName().startsWith("extract") && !c.getName().startsWith("extractCount")).count(); | ||
if (extractCount > -1 || numExtractElements > 0) { | ||
if (!skipExtractCountValidation) { | ||
assertEquals(Math.max(extractCount, 0), Math.toIntExact(numExtractElements), | ||
"Expected extractCount in " + tname + " not equal to number of <extract#> elements"); | ||
} else { | ||
if (Math.toIntExact(numExtractElements) != extractCount) { | ||
logger.warn("Expected extractCount and actual <extract#> count in {} not equal. Expected: {} Actual: {}", tname, | ||
Math.max(extractCount, 0), numExtractElements); | ||
} | ||
} | ||
} | ||
|
||
if (payload.hasExtractedRecords()) { | ||
List<IBaseDataObject> extractedChildren = payload.getExtractedRecords(); | ||
int foundCount = extractedChildren.size(); | ||
|
||
if (extractCountStr != null) { | ||
assertEquals(Integer.parseInt(extractCountStr), foundCount, | ||
String.format("Number of extracted children in '%s' is %s, not expected %s", tname, foundCount, extractCountStr)); | ||
if (extractCount > -1) { | ||
assertEquals(extractCount, foundCount, | ||
String.format("Number of extracted children in '%s' is %s, not expected %s", tname, foundCount, | ||
extractCount)); | ||
} | ||
|
||
int attNum = 1; | ||
|
@@ -300,9 +329,9 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< | |
attNum++; | ||
} | ||
} else { | ||
if (extractCountStr != null) { | ||
assertEquals(0, Integer.parseInt(extractCountStr), | ||
String.format("No extracted children in '%s' when expecting %s", tname, extractCountStr)); | ||
if (extractCount > -1) { | ||
assertEquals(0, extractCount, | ||
String.format("No extracted children in '%s' when expecting %s", tname, extractCount)); | ||
} | ||
} | ||
} | ||
|
@@ -419,4 +448,13 @@ protected void setupPayload(IBaseDataObject payload, Document doc) { | |
payload.setFileType(payload.currentForm()); | ||
} | ||
} | ||
|
||
// allow the validation of att and ext counts to be skipped/not logged in tests | ||
protected void setAttachmentCountValidation(boolean value) { | ||
this.skipAttCountValidation = !value; | ||
} | ||
|
||
protected void setExtractCountValidation(boolean value) { | ||
this.skipExtractCountValidation = !value; | ||
} | ||
} |