Skip to content

Commit

Permalink
Updated tests based on andrewbp review. Also cleaned up/corrected add…
Browse files Browse the repository at this point in the history
…ed log lines within ExtractionTest
  • Loading branch information
Sam Bishop committed Apr 22, 2022
1 parent 0332f79 commit 5d1c065
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
17 changes: 7 additions & 10 deletions src/main/java/emissary/test/core/ExtractionTest.java
Expand Up @@ -401,7 +401,7 @@ protected void validateFieldInFilter(String key, String tname) {
// check if EXTRA_PARAM = "*" is defined
// if yes, pass validation
if (currentLine.equals("EXTRA_PARAM = \"*\"")) {
logger.info("In " + filterName + ": EXTRA_PARAM = \"*\" validates \"" + key + "\".");
logger.debug("In {}: {} validated by EXTRA_PARAM = \"*\".", filterName, key);
reader.close();
isr.close();
is.close();
Expand All @@ -411,9 +411,7 @@ protected void validateFieldInFilter(String key, String tname) {
else if (currentLine.contains(blacklistField) || currentLine.contains(extraParam)
|| currentLine.contains(extraTldParam)) {
if (currentLine.contains(key)) {
logger.info(
"In " + filterName + ": Parameter \"" + key + "\" found. \"" + key
+ "\" is validated.");
logger.debug("In {}: {} is found and validated.", filterName, key);
reader.close();
isr.close();
is.close();
Expand All @@ -428,8 +426,7 @@ else if (currentLine.contains(extraPrefix) || currentLine.contains(extraTldPrefi
int preEnd = currentLine.length() - 1;
prefix = currentLine.substring(preStart, preEnd);
if (key.startsWith(prefix)) {
logger.info("In " + filterName + ": Parameter Prefix \"" + prefix + "\" found. \"" + key
+ "\" is validated.");
logger.debug("In {}: Parameter Prefix is found. {} validated", filterName, key);
reader.close();
isr.close();
is.close();
Expand All @@ -440,9 +437,9 @@ else if (currentLine.contains(extraPrefix) || currentLine.contains(extraTldPrefi
}
// meta name not validated by current filter, log this information
if ((i + 1) == filterList.size()) {
logger.info(key + " not found in " + filterName + ".");
logger.debug("{} not found in {}.", key, filterName);
} else {
logger.info(key + " not found in " + filterName + ". Moving to next file.");
logger.debug("{} not found in {}. Moving to next file.", key, filterName);
}
// close InputSteam, InputStreamReader, and BufferedReader
reader.close();
Expand All @@ -454,9 +451,9 @@ else if (currentLine.contains(extraPrefix) || currentLine.contains(extraTldPrefi
// however, if another error occured, it should be output to the log
if (!e.toString().contains("NullPointerException")) {
if ((i + 1) < filterList.size()) {
logger.warn("Error while validating " + key + ": " + e);
logger.warn("Error while validating {}", key, e);
} else {
logger.warn("Error while validating " + key + ": " + e + ". Moving to next file.");
logger.warn("Error while validating {}. Moving to next file.", key, e);
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/emissary/test/core/TestExtractionTest.java
Expand Up @@ -56,16 +56,11 @@ public void testCheckStringValueForCollectionFailure() throws JDOMException, IOE
public void testFindFilter() throws IOException {
WhyDoYouMakeMeDoThisExtractionTest test = new WhyDoYouMakeMeDoThisExtractionTest("nonsense");

boolean t1 = test.findFilter("emissary.output.filter.DataFilter");
boolean t2 = test.findFilter("emissary.output.filter.JsonOutputFilter");
boolean t3 = test.findFilter("this.should.not.be.found");
boolean t4 = test.findFilter("DataFilter");

// verify boolean "result" from findFilter() is returning correctly
Assert.assertTrue("DataFilter should be found.", t1);
Assert.assertTrue("JsonOutputFilter should be found.", t2);
Assert.assertFalse("This filter should not be found.", t3);
Assert.assertFalse("Should return false since path not provided.", t4);
Assert.assertTrue("DataFilter should be found.", test.findFilter("emissary.output.filter.DataFilter"));
Assert.assertTrue("JsonOutputFilter should be found.", test.findFilter("emissary.output.filter.JsonOutputFilter"));
Assert.assertFalse("This filter should not be found.", test.findFilter("this.should.not.be.found"));
Assert.assertFalse("Should return false since path not provided.", test.findFilter("DataFilter"));

// verify only found filters paths are added to filterList, should be 2 in this case
Assert.assertEquals("filterList<InputStream> should have size 2.", 2, test.filterList.size());
Expand Down

0 comments on commit 5d1c065

Please sign in to comment.