if (path == null)
{
logger.warn("This is an empty test");
return;
}
PreflightDocument document = null;
try
{
FileDataSource bds = new FileDataSource(path);
PreflightParser parser = new PreflightParser(bds);
parser.parse();
document = parser.getPreflightDocument();
document.validate();
ValidationResult result = document.getResult();
Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid());
Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0);
// could contain more than one error
boolean found = false;
if (this.expectedError != null)
{
for (ValidationError error : result.getErrorsList())
{
if (error.getErrorCode().equals(this.expectedError))
{
found = true;
if (outputResult == null)
{
break;
}
}
if (outputResult != null)
{
String log = path.getName().replace(".pdf", "") + "#" + error.getErrorCode() + "#"
+ error.getDetails() + "\n";
outputResult.write(log.getBytes());
}
}
}
if (result.getErrorsList().size() > 0)
{
if (this.expectedError == null)
{
logger.info("File invalid as expected (no expected code) :" + this.path.getAbsolutePath());
}
else if (!found)
{
StringBuilder message = new StringBuilder(100);
message.append(path).append(" : Invalid error code returned. Expected ");
message.append(this.expectedError).append(", found ");
for (ValidationError error : result.getErrorsList())
{
message.append(error.getErrorCode()).append(" ");
}
Assert.fail(message.toString());
}
}
else
{
Assert.assertEquals(path + " : Invalid error code returned.", this.expectedError, result
.getErrorsList().get(0).getErrorCode());
}
}
catch (ValidationException e)
{
throw new Exception(path + " :" + e.getMessage(), e);
}
finally
{
if (document != null)
{
document.close();
}
}
}