Chapter 9. PDFUnit for Non-Perl Systems

9.1.  A quick Look at PDFUnit-Java

The first implementation of PDFUnit was PDFUnit-Java. It is the reference for implementations in other programming languages. Whenever it is possible, the keywords in all implementations are chosen to be the same as in PDFUnit-Java.

The following examples shows that the API follows the Fluent Interface (http://de.wikipedia.org/wiki/Fluent_Interface):

@Test
public void hasTextOnFirstPageInPageRegion() throws Exception {
  String filename = "documentUnderTest.pdf";
  
  int leftX  =  50;
  int upperY = 130;
  int width  = 170;
  int height =  25; 
  PageRegion pageRegion = new PageRegion(leftX, upperY, width, height);
  
  AssertThat.document(filename)
            .restrictedTo(FIRST_OAGE)
            .restrictedTo(pageRegion)
            .hasText()
            .containing("Content on first page") 
  ;
}
@Test
public void compareFields() throws Exception {
  String filenameTest = "documentUnderTest.pdf";
  String filenameReference = "reference.pdf";
  
  AssertThat.document(filenameTest)
            .and(filenameReference)
            .haveSameFieldsByName()
            .haveSameFieldsByValue()
  ;
}
@Test
public void hasSignature() throws Exception {
  String filename = "documentUnderTest.pdf";
  Calendar signingDate = DateHelper.getCalendar("2007-10-14", "yyyy-MM-dd");
  
  AssertThat.document(filename)
            .hasSignatureField("sign_rbl")
            .signedBy("Raymond Berthou")
            .signedOn(signingDate)
  ;
}

A detailed documentation of PDFUnit-Java is available from http://www.pdfunit.com/en/documentation/java/index.html.