From 5695dda1336580a22901e8dec217a1f7ebf445c6 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Thu, 16 Dec 2021 14:09:56 -0500 Subject: [PATCH 1/6] Improved ExtractionTest Validation of Attachment and Extracted Children Expected vs Found Count. Added 3 more tests to TestExtractionTest to further tests. --- ...tachmentAndExtractedRecordCountFailure.xml | 53 +++++++++++++++++++ ...tAttachmentAndExtractedRecordCountTest.xml | 53 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml create mode 100644 src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml diff --git a/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml b/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml new file mode 100644 index 0000000000..c25a00da0f --- /dev/null +++ b/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml @@ -0,0 +1,53 @@ + + + MESSAGE + + + + 0 + MIME-PROCESSED + 1 + MESSAGE + MESSAGE.dat + 0 + + + XML_RECORD + XML_RECORD + XML.dat-att-1-att-1 + + root.element1 + elementValue + + + + XML_RECORD + XML_RECORD + XML.dat-att-1-att-2-att-1 + + root.element2.child1 + child1Value + + + + XML_RECORD + XML_RECORD + XML.dat-att-1-att-2-att-2 + + root.element2.child2..attribute1 + attribute1Value + + + root.element2.child2..attribute2 + attribute2Value + + + + 1 + UNKNOWN + 19 + just the body pls + + + + diff --git a/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml b/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml new file mode 100644 index 0000000000..bb3510b9d4 --- /dev/null +++ b/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml @@ -0,0 +1,53 @@ + + + MESSAGE + + + + 1 + MIME-PROCESSED + 1 + MESSAGE + MESSAGE.dat + 3 + + + XML_RECORD + XML_RECORD + XML.dat-att-1-att-1 + + root.element1 + elementValue + + + + XML_RECORD + XML_RECORD + XML.dat-att-1-att-2-att-1 + + root.element2.child1 + child1Value + + + + XML_RECORD + XML_RECORD + XML.dat-att-1-att-2-att-2 + + root.element2.child2..attribute1 + attribute1Value + + + root.element2.child2..attribute2 + attribute2Value + + + + 1 + UNKNOWN + 19 + just the body pls + + + + From 9d132c8501936ca9fe4cbe14d63959c83f2aea88 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Thu, 30 Dec 2021 16:37:06 -0500 Subject: [PATCH 2/6] Fixed issues with both Att and Extract Count. All possible cases should be covered now and should throw the correct error in each case. Added more tests to verify errors being thrown in each case. Removed two of the previous testing xmls, created a new, simpler xml for testing --- ...tachmentAndExtractedRecordCountFailure.xml | 53 ------------------- ...tAttachmentAndExtractedRecordCountTest.xml | 53 ------------------- .../core/TestExtractionAttAndExtractCount.xml | 24 +++++++++ 3 files changed, 24 insertions(+), 106 deletions(-) delete mode 100644 src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml delete mode 100644 src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml create mode 100644 src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml diff --git a/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml b/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml deleted file mode 100644 index c25a00da0f..0000000000 --- a/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountFailure.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - MESSAGE - - - - 0 - MIME-PROCESSED - 1 - MESSAGE - MESSAGE.dat - 0 - - - XML_RECORD - XML_RECORD - XML.dat-att-1-att-1 - - root.element1 - elementValue - - - - XML_RECORD - XML_RECORD - XML.dat-att-1-att-2-att-1 - - root.element2.child1 - child1Value - - - - XML_RECORD - XML_RECORD - XML.dat-att-1-att-2-att-2 - - root.element2.child2..attribute1 - attribute1Value - - - root.element2.child2..attribute2 - attribute2Value - - - - 1 - UNKNOWN - 19 - just the body pls - - - - diff --git a/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml b/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml deleted file mode 100644 index bb3510b9d4..0000000000 --- a/src/test/resources/emissary/test/core/TestAttachmentAndExtractedRecordCountTest.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - MESSAGE - - - - 1 - MIME-PROCESSED - 1 - MESSAGE - MESSAGE.dat - 3 - - - XML_RECORD - XML_RECORD - XML.dat-att-1-att-1 - - root.element1 - elementValue - - - - XML_RECORD - XML_RECORD - XML.dat-att-1-att-2-att-1 - - root.element2.child1 - child1Value - - - - XML_RECORD - XML_RECORD - XML.dat-att-1-att-2-att-2 - - root.element2.child2..attribute1 - attribute1Value - - - root.element2.child2..attribute2 - attribute2Value - - - - 1 - UNKNOWN - 19 - just the body pls - - - - diff --git a/src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml b/src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml new file mode 100644 index 0000000000..504ba65fdb --- /dev/null +++ b/src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml @@ -0,0 +1,24 @@ + + + + 1 + 1 + + + 1 + UNKNOWN + 19 + just the body pls + + + XML_RECORD + XML_RECORD + XML.dat-att-1-att-1 + + root.element1 + elementValue + + + + + From 8efa6fdaa457914a4058c47f5fc05bf752b457a7 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Thu, 19 Sep 2024 11:51:02 -0400 Subject: [PATCH 3/6] rebased and updates --- .../test/core/junit5/ExtractionTest.java | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/src/test/java/emissary/test/core/junit5/ExtractionTest.java b/src/test/java/emissary/test/core/junit5/ExtractionTest.java index aa92e7f478..1da7a3ba33 100644 --- a/src/test/java/emissary/test/core/junit5/ExtractionTest.java +++ b/src/test/java/emissary/test/core/junit5/ExtractionTest.java @@ -48,6 +48,9 @@ public abstract class ExtractionTest extends UnitTest { private static final List 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 data() { /** * Allow overriding the initial form in extensions to this test. - * + * * By default, get the initial form from the filename in the form {@code INITIAL_FORM@2.dat} 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 elements"); + } else { + if (Math.toIntExact(numAttElements) != numAtt) { + logger.warn("Expected numAttachments and actual 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 elements"); + } else { + if (Math.toIntExact(numExtractElements) != extractCount) { + logger.warn("Expected extractCount and actual count in {} not equal. Expected: {} Actual: {}", tname, + Math.max(extractCount, 0), numExtractElements); + } + } + } if (payload.hasExtractedRecords()) { List 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; + } } From 0e0e0c827e0cf644edf36cd3e511188f6e8dc07d Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Thu, 19 Sep 2024 11:56:17 -0400 Subject: [PATCH 4/6] removing added test --- .../core/TestExtractionAttAndExtractCount.xml | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml diff --git a/src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml b/src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml deleted file mode 100644 index 504ba65fdb..0000000000 --- a/src/test/resources/emissary/test/core/TestExtractionAttAndExtractCount.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - 1 - 1 - - - 1 - UNKNOWN - 19 - just the body pls - - - XML_RECORD - XML_RECORD - XML.dat-att-1-att-1 - - root.element1 - elementValue - - - - - From 4e392664d231c17fd558f41dd8a523b5387c7af1 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Thu, 26 Sep 2024 16:20:45 -0400 Subject: [PATCH 5/6] change validation process to be less burdensome donwstream --- .../test/core/junit5/ExtractionTest.java | 76 +++++++++---------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/src/test/java/emissary/test/core/junit5/ExtractionTest.java b/src/test/java/emissary/test/core/junit5/ExtractionTest.java index 1da7a3ba33..1a0bbf8853 100644 --- a/src/test/java/emissary/test/core/junit5/ExtractionTest.java +++ b/src/test/java/emissary/test/core/junit5/ExtractionTest.java @@ -48,9 +48,6 @@ public abstract class ExtractionTest extends UnitTest { private static final List 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); @@ -177,19 +174,25 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< 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 elements"); - } else { - if (Math.toIntExact(numAttElements) != numAtt) { - logger.warn("Expected numAttachments and actual count in {} not equal. Expected: {} Actual: {}", tname, - Math.max(numAtt, 0), numAttElements); - } + // check attachments answer file count against payload count + if (numAtt > -1) { + assertEquals(numAtt, attachments != null ? attachments.size() : 0, + String.format("Expected in %s not equal to number of att in payload.", tname)); + } else if (numAtt == -1 && numAttElements > 0) { + assertEquals(numAttElements, attachments != null ? attachments.size() : 0, + String.format("Expected in %s not equal to number of att in payload.", tname)); + } else { + if (attachments != null && !attachments.isEmpty()) { + fail(String.format("%d attachments in payload with no count in answer xml, add matching count for %s", + attachments.size(), tname)); } } - if (numAtt > -1) { - assertEquals(numAtt, attachments != null ? attachments.size() : 0, "Number of attachments in " + tname); + // log if and don't match in answer file + if (numAtt > -1 || numAttElements > 0) { + if (Math.toIntExact(numAttElements) != numAtt) { + logger.warn("Expected and actual attachment counts in {} not equal. : {} : {}", tname, + Math.max(numAtt, 0), numAttElements); + } } for (Element currentForm : el.getChildren("currentForm")) { @@ -293,31 +296,23 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< assertNull(viewData, String.format("Alternate View '%s' is present, but should not be, in %s", viewName, tname)); } - // Check each extract 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 elements"); - } else { - if (Math.toIntExact(numExtractElements) != extractCount) { - logger.warn("Expected extractCount and actual count in {} not equal. Expected: {} Actual: {}", tname, - Math.max(extractCount, 0), numExtractElements); - } - } - } - if (payload.hasExtractedRecords()) { List extractedChildren = payload.getExtractedRecords(); int foundCount = extractedChildren.size(); - + // check extracted records answer file count against payload count if (extractCount > -1) { assertEquals(extractCount, foundCount, - String.format("Number of extracted children in '%s' is %s, not expected %s", tname, foundCount, - extractCount)); + String.format("Expected in %s not equal to number of extracts in payload.", tname)); + } else if (extractCount == -1 && numExtractElements > 0) { + assertEquals(numExtractElements, foundCount, + String.format("Expected in %s not equal to number of extracts in payload.", tname)); + } else { + fail(String.format("%d extracts in payload with no count in answer xml, add matching count for %s", + foundCount, tname)); } int attNum = 1; @@ -331,7 +326,17 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< } else { if (extractCount > -1) { assertEquals(0, extractCount, - String.format("No extracted children in '%s' when expecting %s", tname, extractCount)); + String.format("No extracted children in '%s' when is %d", tname, extractCount)); + } else if (numExtractElements > 0) { + assertEquals(0, numExtractElements, + String.format("No extracted children in '%s' when is %d", tname, numExtractElements)); + } + } + // log if and don't match in answer file + if (extractCount > -1 || numExtractElements > 0) { + if (Math.toIntExact(numExtractElements) != extractCount) { + logger.warn("Expected and actual extract counts in {} not equal. : {} : {}", tname, + Math.max(extractCount, 0), numExtractElements); } } } @@ -448,13 +453,4 @@ 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; - } } From 4cd331d93365adf354a59cbad6ef03135ac781f7 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Fri, 27 Sep 2024 09:11:14 -0400 Subject: [PATCH 6/6] removing log messages --- .../emissary/test/core/junit5/ExtractionTest.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/test/java/emissary/test/core/junit5/ExtractionTest.java b/src/test/java/emissary/test/core/junit5/ExtractionTest.java index 1a0bbf8853..9359adf016 100644 --- a/src/test/java/emissary/test/core/junit5/ExtractionTest.java +++ b/src/test/java/emissary/test/core/junit5/ExtractionTest.java @@ -187,13 +187,6 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< attachments.size(), tname)); } } - // log if and don't match in answer file - if (numAtt > -1 || numAttElements > 0) { - if (Math.toIntExact(numAttElements) != numAtt) { - logger.warn("Expected and actual attachment counts in {} not equal. : {} : {}", tname, - Math.max(numAtt, 0), numAttElements); - } - } for (Element currentForm : el.getChildren("currentForm")) { String cf = currentForm.getTextTrim(); @@ -332,13 +325,6 @@ protected void checkAnswers(Element el, IBaseDataObject payload, @Nullable List< String.format("No extracted children in '%s' when is %d", tname, numExtractElements)); } } - // log if and don't match in answer file - if (extractCount > -1 || numExtractElements > 0) { - if (Math.toIntExact(numExtractElements) != extractCount) { - logger.warn("Expected and actual extract counts in {} not equal. : {} : {}", tname, - Math.max(extractCount, 0), numExtractElements); - } - } } private static void checkForMissingNameElement(String parentTag, String key, String tname) {