Search in sources :

Example 1 with PDFUtil

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");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PDFUtil(com.testautomationguru.utility.PDFUtil) File(java.io.File) URL(java.net.URL)

Example 2 with PDFUtil

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()));
}
Also used : Path(java.nio.file.Path) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) PDFUtil(com.testautomationguru.utility.PDFUtil) File(java.io.File) Test(org.junit.Test)

Aggregations

PDFUtil (com.testautomationguru.utility.PDFUtil)2 File (java.io.File)2 URL (java.net.URL)1 Path (java.nio.file.Path)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 Message (nl.nn.adapterframework.stream.Message)1 Test (org.junit.Test)1