use of org.apache.pdfbox.preflight.ValidationResult in project pdfbox by apache.
the class TestValidFiles method validate.
@Test()
public void validate() throws Exception {
if (path == null) {
logger.warn("This is an empty test");
return;
}
PreflightDocument document = null;
try {
PreflightParser parser = new PreflightParser(path);
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
if (result.getErrorsList().size() > 0) {
Assert.fail("File expected valid : " + path.getAbsolutePath());
}
} catch (ValidationException e) {
throw new Exception(path + " :" + e.getMessage(), e);
} finally {
if (document != null) {
document.close();
}
}
}
use of org.apache.pdfbox.preflight.ValidationResult in project pdfbox by apache.
the class TestMetadataFiles method checkPDF.
private boolean checkPDF(File pdf) {
PreflightDocument document = null;
boolean testResult = false;
if (pdf.exists()) {
ValidationResult result = null;
try {
PreflightParser parser = new PreflightParser(pdf);
parser.parse();
document = (PreflightDocument) parser.getPDDocument();
document.validate();
result = document.getResult();
} catch (SyntaxValidationException e) {
result = e.getResult();
} catch (IOException e) {
fail("An exception occured while parsing the PDF " + pdf + ": " + e);
}
if (result != null) {
testResult = result.isValid();
}
if (document != null) {
try {
document.close();
} catch (IOException e) {
// shouldn't happen;
}
}
} else {
fail("Can't find the given file " + pdf);
}
return testResult;
}
use of org.apache.pdfbox.preflight.ValidationResult in project pdfbox by apache.
the class TestXmlResultParser method testSameErrorTwice.
@Test
public void testSameErrorTwice() throws Exception {
ValidationResult result = new ValidationResult(false);
result.addError(new ValidationResult.ValidationError(ERROR_CODE));
result.addError(new ValidationResult.ValidationError(ERROR_CODE));
parser.createResponseWithError(document, "pdftype", result, preflight);
Assert.assertNotNull(xpath.evaluate("errors[@count='2']", preflight, XPathConstants.NODE));
Assert.assertNotNull(xpath.evaluate("errors/error[@count='2']", preflight, XPathConstants.NODE));
Element code = (Element) xpath.evaluate("errors/error[@count='2']/code", preflight, XPathConstants.NODE);
Assert.assertNotNull(code);
Assert.assertEquals(ERROR_CODE, code.getTextContent());
}
use of org.apache.pdfbox.preflight.ValidationResult in project pdfbox by apache.
the class TestXmlResultParser method testSameCodeWithDifferentMessages.
@Test
public void testSameCodeWithDifferentMessages() throws Exception {
ValidationResult result = new ValidationResult(false);
result.addError(new ValidationResult.ValidationError(ERROR_CODE, "message 1"));
result.addError(new ValidationResult.ValidationError(ERROR_CODE, "message 2"));
parser.createResponseWithError(document, "pdftype", result, preflight);
Assert.assertNotNull(xpath.evaluate("errors[@count='2']", preflight, XPathConstants.NODE));
NodeList nl = (NodeList) xpath.evaluate("errors/error[@count='1']", preflight, XPathConstants.NODESET);
Assert.assertEquals(2, nl.getLength());
}
use of org.apache.pdfbox.preflight.ValidationResult in project pdfbox by apache.
the class TestXmlResultParser method testTwoError.
@Test
public void testTwoError() throws Exception {
ValidationResult result = new ValidationResult(false);
result.addError(new ValidationResult.ValidationError("7"));
result.addError(new ValidationResult.ValidationError(ERROR_CODE));
parser.createResponseWithError(document, "pdftype", result, preflight);
Assert.assertNotNull(xpath.evaluate("errors[@count='2']", preflight, XPathConstants.NODE));
NodeList nl = (NodeList) xpath.evaluate("errors/error[@count='1']", preflight, XPathConstants.NODESET);
Assert.assertEquals(2, nl.getLength());
}
Aggregations