use of com.testautomationguru.utility.PDFUtil in project iaf by ibissource.
the class PdfPipeTest method expectSuccessfullConversion.
public void expectSuccessfullConversion(String pipeName, String fileToConvert, String metadataXml, String expectedFile) throws Exception {
String documentMetadata = executeConversion(pipeName, fileToConvert);
String expected = TestFileUtils.getTestFile(metadataXml);
MatchUtils.assertXmlEquals("Conversion XML does not match", applyIgnores(expected), applyIgnores(documentMetadata), true);
// Get document for path
Pattern convertedDocumentPattern = Pattern.compile(REGEX_PATH_IGNORE);
Matcher convertedDocumentMatcher = convertedDocumentPattern.matcher(documentMetadata);
if (convertedDocumentMatcher.find()) {
// Find converted document location
String convertedFilePath = convertedDocumentMatcher.group();
System.out.println("found converted file [" + convertedFilePath + "]");
URL expectedFileUrl = TestFileUtils.getTestFileURL(expectedFile);
assertNotNull("cannot find expected file [" + expectedFile + "]", expectedFileUrl);
File file = new File(expectedFileUrl.toURI());
String expectedFilePath = file.getPath();
System.out.println("converted relative path [" + expectedFile + "] to absolute file [" + expectedFilePath + "]");
PDFUtil pdfUtil = new PDFUtil();
// remove Aspose evaluation copy information
pdfUtil.excludeText("(Created with an evaluation copy of Aspose.([a-zA-Z]+). To discover the full versions of our APIs please visit: https:\\/\\/products.aspose.com\\/([a-zA-Z]+)\\/)");
// pdfUtil.enableLog();
boolean compare = pdfUtil.compare(convertedFilePath, file.getPath());
assertTrue("pdf files [" + convertedFilePath + "] and [" + expectedFilePath + "] should match", compare);
} else {
fail("failed to extract converted file from documentMetadata xml");
}
}
use of com.testautomationguru.utility.PDFUtil in project iaf by ibissource.
the class PdfPipeTest method attachFileToMainDoc.
@Test
public void attachFileToMainDoc() throws Exception {
pipe.setAction(DocumentAction.COMBINE);
pipe.setMainDocumentSessionKey("mainDoc");
pipe.setFilenameToAttachSessionKey("attachedFilename");
Message mainDoc = TestFileUtils.getNonRepeatableTestFileMessage("/PdfPipe/combine/maindoc.pdf");
session.put(pipe.getMainDocumentSessionKey(), mainDoc);
session.put(pipe.getFilenameToAttachSessionKey(), "attachedFile");
Message fileToAttachMainDoc = TestFileUtils.getNonRepeatableTestFileMessage("/PdfPipe/combine/filetobeattached.pdf");
PipeRunResult prr = doPipe(pipe, fileToAttachMainDoc, session);
Message result = prr.getResult();
Path resultingFile = Files.createTempFile("PdfPipeTest", ".pdf");
Files.copy(result.asInputStream(), resultingFile, StandardCopyOption.REPLACE_EXISTING);
String expectedFilePath = new File(TestFileUtils.getTestFileURL("/PdfPipe/combine/combined.pdf").toURI()).getCanonicalPath();
// comparison
PDFUtil pdfUtil = new PDFUtil();
assertTrue(pdfUtil.compare(expectedFilePath, resultingFile.toFile().getCanonicalPath()));
}
Aggregations