| 1 |
package org.sejda.impl.sambox; |
| 2 |
|
| 3 |
import org.junit.Test; |
| 4 |
import org.sejda.core.service.BaseTaskTest; |
| 5 |
import org.sejda.impl.sambox.component.DefaultPdfSourceOpener; |
| 6 |
import org.sejda.impl.sambox.component.PDDocumentHandler; |
| 7 |
import org.sejda.model.exception.TaskIOException; |
| 8 |
import org.sejda.model.input.FileSource; |
| 9 |
import org.sejda.model.input.PdfFileSource; |
| 10 |
import org.sejda.model.input.PdfStreamSource; |
| 11 |
import org.sejda.model.input.StreamSource; |
| 12 |
import org.sejda.model.parameter.MergeParameters; |
| 13 |
import org.sejda.model.task.Task; |
| 14 |
|
| 15 |
import javax.imageio.ImageIO; |
| 16 |
import java.awt.image.BufferedImage; |
| 17 |
import java.io.IOException; |
| 18 |
|
| 19 |
import static org.junit.Assert.assertEquals; |
| 20 |
import static org.sejda.TestUtils.encryptedAtRest; |
| 21 |
|
| 22 |
public class EncryptionAtRestSourceTest extends BaseTaskTest<MergeParameters> { |
| 23 |
|
| 24 |
@Test |
| 25 |
public void pdfFileSource() throws IOException, TaskIOException { |
| 26 |
PdfFileSource encrypted = encryptedAtRest(customInputAsFileSource("pdf/test-pdf.pdf")); |
| 27 |
PDDocumentHandler doc = new DefaultPdfSourceOpener().open(encrypted); |
| 28 |
assertEquals(doc.getNumberOfPages(), 11); |
| 29 |
} |
| 30 |
|
| 31 |
@Test |
| 32 |
public void pdfStreamSource() throws IOException, TaskIOException { |
| 33 |
PdfStreamSource encrypted = encryptedAtRest(customInput("pdf/test-pdf.pdf")); |
| 34 |
PDDocumentHandler doc = new DefaultPdfSourceOpener().open(encrypted); |
| 35 |
assertEquals(doc.getNumberOfPages(), 11); |
| 36 |
} |
| 37 |
|
| 38 |
@Test |
| 39 |
public void streamSource() throws IOException { |
| 40 |
StreamSource encrypted = encryptedAtRest(customNonPdfInput("image/large.jpg")); |
| 41 |
|
| 42 |
BufferedImage image = ImageIO.read(encrypted.getSeekableSource().asNewInputStream()); |
| 43 |
assertEquals(image.getWidth(), 5760); |
| 44 |
} |
| 45 |
|
| 46 |
@Test |
| 47 |
public void fileSource() throws IOException { |
| 48 |
FileSource encrypted = encryptedAtRest(customNonPdfInputAsFileSource("image/large.jpg")); |
| 49 |
|
| 50 |
BufferedImage image = ImageIO.read(encrypted.getSeekableSource().asNewInputStream()); |
| 51 |
assertEquals(image.getWidth(), 5760); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public Task<MergeParameters> getTask() { |
| 56 |
return null; |
| 57 |
} |
| 58 |
} |