2022-11-01 15:18:53 +03:30
|
|
|
package com.baeldung.pdfinfo;
|
|
|
|
|
|
|
|
|
|
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
public class PdfInfoPdfBoxUnitTest {
|
|
|
|
|
|
|
|
|
|
private static final String PDF_FILE = "src/test/resources/input.pdf";
|
|
|
|
|
|
|
|
|
|
@Test
|
2022-11-09 11:55:20 +03:30
|
|
|
public void givenPdf_whenGetNumberOfPages_thenOK() throws IOException {
|
|
|
|
|
Assert.assertEquals(4, PdfInfoPdfBox.getNumberOfPages(PDF_FILE));
|
2022-11-01 15:18:53 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void givenPdf_whenIsPasswordRequired_thenOK() throws IOException {
|
2022-11-09 11:55:20 +03:30
|
|
|
Assert.assertEquals(false, PdfInfoPdfBox.isPasswordRequired(PDF_FILE));
|
2022-11-01 15:18:53 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void givenPdf_whenGetInfo_thenOK() throws IOException {
|
|
|
|
|
PDDocumentInformation info = PdfInfoPdfBox.getInfo(PDF_FILE);
|
2022-11-09 11:55:20 +03:30
|
|
|
Assert.assertEquals("LibreOffice 4.2", info.getProducer());
|
|
|
|
|
Assert.assertEquals("Writer", info.getCreator());
|
2022-11-01 15:18:53 +03:30
|
|
|
}
|
|
|
|
|
}
|