NAME

PDF::PDFUnit - Perl interface to the Java PDFUnit testing framework

IMPORTANT

This Module is not useable on its own!

It it "just" a Perl wrapper around Carsten Siedentop's awesome PDFUnit (a PDF testing framework written in Java).

SYNOPSIS

use PDF::PDFUnit;

AssertThat
    ->document("test.pdf")
    ->hasNumberOfPages(1)
     ;

...or (more typical):

use Test::More;
use Test::Exception;
use PDF::PDFUnit;

lives_ok {
    AssertThat
        ->document("test.pdf")
        ->hasNumberOfPages(1)
        ;
} "Document has one page";

...or (nearly everything is possible):

use Test::More;
use Test::Exception;
use PDF::PDFUnit;

lives_ok {
    my $leftX  =   0;
    my $upperY =  30;
    my $width  = 210;
    my $height = 235;

    my $textBody = PageRegion->new($leftX, $upperY, $width, $height);

    AssertThat
        ->document("test.pl")
        ->restrictedTo(LAST_PAGE)
        ->restrictedTo($textBody)
        ->hasNoImage()
        ->hasNoText()
        ;
} "Last page body should be empty";

DESCRIPTION

As mentioned above, PDF::PDFUnit is just a wrapper. Therefore, we won't repeat the excellent documentation you can find at http://pdfunit.com/en/documentation/java/.

Ok, it's Java, but if you find an example like

@Test
public void hasOnePage_en() throws Exception {
  String filename = "test.pdf";

  AssertThat.document(filename)
            .hasNumberOfPages(1)
  ;
}

it should not be too hard to translate it into the real language:

lives_ok {
    my $filename = "test.pdf";

    AssertThat
        ->document($filename)
        ->hasNumberOfPages(1)
        ;
} "Document has one page";

Every method call behind AssertThat is essentially one test. But typically you will use the very convenient fluent interface.

TESTING

The Java people throw exceptions when their tests fail. Like it or not, PDF::PDFUnit does the same for technical reasons.

Occasionally you want to peek into the thrown PDFUnitValidationException object, because it should contain a helpful message.

Under Test::More, you could do something like

diag $@->getMessage() if $@;

Just use print or say otherwise.

IMPORT TAGS

PDF::PDFUnit knows two import tags. Both of them are not intended for public use:

    :skip_on_error

    This is intended for the distribution tests: If something fails during initialization, then all tests will be skipped. (Trivial case: No configuration file available.)

    :noinit

    Use this if you want to start the initialization process later. At some point you could then call

    PDF::PDFUnit->init();

    or even instead

    PDF::PDFUnit->load_config();
    PDF::PDFUnit->build_classpath();
    PDF::PDFUnit->attach_java();

    pdfunit-perl.pl uses this. You will probably never need it.

AUTHOR

Axel Miesen <miesen@quadraginta-duo.de>

THANKS TO

Carsten Siedentop <info@pdfunit.com> for writing PDFUnit-Java

SEE ALSO

Inline::Java, PDFUnit