de.oio.jpdfunit
Class DocumentTester

java.lang.Object
  extended by de.oio.jpdfunit.DocumentTester
All Implemented Interfaces:
ContentAssertion, DocumentAssertion, FontAssertion, MetaDataAssertion

public class DocumentTester
extends Object
implements DocumentAssertion

The PdfTesterClass is a core element of JPdfUnit. This class implements the Assertion interfaces and has a Document and a Content for working with the pdf files. The different assert methods are implemented right here.

Author:
bbratkus

Constructor Summary
DocumentTester(InputStream fileStream)
          The Constructor uses a InputStream to get the document.
DocumentTester(String file)
          The constructor uses a String to get the document.
 
Method Summary
 void assertAllFontNamesInDocument(String[] expected)
          
 void assertAllFontNamesOnPage(String[] expected, int page)
          
 void assertAllFontTypesInDocument(String[] expected)
          
 void assertAllFontTypesOnPage(String[] expected, int page)
          
 void assertAuthorsNameEquals(String expected)
          The method compares the supposed authors name to the authors name of the pdf document.
 void assertBookmarkExists(String bookmarkName)
           
 void assertBookmarksAre(String[] bookmarks)
           
 void assertContentContainsText(String text, TextSearchType type)
          This assert method checks if the supposed parameters are contained in the document.
 void assertContentContainsTextMultipleTimes(String text, TextSearchType type)
          This assert method checks if the supposed parameters are contained in the document.
 void assertContentContainsTextOnPage(String text, int page, TextSearchType type)
          This assert method checks if the supposed parameters are contained in the document.
 void assertContentDoesNotContainText(String text, TextSearchType type)
          This assert method checks if the supposed parameters are not contained in the document.
 void assertContentDoesNotContainTextMultipleTimes(String text, TextSearchType type)
          This assert method checks if the supposed parameters are not contained in the document.
 void assertContentDoesNotContainTextOnPage(String text, int page, TextSearchType type)
          This assert method checks if the supposed parameters are not contained in the document.
 void assertCreationDateEquals(Calendar expected)
          The method comapares the supposed creation date to the creation date of the document.
 void assertCreatorEquals(String expected)
          The method compares the supposed creator to the creator of the document.
 void assertDecryptionWithOwnerPasswd(String expected)
          The method compares the supposed owner password with the owner password if it exists of the document and trys to decrypt the document.
 void assertDecryptionWithUserPasswd(String expected)
          The method compares the supposed user password with the user password if it exists of the document and trys to decrypt the document.
 void assertDocumentTitleEquals(String expected)
          The method comapares the supposed document title of the document informations with the document title of the document.
 void assertEncryptionLenghthEquals(int expected)
          The method compares the supposed encryption length with the encryption length of the document if it is encrypted else it returns 0.
 void assertFontNameInDocumentEquals(String expected)
          
 void assertFontNameOnPage(String expected, int page)
          
 void assertFontTypeInDocument(String expected)
          
 void assertFontTypeOnPage(String expected, int page)
          
 void assertIsDocumentEncrypted(boolean expected)
          The method checks if the current document is encrypted and comapares it to the parameter.
 void assertIsOwnerPasswd(String expected)
          Deprecated. 
 void assertIsUserPasswd(String expected)
          Deprecated. 
 void assertKeywordsEquals(String expected)
          The method compares the supposed keywords to the keywords of the document informations of the document.
 void assertNumberOfBookmarks(int numberOfBookmarks)
           
 void assertPageCountEquals(int expected)
          The method compares the supposed page number to the page number of the document.
 void assertSubjectEquals(String expected)
          The method compares the supposed subject to the subject of the document.
 void assertVersionEquals(float expected)
          The method compares the supposed version to the version of the document.
 void close()
          File handling you have to close the document after finishing your tests.
 Content getContent()
          The method returns the Content of the Document.
 Document getDocument()
          The method returns the Document of the DocumentTester.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentTester

public DocumentTester(String file)
The constructor uses a String to get the document.

Parameters:
file - The path and the file as String. I.e. "/home/bbratkus/test.pdf", a relative path.

DocumentTester

public DocumentTester(InputStream fileStream)
The Constructor uses a InputStream to get the document.

Parameters:
fileStream - The Stream which the pdf file is within.
Method Detail

assertAuthorsNameEquals

public void assertAuthorsNameEquals(String expected)
The method compares the supposed authors name to the authors name of the pdf document.

Specified by:
assertAuthorsNameEquals in interface MetaDataAssertion
Parameters:
expected - The expected authors name, the methods checks if the expected value equals the authors name of the pdf file.

assertContentContainsText

public void assertContentContainsText(String text,
                                      TextSearchType type)
This assert method checks if the supposed parameters are contained in the document. The method matches the first time the text was found in the document.

Specified by:
assertContentContainsText in interface ContentAssertion
Parameters:
text - The text to search within the document for. Even a regular expression is a valid parameter.
type - The TextSearchtype but remember that this is relative to the single pages of the document.

assertContentContainsTextOnPage

public void assertContentContainsTextOnPage(String text,
                                            int page,
                                            TextSearchType type)
This assert method checks if the supposed parameters are contained in the document. The method trys to match the text on a certain page in the document.

Specified by:
assertContentContainsTextOnPage in interface ContentAssertion
Parameters:
text - The text to search within the document for. Even a regular expression is a valid parameter.
page - The supposed page to search for the text. The page count is 1-based.
type - The TextSearchtype but remember that this is relative to the single pages of the document.

assertContentContainsTextMultipleTimes

public void assertContentContainsTextMultipleTimes(String text,
                                                   TextSearchType type)
This assert method checks if the supposed parameters are contained in the document. The method trys to match all the time the text was found in the document.

Specified by:
assertContentContainsTextMultipleTimes in interface ContentAssertion
Parameters:
text - The text to search within the document for. Even a regular expression is a valid parameter.
type - The TextSearchtype but remember that this is relative to the single pages of the document.

assertContentDoesNotContainText

public void assertContentDoesNotContainText(String text,
                                            TextSearchType type)
This assert method checks if the supposed parameters are not contained in the document. The method matches the first time the text was found in the document.

Specified by:
assertContentDoesNotContainText in interface ContentAssertion
Parameters:
text - The text to search within the document for. Even a regular expression is a valid parameter.
type - The TextSearchtype but remember that this is relative to the single pages of the document.

assertContentDoesNotContainTextOnPage

public void assertContentDoesNotContainTextOnPage(String text,
                                                  int page,
                                                  TextSearchType type)
This assert method checks if the supposed parameters are not contained in the document. The method trys to match the text on a certain page in the document.

Specified by:
assertContentDoesNotContainTextOnPage in interface ContentAssertion
Parameters:
text - The text to search within the document for. Even a regular expression is a valid parameter.
page - The supposed page to search for the text. The page count is 1-based.
type - The TextSearchtype but remember that this is relative to the single pages of the document.

assertContentDoesNotContainTextMultipleTimes

public void assertContentDoesNotContainTextMultipleTimes(String text,
                                                         TextSearchType type)
This assert method checks if the supposed parameters are not contained in the document. The method trys to match all the time the text was found in the document.

Specified by:
assertContentDoesNotContainTextMultipleTimes in interface ContentAssertion
Parameters:
text - The text to search within the document for. Even a regular expression is a valid parameter.
type - The TextSearchtype but remember that this is relative to the single pages of the document.

assertCreatorEquals

public void assertCreatorEquals(String expected)
The method compares the supposed creator to the creator of the document.

Specified by:
assertCreatorEquals in interface MetaDataAssertion
Parameters:
expected - The supposed creator of the document.

assertCreationDateEquals

public void assertCreationDateEquals(Calendar expected)
The method comapares the supposed creation date to the creation date of the document.

Specified by:
assertCreationDateEquals in interface MetaDataAssertion
Parameters:
expected - The expected creation date of the document. It will be compared to the creation date of the document.

assertDecryptionWithOwnerPasswd

public void assertDecryptionWithOwnerPasswd(String expected)
The method compares the supposed owner password with the owner password if it exists of the document and trys to decrypt the document.

Specified by:
assertDecryptionWithOwnerPasswd in interface MetaDataAssertion
Parameters:
expected - The supposed owner password. This method tries to decrypt the pdf file with this password.

assertDecryptionWithUserPasswd

public void assertDecryptionWithUserPasswd(String expected)
The method compares the supposed user password with the user password if it exists of the document and trys to decrypt the document.

Specified by:
assertDecryptionWithUserPasswd in interface MetaDataAssertion
Parameters:
expected - The supposed user password. This method tries to decrypt the pdf file with this password.

assertDocumentTitleEquals

public void assertDocumentTitleEquals(String expected)
The method comapares the supposed document title of the document informations with the document title of the document.

Specified by:
assertDocumentTitleEquals in interface MetaDataAssertion
Parameters:
expected - The expected document title, the methods checks if the expected value equals the document title of the pdf file.

assertEncryptionLenghthEquals

public void assertEncryptionLenghthEquals(int expected)
The method compares the supposed encryption length with the encryption length of the document if it is encrypted else it returns 0.

Specified by:
assertEncryptionLenghthEquals in interface MetaDataAssertion
Parameters:
expected - The expected encryption length, the method checks if the expected value equals the encryption length of the pdf file.

assertKeywordsEquals

public void assertKeywordsEquals(String expected)
The method compares the supposed keywords to the keywords of the document informations of the document.

Specified by:
assertKeywordsEquals in interface MetaDataAssertion
Parameters:
expected - The expected keywords, the method checks if the expected keywords equals the keywords of the pdf file.

assertPageCountEquals

public void assertPageCountEquals(int expected)
The method compares the supposed page number to the page number of the document.

Specified by:
assertPageCountEquals in interface MetaDataAssertion
Parameters:
expected - The expected page count. The method checks if the expected page count equals the page count of the pdf file. The page count is 1-based.

assertSubjectEquals

public void assertSubjectEquals(String expected)
The method compares the supposed subject to the subject of the document.

Specified by:
assertSubjectEquals in interface MetaDataAssertion
Parameters:
expected - The expected subject, the method checks if the expected subject equals the subject of the pdf file.

assertIsDocumentEncrypted

public void assertIsDocumentEncrypted(boolean expected)
The method checks if the current document is encrypted and comapares it to the parameter.

Specified by:
assertIsDocumentEncrypted in interface MetaDataAssertion
Parameters:
expected - Expected has to be set to "true" if you suppose that the document is encrypted.

assertIsOwnerPasswd

@Deprecated
public void assertIsOwnerPasswd(String expected)
Deprecated. 

The method compares the supposed owner password with the owner password if it exists of the document.

Specified by:
assertIsOwnerPasswd in interface MetaDataAssertion
Parameters:
expected - The expected owner password. The method compares the expected owner password to the owner password of the pdf file. This is necessary for changing the document attributes.

assertIsUserPasswd

@Deprecated
public void assertIsUserPasswd(String expected)
Deprecated. 

The method compares the supposed user password with the user password if it exists of the document.

Specified by:
assertIsUserPasswd in interface MetaDataAssertion
Parameters:
expected - The expected user password. The method compares the expected user password to the user password of the pdf file. This is necessary for reading the pdf file.

assertVersionEquals

public void assertVersionEquals(float expected)
The method compares the supposed version to the version of the document.

Specified by:
assertVersionEquals in interface MetaDataAssertion
Parameters:
expected - The expected version of the pdf file. The method checks if the expected version equals the version of the pdf file.

close

public void close()
File handling you have to close the document after finishing your tests.


getContent

public Content getContent()
The method returns the Content of the Document.

Returns:
Returns the content.

getDocument

public Document getDocument()
The method returns the Document of the DocumentTester.

Returns:
Returns the document.

assertFontNameInDocumentEquals

public void assertFontNameInDocumentEquals(String expected)

Specified by:
assertFontNameInDocumentEquals in interface FontAssertion
Parameters:
expected - A expected font name like "Verdana-BoldItalic".

assertAllFontNamesInDocument

public void assertAllFontNamesInDocument(String[] expected)

Specified by:
assertAllFontNamesInDocument in interface FontAssertion
Parameters:
expected - Expected font names like "Verdana-BoldItalic".

assertFontNameOnPage

public void assertFontNameOnPage(String expected,
                                 int page)

Specified by:
assertFontNameOnPage in interface FontAssertion
Parameters:
expected - A expected font name like "Verdana-BoldItalic".
page - The supposed page number, notice it is 1-based.

assertAllFontNamesOnPage

public void assertAllFontNamesOnPage(String[] expected,
                                     int page)

Specified by:
assertAllFontNamesOnPage in interface FontAssertion
Parameters:
expected - Expected font names like "Verdana-BoldItalic".
page - The supposed page number, notice it is 1-based.

assertFontTypeInDocument

public void assertFontTypeInDocument(String expected)

Specified by:
assertFontTypeInDocument in interface FontAssertion
Parameters:
expected - A supposed font type, i.e. "TrueType" or "Type1".

assertAllFontTypesInDocument

public void assertAllFontTypesInDocument(String[] expected)

Specified by:
assertAllFontTypesInDocument in interface FontAssertion
Parameters:
expected - All supposed font types in the document. Be carefull and list all of them. A supposed font type is i.e. "TrueType" or "Type1".

assertFontTypeOnPage

public void assertFontTypeOnPage(String expected,
                                 int page)

Specified by:
assertFontTypeOnPage in interface FontAssertion
Parameters:
expected - A supposed font type, i.e "TrueType" or "Type1".
page - The supposed page to search for the font type.

assertAllFontTypesOnPage

public void assertAllFontTypesOnPage(String[] expected,
                                     int page)

Specified by:
assertAllFontTypesOnPage in interface FontAssertion
Parameters:
expected - All supposed font types in the document. Be carefull and list all of them. A supposed font type is i.e. "TrueType" or "Type1".
page - The supposed page to search for the font types.

assertNumberOfBookmarks

public void assertNumberOfBookmarks(int numberOfBookmarks)

assertBookmarkExists

public void assertBookmarkExists(String bookmarkName)

assertBookmarksAre

public void assertBookmarksAre(String[] bookmarks)


Copyright © 2011. All Rights Reserved.