From 4e392664d231c17fd558f41dd8a523b5387c7af1 Mon Sep 17 00:00:00 2001 From: Sam Bishop Date: Thu, 26 Sep 2024 16:20:45 -0400 Subject: [PATCH] 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; - } }