Skip to content

Commit

Permalink
Added ability to skip Att and Extract Count Check. Added all count va…
Browse files Browse the repository at this point in the history
…lidation to junit5/ExtractionTest as well.
  • Loading branch information
sambish5 committed Oct 12, 2022
1 parent 7663f03 commit d0e5d9a
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 41 deletions.
28 changes: 16 additions & 12 deletions src/test/java/emissary/test/core/ExtractionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,17 @@ protected void checkAnswers(Document answers, IBaseDataObject payload, List<IBas
}

protected void checkAnswers(Element el, IBaseDataObject payload, List<IBaseDataObject> attachments, String tname) throws DataConversionException {
// check to see if payload has extracted records or see if attachments is not null
// if true, implement check on IBaseDataObject payload and attachments to compare expected v found counts
// else, implement base check of resource
if ((attachments != null) || payload.hasExtractedRecords()) {
checkAttachmentAndExtractedRecordCount(el, payload, attachments, tname);
} else {
checkAttachmentAndExtractedRecordCount(resource, el, tname);
// see if <skipAttExtCountCheck> exists in answer file and if the text != true.
String skipAttExtCountCheck = el.getChildTextTrim("skipAttExtCountCheck");
if (skipAttExtCountCheck == null || !skipAttExtCountCheck.equalsIgnoreCase("true")) {
// see if payload has extracted records or see if attachments is not null
if (attachments != null || payload.hasExtractedRecords()) {
// implement check on IBaseDataObject payload and attachments to compare expected v found counts
checkAttachmentAndExtractedRecordCount(el, payload, attachments, tname);
} else {
// implement base check of resource answer file
checkAttachmentAndExtractedRecordCount(el, tname);
}
}

for (Element currentForm : el.getChildren("currentForm")) {
Expand Down Expand Up @@ -298,10 +302,10 @@ public void checkAttachmentAndExtractedRecordCount(Element el, IBaseDataObject p
}

// check resource file
checkAttachmentAndExtractedRecordCount(resource, el, tname);
checkAttachmentAndExtractedRecordCount(el, tname);
}

public void checkAttachmentAndExtractedRecordCount(String resourceName, Element parent, String tname) {
public void checkAttachmentAndExtractedRecordCount(Element parent, String tname) {
// initialize attachment/extracted record counts to 0
int attExpectedCount = 0;
int attFoundCount = 0;
Expand All @@ -321,8 +325,8 @@ public void checkAttachmentAndExtractedRecordCount(String resourceName, Element
// expected counts of <numAttachments> & <extractCount>
// found counts of <att> and <extract>
List<Element> children = parent.getChildren();
for (int i = 0; i < children.size(); i++) {
String currentChild = children.get(i).toString();
for (Element child : children) {
String currentChild = child.toString();

if (currentChild.contains("numAttachments")) {
String attCountStr = parent.getChildTextTrim("numAttachments");
Expand Down Expand Up @@ -357,7 +361,7 @@ public void checkAttachmentAndExtractedRecordCount(String resourceName, Element
// make sure expected = found count
// formats fail string output
if (attExpectedCount != attFoundCount || extExpectedCount != extFoundCount || !missingNumAttachments || !missingExtCount) {
String failResult = "Errors in " + resourceName + ": ";
String failResult = "Errors in " + tname + ": ";
if (!missingNumAttachments) {
failResult += "<numAttachments> missing int between tags. ";
} else {
Expand Down
36 changes: 18 additions & 18 deletions src/test/java/emissary/test/core/TestExtractionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void testCheckStringValueForCollectionFailure() throws JDOMException, IOExceptio
}

@Test
public void testAttachmentAndExtractedRecordCountTest() throws JDOMException, IOException {
void testAttachmentAndExtractedRecordCountTest() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -68,11 +68,11 @@ public void testAttachmentAndExtractedRecordCountTest() throws JDOMException, IO
parent = root;
}

test.checkAttachmentAndExtractedRecordCount(resourceName, parent, "TestAttachmentAndExtractedRecordCountTest");
test.checkAttachmentAndExtractedRecordCount(parent, resourceName);
}

@Test
public void testAttachmentAndExtractedRecordCountFailure() throws JDOMException, IOException {
void testAttachmentAndExtractedRecordCountFailure() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -96,14 +96,14 @@ public void testAttachmentAndExtractedRecordCountFailure() throws JDOMException,

Element finalParent = parent;
assertThrows(AssertionError.class,
() -> test.checkAttachmentAndExtractedRecordCount(resourceName, finalParent, "TestAttachmentAndExtractedRecordCountFailure"));
() -> test.checkAttachmentAndExtractedRecordCount(finalParent, resourceName));

numAttChild.setText("1");
extCountChild.setText("1");
}

@Test
public void testNoAttachmentsOrExtractedRecords() throws JDOMException, IOException {
void testNoAttachmentsOrExtractedRecords() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand Down Expand Up @@ -133,7 +133,7 @@ public void testNoAttachmentsOrExtractedRecords() throws JDOMException, IOExcept
parent.removeChild("att1");
parent.removeChild("extract1");

test.checkAttachmentAndExtractedRecordCount(resourceName, parent, "TestNoAttachmentsAndExtractedRecords");
test.checkAttachmentAndExtractedRecordCount(parent, resourceName);

parent.addContent(indexNumAtt, numAttChild);
parent.addContent(indexExtCount, extCountChild);
Expand All @@ -142,7 +142,7 @@ public void testNoAttachmentsOrExtractedRecords() throws JDOMException, IOExcept
}

@Test
public void testNumAttachmentTagMissing() throws JDOMException, IOException {
void testNumAttachmentTagMissing() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -165,13 +165,13 @@ public void testNumAttachmentTagMissing() throws JDOMException, IOException {

Element finalParent = parent;
assertThrows(AssertionError.class,
() -> test.checkAttachmentAndExtractedRecordCount(resourceName, finalParent, "TestAttachmentAndExtractedRecordCountFailure"));
() -> test.checkAttachmentAndExtractedRecordCount(finalParent, resourceName));

parent.addContent(indexNumAtt, numAttChild);
}

@Test
public void testAttachmentNumNotDefined() throws JDOMException, IOException {
void testAttachmentNumNotDefined() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -193,13 +193,13 @@ public void testAttachmentNumNotDefined() throws JDOMException, IOException {

Element finalParent = parent;
assertThrows(AssertionError.class,
() -> test.checkAttachmentAndExtractedRecordCount(resourceName, finalParent, "TestAttachmentAndExtractedRecordCountFailure"));
() -> test.checkAttachmentAndExtractedRecordCount(finalParent, resourceName));

numAttChild.setText("1");
}

@Test
public void testAttCountFoundNotEqualExpected() throws JDOMException, IOException {
void testAttCountFoundNotEqualExpected() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -222,13 +222,13 @@ public void testAttCountFoundNotEqualExpected() throws JDOMException, IOExceptio

Element finalParent = parent;
assertThrows(AssertionError.class,
() -> test.checkAttachmentAndExtractedRecordCount(resourceName, finalParent, "TestAttachmentAndExtractedRecordCountFailure"));
() -> test.checkAttachmentAndExtractedRecordCount(finalParent, resourceName));

parent.addContent(indexAtt, att);
}

@Test
public void testExtractCountTagMissing() throws JDOMException, IOException {
void testExtractCountTagMissing() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -251,13 +251,13 @@ public void testExtractCountTagMissing() throws JDOMException, IOException {

Element finalParent = parent;
assertThrows(AssertionError.class,
() -> test.checkAttachmentAndExtractedRecordCount(resourceName, finalParent, "TestAttachmentAndExtractedRecordCountFailure"));
() -> test.checkAttachmentAndExtractedRecordCount(finalParent, resourceName));

parent.addContent(indexExtCount, extCountChild);
}

@Test
public void testExtractCountNotDefined() throws JDOMException, IOException {
void testExtractCountNotDefined() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -279,13 +279,13 @@ public void testExtractCountNotDefined() throws JDOMException, IOException {

Element finalParent = parent;
assertThrows(AssertionError.class,
() -> test.checkAttachmentAndExtractedRecordCount(resourceName, finalParent, "TestAttachmentAndExtractedRecordCountFailure"));
() -> test.checkAttachmentAndExtractedRecordCount(finalParent, resourceName));

extCountChild.setText("1");
}

@Test
public void testExtCountFoundNotEqualExpected() throws JDOMException, IOException {
void testExtCountFoundNotEqualExpected() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(org.jdom2.input.sax.XMLReaders.NONVALIDATING);
String resourceName = "/emissary/test/core/TestExtractionAttAndExtractCount.xml";
InputStream inputStream = TestExtractionTest.class.getResourceAsStream(resourceName);
Expand All @@ -308,7 +308,7 @@ public void testExtCountFoundNotEqualExpected() throws JDOMException, IOExceptio

Element finalParent = parent;
assertThrows(AssertionError.class,
() -> test.checkAttachmentAndExtractedRecordCount(resourceName, finalParent, "TestAttachmentAndExtractedRecordCountFailure"));
() -> test.checkAttachmentAndExtractedRecordCount(finalParent, resourceName));

parent.addContent(indexExt, ext);
}
Expand Down
Loading

0 comments on commit d0e5d9a

Please sign in to comment.