SourceForge.net Logo

JUnit

PDFBox

Orientation in Objects

framework


For a better understanding of JPdfUnit there are some architectural diagramms.

   back
1. the core framework
2. PDFBox Integration
3. big picture
4. usage scenarios
4.1. MyTest extends PdfTestCase
4.2. MyTest uses the PdfTester
4.3. Working with the DocumentTester

core framework

an abstraction for a possible reuse in other contexts


The first one is a core class diagramm. The DocumentTester class is the central class of the core framework. This class implements the Assertion interfaces and holds Document and Content. The Document interface provides the possibilities to get generell information about the document like number of pages or the author. The Content interface allows to search the document for specific text. This can be realized via simple text Strings or even via regular expressions. These two objects are created via the DocumentFactory. The DocumentTestCase class works with a DocumentTester an provides the user simple assert methods. The Assertion interfaces are separated in assertions concerning the Document (MetaDataAssertion) and the Content (ContentAssertion) which allows the user to search the document for specific text. This can be realized via simple text Strings or even via regular expressions.
top

JPdfUnit core architecture

picture 1 : the core framework

PDFBox Integration

the framework and pdfbox - connected with an adapter


As pdf library PDFBox is used as an api for pdf document access in this testing framework. For a possible exchange of this we used an adapter. The core of the adapter represents the PdfBoxAnalyser class. This class extends the PDFTextStripper class of the PDFBox and works with the PDDocument and the PDDocumentInformation classes of the PDFBox too for a maximum of information about the pdf document. The gained informations and functionality are provided to the user via two interfaces Document and Content which are implemented by the PdfBoxDocumentAdapter and the PdfBoxContentAdapter and so thematically seperated.
top

JPdfUnit core architecture

picture 2 : the framework and pdfbox

Big picture

put it together now and there is still more to find out - framework overview


Finally there is a complete framework overview. Some more classes are added even the Enum and Exceptions which could be thrown at runtime. The DocumentFactoryException can be thrown at runtime while instanciating a new Factory. The DocumentDataSource and the PdfDataSource are responsible for the correct sources for working with the DocumentTestCase class. The TextSearcher its subclasses and the TextSearchType working for the DocumentTester. They are used in the different assert methods to define the kind of searching the text within the document.
top

JPdfUnit core architecture

picture 3 : framework overview

usage scenarios



1. extend the DocumentTestCase class

OIOTest extends DocumentTestCase


The easiest way to use jpdfunit is to make your test class extend the DocumentTestCase class. Now you need to create a test class like OIOTest. DocumentTestCase extends the JUnit TestCase class and does setUp and tearDown for you. There is just one method which has to be implemented the getDataSource().

top

JPdfUnit core architecture

picture 4 : extend the testcase
sequence digaramm 1

2. use the DocumentTester

MyTest uses the DocumentTester and does not extend the DocumentTestCase class


The other possibility to work with the DocumentTester class. This class is the core of the framework and offers the user the hole functionality. The best practice is to override the standard JUnit setUp() method and creating there a DocumentTester with your pdf as parameter for the constructor. After this inital step execute the desired operation on your pdf file. Do not forget to close the document of your DocumentTester in the teardown() method.

top

JPdfUnit core architecture

picture 5 : do not extend the testcase
sequence diagramm 2

3. working with the DocumentTester in a application

MyClass uses the DocumentTester without the JUnit testing framework


Here is another idea to generate possible value of JPdfUnit. You can use the DocumentTester indepentent to JUnit. So you can get all the Informations as to content and the document via the interfaces Document and Content with your DocumentTester. Of course you can not use the assert methods of the DocumentTester because they need the JUnit framework. So only use the functionallities which are provided by the Document and Content interfaces.

top

JPdfUnit core architecture

picture 6 : working with the DocumentTester

Valid XHTML 1.0! Valid CSS! Desidned by CSS!