Skip to content

Commit

Permalink
More test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Sep 6, 2023
1 parent 32c1339 commit 28e5e35
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,42 +112,7 @@ public void onEndPage(PdfWriter writer, Document document) {
}

}
cb.endText();

// while ( itElements.hasNext() ) {
// DocElement current = (DocElement)itElements.next();
// if ( current instanceof DocPara ) {
// DocPara para = (DocPara) current;
// String originalText = para.getText();
// String text = ITextDocHandler.createText( docHelper.getParams(), originalText );
// float textBase = document.bottom() - totalOffset;
// float textSize = baseFont.getWidthPoint(text, footerTextSize);
// cb.beginText();
// cb.setFontAndSize(baseFont, footerTextSize);
// if( para.getAlign() == DocPara.ALIGN_CENTER ) {
// cb.setTextMatrix((document.right() / 2), textBase);
// cb.showText(text);
// cb.endText();
// //cb.addTemplate(totalPages, (document.right() / 2) + textSize, textBase);
// } else if( para.getAlign() == DocPara.ALIGN_LEFT ) {
// cb.setTextMatrix(document.left(), textBase);
// cb.showText(text);
// cb.endText();
// //cb.addTemplate(totalPages, document.left() + textSize, textBase);
// } else {
// float adjust = baseFont.getWidthPoint("0", footerTextSize);
// cb.setTextMatrix(document.right() - textSize - adjust, textBase);
// cb.showText(text);
// cb.endText();
// //cb.addTemplate(totalPages, document.right() - adjust, textBase);
// }
//
// } else {
// throw new RuntimeException( "Element not allowed in footer (accepted only DocPara) : "+current );
// }
// }


cb.endText();
// restore writer state
cb.restoreState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,49 @@
import org.fugerit.java.doc.mod.openpdf.HtmlTypeHandler;
import org.fugerit.java.doc.mod.openpdf.PdfTypeHandler;
import org.fugerit.java.doc.mod.openpdf.RtfTypeHandler;
import org.junit.Assert;
import org.junit.Test;

public class TestDefaultDoc extends TestDocBase {

private static final String DEFAULT_DOC = "default_doc";

private static final String DEFAULT_DOC_ALT = "default_doc_alt";

@Test
public void testOpenPDF() {
this.testDocWorker( "default_doc" , PdfTypeHandler.HANDLER );
boolean ok = this.testDocWorker( DEFAULT_DOC , PdfTypeHandler.HANDLER );
Assert.assertTrue(ok);
}

@Test
public void testOpenHTML() {
this.testDocWorker( "default_doc" , HtmlTypeHandler.HANDLER );
boolean ok = this.testDocWorker( DEFAULT_DOC , HtmlTypeHandler.HANDLER );
Assert.assertTrue(ok);
}

@Test
public void testOpenRTF() {
this.testDocWorker( "default_doc" , RtfTypeHandler.HANDLER );
boolean ok = this.testDocWorker( DEFAULT_DOC , RtfTypeHandler.HANDLER );
Assert.assertTrue(ok);
}

@Test
public void testOpenAltPDF() {
boolean ok = this.testDocWorker( DEFAULT_DOC_ALT , PdfTypeHandler.HANDLER );
Assert.assertTrue(ok);
}

@Test
public void testOpenAltHTML() {
boolean ok = this.testDocWorker( DEFAULT_DOC_ALT , HtmlTypeHandler.HANDLER );
Assert.assertTrue(ok);
}

@Test
public void testOpenAltRTF() {
boolean ok = this.testDocWorker( DEFAULT_DOC_ALT , RtfTypeHandler.HANDLER );
Assert.assertTrue(ok);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@
@Slf4j
public class TestDocBase {

protected void testDocWorker( String testCase, DocTypeHandler handler ) {
protected boolean testDocWorker( String testCase, DocTypeHandler handler ) {
boolean ok = false;
String inputXml = "xml/"+testCase+".xml" ;
File outputFile = new File( "target", testCase+"."+handler.getType() );
log.info( "inputXml:{}, outputFile:{}", inputXml, outputFile );
try ( InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( inputXml ) );
OutputStream os = new FileOutputStream( outputFile ) ) {
handler.handle( DocInput.newInput( handler.getType() , reader ) , DocOutput.newOutput(os) );
ok = true;
} catch (Exception e) {
String message = "Error : "+e.getMessage();
log.error( message , e );
fail( message );
}
return ok;
}

}
3 changes: 3 additions & 0 deletions src/test/resources/xml/default_doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<!--
<info name="default-font-name">TitilliumWeb</info>
-->
<header-ext>
<para align="right">header test</para>
</header-ext>
<footer-ext>
<para align="right">${r"${currentPage}"} / ${r"${pageCount}"}</para>
</footer-ext>
Expand Down
48 changes: 48 additions & 0 deletions src/test/resources/xml/default_doc_alt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<doc
xmlns="http://javacoredoc.fugerit.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-0.xsd" >

<metadata>
<!-- Margin for document : left;right;top;bottom -->
<info name="margins">10;10;10;30</info>
<info name="excel-table-id">excel-table=print</info>
<!-- documenta meta information -->
<info name="doc-title">Basic example</info>
<info name="doc-subject">fj doc venus sample source xml</info>
<info name="doc-author">fugerit79</info>
<info name="doc-language">en</info>
<!-- font must be loaded -->
<!--
<info name="default-font-name">TitilliumWeb</info>
-->
<header-ext>
<para align="right">header test</para>
</header-ext>
<footer-ext>
<para align="right">${r"${currentPage}"} / ${r"${pageCount}"}</para>
</footer-ext>
</metadata>
<body>
<para>My sample title</para>
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
<row>
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
<cell align="center"><para style="bold">Surname</para></cell>
<cell align="center"><para style="bold">Title</para></cell>
</row>
<row>
<cell><para><![CDATA[Luthien]]></para></cell>
<cell><para><![CDATA[Tinuviel]]></para></cell>
<cell><para><![CDATA[Queen]]></para></cell>
</row>
<row>
<cell><para><![CDATA[Thorin]]></para></cell>
<cell><para><![CDATA[Oakshield]]></para></cell>
<cell><para><![CDATA[King]]></para></cell>
</row>
</table>
</body>

</doc>

0 comments on commit 28e5e35

Please sign in to comment.