|
3 | 3 | import lombok.extern.slf4j.Slf4j; |
4 | 4 | import org.fugerit.java.core.cfg.ConfigRuntimeException; |
5 | 5 | import org.fugerit.java.core.db.daogen.BasicDaoResult; |
| 6 | +import org.fugerit.java.core.lang.ex.CodeRuntimeException; |
6 | 7 | import org.fugerit.java.core.lang.helpers.ClassHelper; |
| 8 | +import org.fugerit.java.core.util.result.Result; |
7 | 9 | import org.fugerit.java.doc.base.facade.DocFacadeSource; |
8 | 10 | import org.fugerit.java.doc.base.feature.DocFeatureRuntimeException; |
9 | 11 | import org.fugerit.java.doc.base.feature.FeatureConfig; |
| 12 | +import org.fugerit.java.doc.base.feature.tableintegritycheck.TableIntegrityCheck; |
| 13 | +import org.fugerit.java.doc.base.feature.tableintegritycheck.TableIntegrityCheckConstants; |
10 | 14 | import org.fugerit.java.doc.base.model.DocBase; |
| 15 | +import org.fugerit.java.doc.base.model.DocTable; |
| 16 | +import org.fugerit.java.doc.base.typehelper.generic.GenericConsts; |
11 | 17 | import org.junit.jupiter.api.Assertions; |
12 | 18 | import org.junit.jupiter.api.Test; |
13 | 19 |
|
|
22 | 28 | @Slf4j |
23 | 29 | class TableCheckIntegrityTest { |
24 | 30 |
|
25 | | - private int testWorker( String xmlPath ) { |
26 | | - String fullCLPath = String.format( "feature-info/table-check-integrity/%s.xml", xmlPath ); |
27 | | - log.info( "xmlPath: {}, fullPath: {}", xmlPath, fullCLPath ); |
| 31 | + private DocBase readDocBase( String fullCLPath ) { |
28 | 32 | try (Reader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( fullCLPath ) ) ) { |
29 | 33 | DocFacadeSource docFacadeSource = DocFacadeSource.getInstance(); |
30 | 34 | DocBase docBase = docFacadeSource.parseRE( reader, DocFacadeSource.SOURCE_TYPE_XML, FeatureConfig.DEFAULT ); |
31 | | - log.info( "docBase:{}", docBase ); |
32 | | - return BasicDaoResult.RESULT_CODE_OK; |
| 35 | + return docBase; |
33 | 36 | } catch (IOException e) { |
34 | 37 | throw ConfigRuntimeException.convertEx( e ); |
35 | 38 | } |
36 | 39 | } |
37 | 40 |
|
| 41 | + private int testWorker( String xmlPath ) { |
| 42 | + String fullCLPath = String.format( "feature-info/table-check-integrity/%s.xml", xmlPath ); |
| 43 | + log.info( "xmlPath: {}, fullPath: {}", xmlPath, fullCLPath ); |
| 44 | + DocBase docBase = readDocBase( fullCLPath ); |
| 45 | + log.info( "docBase:{}", docBase ); |
| 46 | + return BasicDaoResult.RESULT_CODE_OK; |
| 47 | + } |
| 48 | + |
38 | 49 | @Test |
39 | 50 | void testOk() { |
40 | 51 | Assertions.assertEquals( BasicDaoResult.RESULT_CODE_OK, this.testWorker( "colspan-rowspan-sample-ok" ) ); |
41 | 52 | Assertions.assertTrue( Boolean.TRUE ); |
42 | 53 | } |
43 | 54 |
|
| 55 | + @Test |
| 56 | + void testConfiguration() { |
| 57 | + FeatureConfig featureConfig = new FeatureConfig() { |
| 58 | + @Override |
| 59 | + public String getTableCheckIntegrity() { |
| 60 | + return TableIntegrityCheckConstants.TABLE_INTEGRITY_CHECK_FAIL; |
| 61 | + } |
| 62 | + }; |
| 63 | + DocBase docBase = readDocBase( "feature-info/table-check-integrity/colspan-rowspan-sample-ko-noconfig.xml" ); |
| 64 | + DocTable docTable = (DocTable) docBase.getDocBody().getElementList().stream().filter( e -> e instanceof DocTable ).findFirst().get(); |
| 65 | + // global configuration set to fail |
| 66 | + Assertions.assertThrows( DocFeatureRuntimeException.class, () -> TableIntegrityCheck.apply( docBase, docTable, featureConfig ) ); |
| 67 | + // override configuration for this document, will not fail but result != OK |
| 68 | + docBase.getStableInfo().setProperty(GenericConsts.DOC_TABLE_CHECK_INTEGRITY, TableIntegrityCheckConstants.TABLE_INTEGRITY_CHECK_WARN ); |
| 69 | + Assertions.assertNotEquals(Result.RESULT_CODE_OK, TableIntegrityCheck.apply( docBase, docTable, featureConfig ) ); |
| 70 | + } |
| 71 | + |
44 | 72 | @Test |
45 | 73 | void testKoNoException() { |
46 | 74 | Arrays.asList( "colspan-rowspan-sample-ko-disabled", "colspan-rowspan-sample-ko-warn" ) |
|
0 commit comments