Class TaskTestContext

java.lang.Object
org.sejda.tests.tasks.TaskTestContext
All Implemented Interfaces:
Closeable, AutoCloseable

public class TaskTestContext extends Object implements Closeable
Context to be used in tests
Author:
Andrea Vacondio
  • Constructor Details

    • TaskTestContext

      public TaskTestContext()
  • Method Details

    • pdfOutputTo

      public TaskTestContext pdfOutputTo(SingleOutputTaskParameters params) throws IOException
      Initialize the given params with a FileTaskOutput
      Parameters:
      params -
      Returns:
      Throws:
      IOException
    • fileOutputTo

      public TaskTestContext fileOutputTo(SingleOutputTaskParameters params, String extension) throws IOException
      Initialize the given params with a FileTaskOutput on a file with the given extension
      Parameters:
      params -
      extension -
      Returns:
      Throws:
      IOException
    • directoryOutputTo

      public TaskTestContext directoryOutputTo(MultipleOutputTaskParameters params) throws IOException
      Initialize the given params with a DirectoryTaskOutput
      Parameters:
      params -
      Returns:
      Throws:
      IOException
    • directoryOutputTo

      public TaskTestContext directoryOutputTo(SingleOrMultipleOutputTaskParameters params) throws IOException
      Initialize the given params with a directory as FileOrDirectoryTaskOutput
      Parameters:
      params -
      Returns:
      Throws:
      IOException
    • pdfOutputTo

      Initialize the given params with a pdf file as FileOrDirectoryTaskOutput
      Parameters:
      params -
      Returns:
      Throws:
      IOException
    • assertCreator

      public TaskTestContext assertCreator()
      asserts the creator has been set to the info dictionary
      Returns:
    • assertVersion

      public TaskTestContext assertVersion(PdfVersion version)
      asserts the PDF version of the output is the given one
      Returns:
    • assertPages

      public TaskTestContext assertPages(int expected)
      asserts the output document has that number of pages
      Returns:
    • assertPages

      public TaskTestContext assertPages(String filename, int expected) throws IOException
      asserts the output document with the given filename exists and has that number of pages. This assert will work only for multiple output task.
      Returns:
      Throws:
      IOException
    • assertHasOutline

      public TaskTestContext assertHasOutline(boolean hasOutline)
      Parameters:
      hasOutline -
    • assertHasAcroforms

      public TaskTestContext assertHasAcroforms(boolean hasForms)
      assert that the document has an acroform with some field in it
      Parameters:
      hasForms -
    • assertOutlineContains

      public TaskTestContext assertOutlineContains(String title)
      assert the document outline contains an item with the given title
      Parameters:
      title -
      Returns:
    • assertOutlineDoesntContain

      public TaskTestContext assertOutlineDoesntContain(String title)
      assert the document outline doesn't contain an item with the given title
      Parameters:
      title -
      Returns:
    • assertOutputSize

      public TaskTestContext assertOutputSize(int size) throws IOException
      asserts that a multiple output task has generated the given number of output files, hidden files don't count
      Returns:
      Throws:
      IOException
    • assertOutputSizeIncludingHidden

      public TaskTestContext assertOutputSizeIncludingHidden(int size)
      asserts that a multiple output task has generated the given number of output files, including hidden files (in case the task is expected to have some hidden leftover)
      Parameters:
      size -
      Returns:
    • assertEmptyMultipleOutput

      public TaskTestContext assertEmptyMultipleOutput()
      asserts that a multiple output task has generated no output
      Returns:
    • assertOutputContainsFilenames

      public TaskTestContext assertOutputContainsFilenames(String... filenames)
      asserts that a multiple output task has generated the given file names
      Parameters:
      filenames -
      Returns:
    • forEachPdfOutput

      public TaskTestContext forEachPdfOutput(Consumer<org.sejda.sambox.pdmodel.PDDocument> consumer) throws IOException
      Applies the given consumer to every generated output
      Parameters:
      consumer -
      Returns:
      Throws:
      IOException
    • forPdfOutput

      public TaskTestContext forPdfOutput(Consumer<org.sejda.sambox.pdmodel.PDDocument> consumer)
      Applies the given consumer to generated single output PDF document
      Parameters:
      consumer -
      Returns:
      Throws:
      IOException
    • forPdfOutput

      public TaskTestContext forPdfOutput(String filename, Consumer<org.sejda.sambox.pdmodel.PDDocument> consumer) throws IOException
      Applies the given consumer to generated output PDF document with the given name
      Parameters:
      consumer -
      Returns:
      Throws:
      IOException
    • forEachRawOutput

      public TaskTestContext forEachRawOutput(Consumer<Path> consumer) throws IOException
      Applies the given consumer to every generated output
      Parameters:
      consumer -
      Returns:
      Throws:
      IOException
    • forRawOutput

      public TaskTestContext forRawOutput(Consumer<Path> consumer)
      Applies the given consumer to a single generated output
      Parameters:
      consumer -
      Returns:
      Throws:
      IOException
    • forRawOutput

      public TaskTestContext forRawOutput(String filename, Consumer<Path> consumer)
    • assertTaskCompleted

      public org.sejda.sambox.pdmodel.PDDocument assertTaskCompleted() throws IOException
      Asserts that the task has completed and generated some output. If a single output task, then the output is paresed and a PDDocument is returned
      Returns:
      Throws:
      IOException
    • assertTaskCompleted

      public org.sejda.sambox.pdmodel.PDDocument assertTaskCompleted(String password) throws IOException
      Asserts that the task has completed and generated some output. If the task generated a single output, then the output is parsed and a PDDocument is returned
      Parameters:
      password -
      Returns:
      Throws:
      IOException
    • getTaskWarnings

      public List<String> getTaskWarnings()
    • listenForTaskFailure

      public void listenForTaskFailure()
    • listenForTaskStart

      public void listenForTaskStart()
    • assertTaskFailed

      public TaskTestContext assertTaskFailed(String message)
    • assertTaskFailed

      public TaskTestContext assertTaskFailed(Class<? extends Throwable> cause)
    • assertTaskFailed

      public TaskTestContext assertTaskFailed()
    • assertFailedSource

      public TaskTestContext assertFailedSource(String source)
    • assertTaskStarted

      public TaskTestContext assertTaskStarted()
    • assertTaskDidNotFail

      public TaskTestContext assertTaskDidNotFail()
    • expectTaskWillProduceWarnings

      @Deprecated public void expectTaskWillProduceWarnings()
      Deprecated.
    • listenForTaskWarnings

      public void listenForTaskWarnings()
    • assertTaskWarning

      public TaskTestContext assertTaskWarning(String message)
    • assertTaskWarnings

      public TaskTestContext assertTaskWarnings(List<String> messages)
    • assertNoTaskWarnings

      public TaskTestContext assertNoTaskWarnings()
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getFileOutput

      public File getFileOutput()
    • assertSimilar

      public void assertSimilar(String filename, String resourcePath) throws IOException
      Throws:
      IOException
    • assertSimilar

      public void assertSimilar(String resourcePath)
    • assertSimilar

      public void assertSimilar(String resourcePath, double similarityThreshold)
    • assertSimilar

      public void assertSimilar(String filename, String resourcePath, double similarityThreshold) throws IOException
      Throws:
      IOException
    • debug

      public void debug(String filename)
    • debugTo

      public void debugTo(String destPath)