Skip to content

Commit f02bfa5

Browse files
committed
Code coverage
1 parent 8330763 commit f02bfa5

File tree

13 files changed

+252
-46
lines changed

13 files changed

+252
-46
lines changed

fj-doc-base/src/main/java/org/fugerit/java/doc/base/feature/tableintegritycheck/TableIntegrityCheck.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ private TableIntegrityCheck() {}
2828
} ) );
2929
}
3030

31-
private static int checkColumns( DocRow docRow, int currentCol, Map<Integer,Integer> rowSpanTracker ) {
31+
private static int processCells( DocRow docRow, int currentCol, Map<Integer,Integer> rowSpanTracker ) {
3232
for (DocElement cell : docRow.getElementList()) {
3333
DocCell docCell = (DocCell) cell;
3434
int colspan = Math.max(1, docCell.getColumnSpan());
3535
int rowspan = Math.max(1, docCell.getRowSpan());
36-
3736
int startCol = currentCol;
3837
currentCol += colspan;
39-
4038
// mark future row occupation
4139
if (rowspan > 1) {
4240
for (int c = startCol; c < startCol+colspan; c++) {
@@ -47,42 +45,39 @@ private static int checkColumns( DocRow docRow, int currentCol, Map<Integer,Inte
4745
return currentCol;
4846
}
4947

50-
private static void checkRows( TableIntegrityCheckResult result, DocTable docTable, int columns, Map<Integer,Integer> rowSpanTracker ) {
48+
private static void validateRows(TableIntegrityCheckResult result, DocTable docTable, int columns, Map<Integer,Integer> rowSpanTracker ) {
5149
int rowIndex = 0;
5250
for (DocElement row : docTable.getElementList()) {
5351
DocRow docRow = (DocRow) row;
5452
int currentCol = 0;
55-
while (currentCol < columns) {
56-
while (rowSpanTracker.getOrDefault(currentCol, 0) > 0) {
57-
rowSpanTracker.put(currentCol, rowSpanTracker.get(currentCol) - 1);
58-
currentCol++;
59-
}
60-
if (currentCol >= columns) break;
61-
currentCol = checkColumns(docRow, currentCol, rowSpanTracker);
53+
// consume row spans first
54+
while (currentCol < columns && rowSpanTracker.getOrDefault(currentCol, 0) > 0) {
55+
rowSpanTracker.put(currentCol, rowSpanTracker.get(currentCol) - 1);
56+
currentCol++;
6257
}
58+
// process actual row cells exactly once
59+
currentCol = processCells(docRow, currentCol, rowSpanTracker);
6360
if (currentCol != columns) {
64-
result.getMessages().add( String.format( "Row %s has %s columns instead of %s", rowIndex, currentCol, columns ) );
61+
result.getMessages().add(
62+
String.format("Row %s has %s columns instead of %s", rowIndex, currentCol, columns)
63+
);
6564
}
6665
rowIndex++;
6766
}
6867
}
6968

69+
7070
private static TableIntegrityCheckResult checkWorker(DocTable docTable, Consumer<TableIntegrityCheckResult> resultConsumer) {
7171
TableIntegrityCheckResult result = new TableIntegrityCheckResult(Result.RESULT_CODE_OK);
72-
7372
int columns = docTable.getColumns();
7473
Map<Integer,Integer> rowSpanTracker = new HashMap<>();
75-
76-
checkRows( result, docTable, columns, rowSpanTracker );
77-
74+
validateRows( result, docTable, columns, rowSpanTracker );
7875
for (Map.Entry<Integer,Integer> e : rowSpanTracker.entrySet()) {
7976
if (e.getValue() > 0) {
8077
result.getMessages().add( String.format( "Unfinished rowspan at column %s", e.getKey() ) );
8178
}
8279
}
83-
8480
result.setResultCode( result.getMessages().size() );
85-
8681
if ( result.getResultCode() == Result.RESULT_CODE_OK ) {
8782
log.debug( "Table Integrity Check OK" );
8883
} else {

fj-doc-base/src/main/java/org/fugerit/java/doc/base/xml/DocXmlParser.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.fugerit.java.doc.base.parser.DocValidationResult;
1919
import org.xml.sax.InputSource;
2020

21-
import lombok.Getter;
2221
import lombok.extern.slf4j.Slf4j;
2322

2423
@Slf4j
@@ -34,23 +33,20 @@ public static void fillDocValidationResultHelper( SAXParseResult result, DocVali
3433
}
3534

3635
private DocHelper docHelper;
37-
38-
@Getter private FeatureConfig featureConfig;
36+
3937

4038
public boolean isFailWhenElementNotFound() {
41-
return featureConfig.isFailWhenElementNotFound();
39+
return this.getFeatureConfig().isFailWhenElementNotFound();
4240
}
4341

4442
public DocXmlParser(DocHelper docHelper, final boolean failWhenElementNotFound ) {
45-
super( DocFacadeSource.SOURCE_TYPE_XML );
46-
this.docHelper = docHelper;
47-
this.featureConfig = FeatureConfig.fromFailWhenElementNotFound( failWhenElementNotFound );
43+
this( docHelper, FeatureConfig.fromFailWhenElementNotFound( failWhenElementNotFound ) );
4844
}
4945

5046
public DocXmlParser(DocHelper docHelper, FeatureConfig featureConfig) {
5147
super( DocFacadeSource.SOURCE_TYPE_XML );
5248
this.docHelper = docHelper;
53-
this.featureConfig = featureConfig;
49+
super.setFeatureConfig( featureConfig );
5450
}
5551

5652
public DocXmlParser( boolean failOnElementNotFound ) {

fj-doc-base/src/test/java/test/org/fugerit/java/doc/base/feature/DocFeatureRuntimeExceptionTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ void convertToRuntimeEx2Test() {
3939
Assertions.assertEquals( TEST_MESSAGE, DocFeatureRuntimeException.convertToRuntimeEx( CONFIG_RUNTIME_EXCEPTION ).getMessage() );
4040
}
4141

42+
@Test
43+
void convertExMethod1Test() {
44+
Assertions.assertEquals( "Exception during testMethod : org.fugerit.java.core.cfg.ConfigRuntimeException: test message", DocFeatureRuntimeException.convertExMethod( "testMethod", CONFIG_RUNTIME_EXCEPTION ).getMessage() );
45+
}
46+
47+
@Test
48+
void convertEx1Test() {
49+
Assertions.assertEquals( "Exception cause is : org.fugerit.java.core.cfg.ConfigRuntimeException: test message", DocFeatureRuntimeException.convertEx( CONFIG_RUNTIME_EXCEPTION ).getMessage() );
50+
}
51+
4252
}

fj-doc-base/src/test/java/test/org/fugerit/java/doc/base/feature/TableCheckIntegrityTest.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import java.io.IOException;
1515
import java.io.InputStreamReader;
1616
import java.io.Reader;
17+
import java.util.Arrays;
18+
import java.util.LinkedHashMap;
19+
import java.util.Map;
20+
import java.util.Properties;
1721

1822
@Slf4j
1923
class TableCheckIntegrityTest {
@@ -32,29 +36,31 @@ private int testWorker( String xmlPath ) {
3236
}
3337

3438
@Test
35-
void testKoDisabled() {
36-
Assertions.assertEquals( BasicDaoResult.RESULT_CODE_OK, this.testWorker( "colspan-rowspan-sample-ko-disabled" ) );
37-
}
38-
39-
@Test
40-
void testKoWarn() {
41-
Assertions.assertEquals( BasicDaoResult.RESULT_CODE_OK, this.testWorker( "colspan-rowspan-sample-ko-warn" ) );
42-
}
43-
44-
@Test
45-
void testKoFail() {
46-
Assertions.assertThrows( DocFeatureRuntimeException.class, () -> this.testWorker( "colspan-rowspan-sample-ko-fail" ) );
39+
void testOk() {
40+
Assertions.assertEquals( BasicDaoResult.RESULT_CODE_OK, this.testWorker( "colspan-rowspan-sample-ok" ) );
4741
}
4842

4943
@Test
50-
void testKoFailUnfinished() {
51-
Assertions.assertThrows( DocFeatureRuntimeException.class, () -> this.testWorker( "colspan-rowspan-sample-ko-fail-unfinished" ) );
44+
void testKoNoException() {
45+
Arrays.asList( "colspan-rowspan-sample-ko-disabled", "colspan-rowspan-sample-ko-warn" )
46+
.forEach( k -> Assertions.assertEquals( BasicDaoResult.RESULT_CODE_OK, this.testWorker( k ) ) );
5247
}
5348

5449
@Test
55-
void testOk() {
56-
Assertions.assertEquals( BasicDaoResult.RESULT_CODE_OK, this.testWorker( "colspan-rowspan-sample-ok" ) );
50+
void testFailException() {
51+
Map<String, String> testCases = new LinkedHashMap<>();
52+
testCases.put( "colspan-rowspan-sample-ko-fail-less-column", "Row 0 has 2 columns instead of 3" );
53+
testCases.put( "colspan-rowspan-sample-ko-fail-extra-column", "Row 3 has 5 columns instead of 3" );
54+
testCases.put( "colspan-rowspan-sample-ko-fail", "Row 1 has 4 columns instead of 3" );
55+
testCases.put( "colspan-rowspan-sample-ko-fail-unfinished", "Unfinished rowspan at column 0" );
56+
for ( String k : testCases.keySet() ) {
57+
try {
58+
this.testWorker( k );
59+
} catch (DocFeatureRuntimeException e) {
60+
log.info( "messages: {}", e.getMessages() );
61+
Assertions.assertTrue( e.getMessages().contains( testCases.get( k ) ) );
62+
}
63+
}
5764
}
5865

59-
6066
}

fj-doc-base/src/test/java/test/org/fugerit/java/doc/base/xml/TestDocXmlParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void testDocXmlParser1() {
4343
Assertions.assertNotNull( parser );
4444
Assertions.assertEquals( FeatureConfig.DEFAULT.isFailWhenElementNotFound(), parser.getFeatureConfig().isFailWhenElementNotFound() );
4545
Assertions.assertEquals(DocFacadeSource.SOURCE_TYPE_XML, parser.getSourceType() );
46+
Assertions.assertNotNull( parser.getFeatureConfig() );
4647
}
4748

4849
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
<!-- documenta meta information -->
11+
<info name="doc-title">colspan / rowspan sample</info>
12+
<info name="doc-subject">fj doc venus sample source FreeMarker Template XML</info>
13+
<info name="doc-author">fugerit79</info>
14+
<info name="doc-language">en</info>
15+
<!-- font must be loaded -->
16+
<info name="default-font-name">TitilliumWeb</info>
17+
<!-- property specific for xls/xlsx -->
18+
<info name="excel-table-id">data-table=print</info>
19+
<!-- property specific for csv -->
20+
<info name="csv-table-id">data-table</info>
21+
<info name="table-check-integrity">fail</info>
22+
<footer-ext>
23+
<para align="right">${currentPage} / ${pageCount}</para>
24+
</footer-ext>
25+
</metadata>
26+
<body>
27+
<para>colspan / rowspan sample</para>
28+
<table columns="3" colwidths="30;30;40" width="100" id="data-table" padding="2">
29+
<row header="true">
30+
<cell rowspan="2" align="center"><para>Title</para></cell>
31+
<cell colspan="2" align="center"><para>Data</para></cell>
32+
</row>
33+
<row header="true">
34+
<cell align="center"><para>Name</para></cell>
35+
<cell align="center"><para>Surname</para></cell>
36+
</row>
37+
<row>
38+
<cell><para>Queen</para></cell>
39+
<cell><para>Luthien</para></cell>
40+
<cell><para>Tinuviel</para></cell>
41+
</row>
42+
<row>
43+
<cell><para>King</para></cell>
44+
<cell><para>Thorin</para></cell>
45+
<cell><para>Oakshield</para></cell>
46+
<cell><para>Extra column 1</para></cell>
47+
<cell><para>Extra column 2</para></cell>
48+
</row>
49+
<row>
50+
<cell><para>Ring bearer</para></cell>
51+
<cell><para>Bilbo</para></cell>
52+
<cell><para>Bagging</para></cell>
53+
</row>
54+
<row>
55+
<cell><para>Eldest</para></cell>
56+
<cell><para>Tom</para></cell>
57+
<cell><para>Bombadil</para></cell>
58+
</row>
59+
</table>
60+
</body>
61+
62+
</doc>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
<!-- documenta meta information -->
11+
<info name="doc-title">colspan / rowspan sample</info>
12+
<info name="doc-subject">fj doc venus sample source FreeMarker Template XML</info>
13+
<info name="doc-author">fugerit79</info>
14+
<info name="doc-language">en</info>
15+
<!-- font must be loaded -->
16+
<info name="default-font-name">TitilliumWeb</info>
17+
<!-- property specific for xls/xlsx -->
18+
<info name="excel-table-id">data-table=print</info>
19+
<!-- property specific for csv -->
20+
<info name="csv-table-id">data-table</info>
21+
<info name="table-check-integrity">fail</info>
22+
<footer-ext>
23+
<para align="right">${currentPage} / ${pageCount}</para>
24+
</footer-ext>
25+
</metadata>
26+
<body>
27+
<para>colspan / rowspan sample</para>
28+
<table columns="3" colwidths="30;30;40" width="100" id="data-table" padding="2">
29+
<row header="true">
30+
<cell align="center"><para>Name</para></cell>
31+
<cell align="center"><para>Surname</para></cell>
32+
</row>
33+
<row>
34+
<cell><para>Queen</para></cell>
35+
<cell><para>Luthien</para></cell>
36+
<cell><para>Tinuviel</para></cell>
37+
</row>
38+
<row>
39+
<cell><para>King</para></cell>
40+
<cell><para>Thorin</para></cell>
41+
<cell><para>King</para></cell>
42+
</row>
43+
<row>
44+
<cell><para>Ring bearer</para></cell>
45+
<cell><para>Bilbo</para></cell>
46+
<cell><para>Bagging</para></cell>
47+
</row>
48+
<row>
49+
<cell><para>Eldest</para></cell>
50+
<cell><para>Tom</para></cell>
51+
<cell><para>Bombadil</para></cell>
52+
</row>
53+
</table>
54+
</body>
55+
56+
</doc>

fj-doc-base/src/test/resources/feature-info/table-check-integrity/colspan-rowspan-sample-ko-fail-unfinished.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
<cell><para>Bagging</para></cell>
5151
</row>
5252
<row>
53-
<cell><para>Eldest</para></cell>
53+
<cell rowspan="2"><para>Eldest</para></cell>
5454
<cell><para>Tom</para></cell>
55+
<cell><para>Bombadil</para></cell>
5556
</row>
5657
</table>
5758
</body>

fj-doc-playground-quarkus/src/main/java/org/fugerit/java/doc/playground/doc/GenerateRest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.fugerit.java.core.util.checkpoint.CheckpointUtils;
99
import org.fugerit.java.core.util.result.Result;
1010
import org.fugerit.java.doc.base.config.DocTypeHandler;
11+
import org.fugerit.java.doc.base.feature.DocFeatureRuntimeException;
1112
import org.fugerit.java.doc.base.parser.DocParser;
1213
import org.fugerit.java.doc.base.parser.DocValidationResult;
1314
import org.fugerit.java.doc.lib.simpletable.SimpleTableDocConfig;
@@ -49,7 +50,18 @@ public Response document(GenerateInput input) {
4950
} catch (Exception e) {
5051
log.warn("Error generating document : " + e, e);
5152
Throwable te = RestHelper.findCause(e);
52-
output.setMessage(te.getClass().getName() + " :\n" + te.getMessage());
53+
StringBuilder builder = new StringBuilder();
54+
builder.append(te.getClass().getName());
55+
builder.append(" :\n");
56+
builder.append(te.getMessage());
57+
if (e instanceof DocFeatureRuntimeException dfre) {
58+
builder.append("\nDetails:\n");
59+
dfre.getMessages().forEach(curr -> {
60+
builder.append(curr.toString());
61+
builder.append("\n");
62+
});
63+
}
64+
output.setMessage(builder.toString());
5365
}
5466
return Response.ok().entity(output).build();
5567
});

fj-doc-playground-quarkus/src/test/java/org/fugerit/java/doc/playground/GenerateRestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private void testWorker(String apiPath, String jsonPayloadPath) {
4848

4949
@Test
5050
void testGenerateDocument() {
51-
int[] testId = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
51+
int[] testId = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
5252
for (int k = 0; k < testId.length; k++) {
5353
String current = String.valueOf(testId[k] < 10 ? "0" + testId[k] : testId[k]);
5454
this.testWorker("/generate/document", "generate/test_generate_input_" + current + ".json");

0 commit comments

Comments
 (0)