Skip to content

Commit e549a27

Browse files
committed
Test coverage fj-doc-mod-*
1 parent 2f3d82d commit e549a27

File tree

24 files changed

+726
-68
lines changed

24 files changed

+726
-68
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package test.org.fugerit.java.doc.mod.opencsv.coverage;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.InputStreamReader;
5+
import java.util.Arrays;
6+
7+
import org.fugerit.java.core.function.SafeFunction;
8+
import org.fugerit.java.core.function.SimpleValue;
9+
import org.fugerit.java.core.lang.helpers.ClassHelper;
10+
import org.fugerit.java.doc.base.config.DocInput;
11+
import org.fugerit.java.doc.base.config.DocOutput;
12+
import org.fugerit.java.doc.base.config.DocTypeHandler;
13+
import org.fugerit.java.doc.mod.opencsv.OpenCSVTypeHandler;
14+
import org.junit.Assert;
15+
import org.junit.Test;
16+
17+
import lombok.AllArgsConstructor;
18+
import lombok.Getter;
19+
import lombok.ToString;
20+
import lombok.extern.slf4j.Slf4j;
21+
22+
@Slf4j
23+
public class TestOpencsvCoverage {
24+
25+
private final static TestEntry[] TEST_LIST = {
26+
new TestEntry( "default_doc" , true ),
27+
new TestEntry( "default_doc_alt" , true ),
28+
new TestEntry( "default_doc_fail1" , false )
29+
};
30+
31+
private final static DocTypeHandler[] HANDLERS = { OpenCSVTypeHandler.HANDLER };
32+
33+
private boolean worker( String path, boolean result ) {
34+
SimpleValue<Boolean> res = new SimpleValue<>(false);
35+
SafeFunction.apply( () -> {
36+
for ( int k=0; k<HANDLERS.length; k++ ) {
37+
DocTypeHandler handler = HANDLERS[k];
38+
try ( InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader(path) );
39+
ByteArrayOutputStream buffer = new ByteArrayOutputStream() ) {
40+
handler.handle( DocInput.newInput( handler.getType() , reader ) , DocOutput.newOutput( buffer ) );
41+
if ( result ) {
42+
res.setValue( buffer.toByteArray().length > 0 );
43+
} else {
44+
res.setValue( buffer.toByteArray().length == 0 );
45+
}
46+
}
47+
}
48+
} );
49+
return res.getValue();
50+
}
51+
52+
@Test
53+
public void test01() {
54+
Arrays.asList( TEST_LIST ).stream().forEach( c -> {
55+
log.info( "test -> {}", c );
56+
Assert.assertTrue( this.worker( "coverage/xml/"+c.getId()+".xml", c.isResult() ) );
57+
} );
58+
}
59+
60+
}
61+
62+
@AllArgsConstructor
63+
@ToString
64+
class TestEntry {
65+
66+
@Getter private String id;
67+
68+
@Getter private boolean result;
69+
70+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc
3+
xmlns="http://javacoredoc.fugerit.org"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-1.xsd" >
6+
7+
<metadata>
8+
<!-- Margin for document : left;right;top;bottom -->
9+
<info name="margins">10;10;10;30</info>
10+
<info name="excel-table-id">excel-table=print</info>
11+
<!-- documenta meta information -->
12+
<info name="doc-title">Basic example</info>
13+
<info name="doc-subject">fj doc venus sample source xml</info>
14+
<info name="doc-author">fugerit79</info>
15+
<info name="doc-language">en</info>
16+
<!-- additional properties -->
17+
<info name="set-total-page">true</info>
18+
<info name="html-css-link">/css/test.css</info>
19+
<!-- CSV options -->
20+
<info name="csv-table-id">excel-table</info>
21+
<header-ext>
22+
<para align="center" fore-color="#eeeeee">header test</para>
23+
</header-ext>
24+
<footer-ext>
25+
<para align="left">test</para>
26+
<para align="center">${r"${currentPage}"} / ${r"${pageCount}"}</para>
27+
<para align="right">test</para>
28+
</footer-ext>
29+
<bookmark-tree>
30+
<bookmark ref="title">Test</bookmark>
31+
</bookmark-tree>
32+
</metadata>
33+
<body>
34+
<h id="title" head-level="1">main title h1</h>
35+
<para font-name="times-roman" style="bold">Test times roman</para>
36+
<para font-name="courier" style="bolditalic">Courier</para>
37+
<para font-name="symbol" style="italic">Symbol</para>
38+
<para font-name="helvetica" style="underline">Symbol</para>
39+
<para size="3" fore-color="#dddddd">Test default font</para>
40+
<br/>
41+
<page-break/>
42+
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
43+
<row>
44+
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
45+
<cell align="center"><para style="bold">Surname</para></cell>
46+
<cell align="center"><para style="bold">Title</para></cell>
47+
</row>
48+
<row>
49+
<cell><para><![CDATA[Luthien]]></para></cell>
50+
<cell><para><![CDATA[Tinuviel]]></para></cell>
51+
<cell><para><![CDATA[Queen]]></para></cell>
52+
</row>
53+
<row>
54+
<cell><para><![CDATA[Thorin]]></para></cell>
55+
<cell><para><![CDATA[Oakshield]]></para></cell>
56+
<cell><para><![CDATA[King]]></para></cell>
57+
</row>
58+
<row>
59+
<cell><phrase><![CDATA[Phrase]]></phrase></cell>
60+
<cell><phrase anchor="1"><![CDATA[Oakshield]]></phrase></cell>
61+
<cell><phrase link="1"><![CDATA[King]]></phrase></cell>
62+
</row>
63+
</table>
64+
<list>
65+
<li><para>test 1</para></li>
66+
</list>
67+
<list list-type="ul">
68+
<li><para>test 2</para></li>
69+
</list>
70+
<list list-type="ol">
71+
<li><para>test 3</para></li>
72+
</list>
73+
<list list-type="uld">
74+
<li><para>test 4</para></li>
75+
</list>
76+
<list list-type="ulm">
77+
<li><para>test 5</para></li>
78+
</list>
79+
<list list-type="oll">
80+
<li><para>test 6</para></li>
81+
</list>
82+
<list list-type="oln">
83+
<li><para>test 7</para></li>
84+
</list>
85+
</body>
86+
87+
</doc>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc
3+
xmlns="http://javacoredoc.fugerit.org"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-0.xsd" >
6+
7+
<metadata>
8+
<!-- Margin for document : left;right;top;bottom -->
9+
<info name="margins">10;10;10;30</info>
10+
<info name="excel-table-id">excel-table=print</info>
11+
<!-- documenta meta information -->
12+
<info name="doc-title">Basic example</info>
13+
<info name="doc-subject">fj doc venus sample source xml</info>
14+
<info name="doc-author">fugerit79</info>
15+
<info name="doc-language">en</info>
16+
<!-- font must be loaded -->
17+
<info name="page-orient">horizontal</info>
18+
<!-- specific xlsx properties -->
19+
<info name="excel-try-autoresize">true</info>
20+
<!-- CSV options -->
21+
<info name="csv-table-id">excel-table</info>
22+
<header>
23+
<phrase fore-color="#222222" leading="3" align="right">header test</phrase>
24+
</header>
25+
<footer>
26+
<para fore-color="#222222" leading="3" align="right">${r"${currentPage}"} / ${r"${pageCount}"}</para>
27+
</footer>
28+
</metadata>
29+
<body>
30+
<image scaling="100" url="cl://test/img_test_teal.jpg"/>
31+
<phrase leading="3">My sample title</phrase>
32+
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
33+
<row>
34+
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
35+
<cell align="center"><para fore-color="#ffffff" style="bold">Surname</para></cell>
36+
<cell align="center"><para style="bold">Title</para></cell>
37+
</row>
38+
<row>
39+
<cell><para><![CDATA[Luthien]]></para></cell>
40+
<cell><para><![CDATA[Tinuviel]]></para></cell>
41+
<cell><para><![CDATA[Queen]]></para></cell>
42+
</row>
43+
<row>
44+
<cell><para><![CDATA[Thorin]]></para></cell>
45+
<cell><para><![CDATA[Oakshield]]></para></cell>
46+
<cell><para><![CDATA[King]]></para></cell>
47+
</row>
48+
<row>
49+
<cell><barcode text="0123456789123"/></cell>
50+
<cell><image scaling="100" url="cl://test/img_test_teal.jpg"/></cell>
51+
<cell>
52+
<table columns="2" colwidths="50;50" width="100" id="a-table" padding="2">
53+
<row>
54+
<cell><para>1</para></cell>
55+
<cell><para>2</para></cell>
56+
</row>
57+
</table>
58+
</cell>
59+
</row>
60+
</table>
61+
</body>
62+
63+
<page-break/>
64+
65+
</doc>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc
3+
xmlns="http://javacoredoc.fugerit.org"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://javacoredoc.fugerit.org https://www.fugerit.org/data/java/doc/xsd/doc-2-0.xsd" >
6+
7+
<metadata>
8+
<!-- Margin for document : left;right;top;bottom -->
9+
<info name="margins">10;10;10;30</info>
10+
<info name="excel-table-id">excel-table=print</info>
11+
<!-- documenta meta information -->
12+
<info name="doc-title">Basic example</info>
13+
<info name="doc-subject">fj doc venus sample source xml</info>
14+
<info name="doc-author">fugerit79</info>
15+
<info name="doc-language">en</info>
16+
<!-- additional properties -->
17+
<info name="set-total-page">true</info>
18+
<info name="html-css-link">/css/test.css</info>
19+
<header-ext>
20+
<para align="center" fore-color="#eeeeee">header test</para>
21+
</header-ext>
22+
<footer-ext>
23+
<para align="left">test</para>
24+
<para align="center">${r"${currentPage}"} / ${r"${pageCount}"}</para>
25+
<phrase link="1"><![CDATA[King]]></phrase>
26+
</footer-ext>
27+
</metadata>
28+
<body>
29+
<para font-name="times-roman" style="bold">Test times roman</para>
30+
<para font-name="courier" style="bolditalic">Courier</para>
31+
<para font-name="symbol" style="italic">Symbol</para>
32+
<para font-name="helvetica" style="underline">Symbol</para>
33+
<para size="-1" fore-color="#dddddd">Test default font</para>
34+
<table columns="3" colwidths="30;30;40" width="100" id="excel-table" padding="2">
35+
<row>
36+
<cell align="center" border-color="#000000" border-width="1"><para style="bold">Name</para></cell>
37+
<cell align="center"><para style="bold">Surname</para></cell>
38+
<cell align="center"><para style="bold">Title</para></cell>
39+
</row>
40+
<row>
41+
<cell><para><![CDATA[Luthien]]></para></cell>
42+
<cell><para><![CDATA[Tinuviel]]></para></cell>
43+
<cell><para><![CDATA[Queen]]></para></cell>
44+
</row>
45+
<row>
46+
<cell><para><![CDATA[Thorin]]></para></cell>
47+
<cell><para><![CDATA[Oakshield]]></para></cell>
48+
<cell><para><![CDATA[King]]></para></cell>
49+
</row>
50+
<row>
51+
<cell><phrase><![CDATA[Phrase]]></phrase></cell>
52+
<cell><phrase anchor="1"><![CDATA[Oakshield]]></phrase></cell>
53+
<cell><phrase link="1"><![CDATA[King]]></phrase></cell>
54+
</row>
55+
</table>
56+
</body>
57+
58+
</doc>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="INFO">
10+
<AppenderRef ref="Console"/>
11+
</Root>
12+
</Loggers>
13+
</Configuration>

fj-doc-mod-poi/src/main/java/org/fugerit/java/doc/mod/poi/BasicPoiTypeHandler.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
import org.fugerit.java.doc.base.typehelper.generic.FormatTypeConsts;
4141

4242
import lombok.AllArgsConstructor;
43-
import lombok.Data;
44-
import lombok.RequiredArgsConstructor;
43+
import lombok.Getter;
44+
import lombok.Setter;
4545
import lombok.extern.slf4j.Slf4j;
4646

4747
@Slf4j
@@ -311,14 +311,12 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception {
311311

312312
}
313313

314-
@Data
315314
@AllArgsConstructor
316-
@RequiredArgsConstructor
317315
class WorkbookDataWrapper {
318316

319-
private TableMatrix tableMatrix;
317+
@Getter @Setter private TableMatrix tableMatrix;
320318

321-
private WorkbookHelper workbookHelper;
319+
@Getter @Setter private WorkbookHelper workbookHelper;
322320

323321
public Workbook getWorkbook() {
324322
return this.getWorkbookHelper().getWorkbook();

fj-doc-mod-poi/src/main/java/org/fugerit/java/doc/mod/poi/PoiCellStyleModel.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,37 @@ private static boolean eq( Object o1, Object o2 ) {
5959
public static CellStyle find( Collection<PoiCellStyleModel> styles, DocPara p, DocCell c ) {
6060
CellStyle result = null;
6161
DocBorders b = c.getDocBorders();
62-
for ( PoiCellStyleModel style : styles ) {
63-
DocPara cp = style.getDocPara();
64-
DocCell cc = style.getDocCell();
65-
DocBorders cb = cc.getDocBorders();
66-
boolean equal = eq( p.getBackColor(), cp.getBackColor() )
67-
&& eq( p.getForeColor(), cp.getForeColor() )
68-
&& eq( p.getFontName(), cp.getFontName() )
69-
&& eq( p.getSize(), cp.getSize() )
70-
&& eq( p.getFormat(), cp.getFormat() )
71-
&& eq( p.getStyle(), cp.getStyle() )
72-
&& eq( p.getType(), cp.getType() )
73-
&& eq( p.getAlign(), cp.getAlign() );
74-
equal = equal
75-
&& eq( c.getBackColor(), cc.getBackColor() )
76-
&& eq( c.getForeColor(), cc.getForeColor() )
77-
&& eq( c.getType(), cc.getType() )
78-
&& eq( c.getAlign(), cc.getAlign() );
79-
equal = equal
80-
&& eq( b.getBorderWidthBottom(), cb.getBorderWidthBottom() )
81-
&& eq( b.getBorderWidthTop(), cb.getBorderWidthTop() )
82-
&& eq( b.getBorderWidthLeft(), cb.getBorderWidthLeft() )
83-
&& eq( b.getBorderWidthRight(), cb.getBorderWidthRight() )
84-
&& eq( b.getBorderColorBottom(), cb.getBorderColorBottom() )
85-
&& eq( b.getBorderColorTop(), cb.getBorderColorTop() )
86-
&& eq( b.getBorderColorLeft(), cb.getBorderColorLeft() )
87-
&& eq( b.getBorderColorRight(), cb.getBorderColorRight() );
88-
if ( equal ) {
89-
result = style.getStyle();
90-
break;
62+
if ( p!= null ) {
63+
for ( PoiCellStyleModel style : styles ) {
64+
DocPara cp = style.getDocPara();
65+
DocCell cc = style.getDocCell();
66+
DocBorders cb = cc.getDocBorders();
67+
boolean equal = eq( p.getBackColor(), cp.getBackColor() )
68+
&& eq( p.getForeColor(), cp.getForeColor() )
69+
&& eq( p.getFontName(), cp.getFontName() )
70+
&& eq( p.getSize(), cp.getSize() )
71+
&& eq( p.getFormat(), cp.getFormat() )
72+
&& eq( p.getStyle(), cp.getStyle() )
73+
&& eq( p.getType(), cp.getType() )
74+
&& eq( p.getAlign(), cp.getAlign() );
75+
equal = equal
76+
&& eq( c.getBackColor(), cc.getBackColor() )
77+
&& eq( c.getForeColor(), cc.getForeColor() )
78+
&& eq( c.getType(), cc.getType() )
79+
&& eq( c.getAlign(), cc.getAlign() );
80+
equal = equal
81+
&& eq( b.getBorderWidthBottom(), cb.getBorderWidthBottom() )
82+
&& eq( b.getBorderWidthTop(), cb.getBorderWidthTop() )
83+
&& eq( b.getBorderWidthLeft(), cb.getBorderWidthLeft() )
84+
&& eq( b.getBorderWidthRight(), cb.getBorderWidthRight() )
85+
&& eq( b.getBorderColorBottom(), cb.getBorderColorBottom() )
86+
&& eq( b.getBorderColorTop(), cb.getBorderColorTop() )
87+
&& eq( b.getBorderColorLeft(), cb.getBorderColorLeft() )
88+
&& eq( b.getBorderColorRight(), cb.getBorderColorRight() );
89+
if ( equal ) {
90+
result = style.getStyle();
91+
break;
92+
}
9193
}
9294
}
9395
return result;

0 commit comments

Comments
 (0)