Skip to content

Commit 7bc7ea8

Browse files
committed
chore: metadata test for openpdf module
1 parent 2284939 commit 7bc7ea8

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

fj-doc-mod-openpdf-ext/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
<scope>test</scope>
5959
</dependency>
6060

61+
<dependency>
62+
<groupId>org.apache.pdfbox</groupId>
63+
<artifactId>pdfbox</artifactId>
64+
<version>${pdfbox-test-version}</version>
65+
<scope>test</scope>
66+
</dependency>
67+
6168
</dependencies>
6269

6370
<profiles>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package test.org.fugerit.java.doc.mod.openpdf.ext;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.pdfbox.pdmodel.PDDocument;
5+
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
6+
import org.fugerit.java.core.lang.helpers.ClassHelper;
7+
import org.fugerit.java.doc.base.config.DocInput;
8+
import org.fugerit.java.doc.base.config.DocOutput;
9+
import org.fugerit.java.doc.base.config.DocTypeHandler;
10+
import org.fugerit.java.doc.mod.openpdf.ext.PdfTypeHandler;
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
13+
14+
import java.io.File;
15+
import java.io.FileOutputStream;
16+
import java.io.InputStreamReader;
17+
18+
@Slf4j
19+
class TestMetadataOpenPDF {
20+
21+
private static final String TEST_TITLE = "Module OpenPDF Metadata Test";
22+
private static final String TEST_SUBJECT = "Simple document to test PDF metadata";
23+
private static final String TEST_AUTHOR = "fugerit79";
24+
private static final String TEST_CREATOR = "My Creator";
25+
private static final String TEST_PRODUCER = "My Producer";
26+
27+
@Test
28+
void testProducer() throws Exception {
29+
DocTypeHandler handler = PdfTypeHandler.HANDLER;
30+
String fileName = "doc_producer";
31+
File outputFile = new File( String.format( "target/%s.%s", fileName, handler.getType() ) );
32+
try ( InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( String.format( "xml/%s.xml", fileName ) ) );
33+
FileOutputStream fos = new FileOutputStream( outputFile ) ) {
34+
handler.handle( DocInput.newInput( handler.getType(), reader ) , DocOutput.newOutput( fos ) );
35+
log.info( "file {}", outputFile.getCanonicalFile() );
36+
}
37+
try (PDDocument document = PDDocument.load(outputFile)) {
38+
PDDocumentInformation info = document.getDocumentInformation();
39+
String producer = info.getProducer();
40+
String creator = info.getCreator();
41+
log.info( "producer : {}, creator : {}", producer, creator );
42+
Assertions.assertEquals( TEST_PRODUCER, producer );
43+
Assertions.assertEquals( TEST_CREATOR, creator );
44+
String title = info.getTitle();
45+
String subject = info.getSubject();
46+
log.info( "title : {}, subject : {}", title, subject );
47+
Assertions.assertEquals( TEST_TITLE, title );
48+
Assertions.assertEquals( TEST_SUBJECT, subject );
49+
String author = info.getAuthor();
50+
String language = document.getDocumentCatalog().getLanguage();
51+
log.info( "author : {}, language : {}", author, language );
52+
Assertions.assertEquals( TEST_AUTHOR, author );
53+
}
54+
}
55+
56+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<doc xmlns="http://javacoredoc.fugerit.org"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd">
4+
<metadata>
5+
<info name="margins">10;10;10;30</info>
6+
<info name="table-border-collapse">collapse</info>
7+
<info name="doc-title">Module OpenPDF Metadata Test</info>
8+
<info name="doc-subject">Simple document to test PDF metadata</info>
9+
<info name="doc-author">fugerit79</info>
10+
<info name="doc-creator">My Creator</info>
11+
<info name="doc-producer">My Producer</info>
12+
<info name="doc-language">it</info>
13+
<footer-ext>
14+
<para align="center">Page ${currentPage}</para>
15+
</footer-ext>
16+
</metadata>
17+
<body>
18+
<h head-level="1">Producer doc sample</h>
19+
<para>Test producer for OpenPDF Module</para>
20+
</body>
21+
</doc>

0 commit comments

Comments
 (0)