1
1
package test .org .fugerit .java .doc .freemarker .process ;
2
2
3
- import static org .junit .Assert .fail ;
4
3
5
4
import java .io .*;
6
5
import java .time .LocalDateTime ;
29
28
import org .fugerit .java .doc .freemarker .process .FreemarkerDocProcessConfig ;
30
29
import org .fugerit .java .doc .freemarker .process .FreemarkerDocProcessConfigFacade ;
31
30
import org .fugerit .java .doc .freemarker .process .FreemarkerDocProcessConfigValidator ;
32
- import org .junit .Assert ;
33
- import org .junit .Test ;
34
31
35
32
import lombok .extern .slf4j .Slf4j ;
33
+ import org .junit .jupiter .api .Assertions ;
34
+ import org .junit .jupiter .api .Test ;
36
35
import test .org .fugerit .java .BasicTest ;
37
36
38
37
@ Slf4j
39
- public class TestFreemarkerDocProcessConfig extends BasicTest {
38
+ class TestFreemarkerDocProcessConfig extends BasicTest {
40
39
41
40
private static final String MAIN_CONFIG = "fj_doc_test/freemarker-doc-process.xml" ;
42
41
43
42
@ Test
44
- public void testConfigRead001 () throws Exception {
43
+ void testConfigRead001 () throws Exception {
45
44
String [] configList = { MAIN_CONFIG , "fj_doc_test/freemarker-doc-process-1.xml" , "fj_doc_test/freemarker-doc-process-2.xml" , "fj_doc_test/freemarker-doc-process-3.xml" };
46
45
for ( int k =0 ;k <configList .length ;k ++ ) {
47
46
String currentConfig = configList [k ];
@@ -50,7 +49,7 @@ public void testConfigRead001() throws Exception {
50
49
String chainId = "sample_chain" ;
51
50
String type = DocConfig .TYPE_HTML ;
52
51
log .info ( "config {}" , config .getChain ( chainId ) );
53
- Assert .assertNotNull ( config );
52
+ Assertions .assertNotNull ( config );
54
53
try (FileOutputStream fos = new FileOutputStream ( new File ( "target" , chainId +"_" +k +"." +type ) ) ) {
55
54
config .fullProcess ( chainId , DocProcessContext .newContext (), DocConfig .TYPE_HTML , fos );
56
55
}
@@ -59,7 +58,7 @@ public void testConfigRead001() throws Exception {
59
58
try (ByteArrayOutputStream fos = new ByteArrayOutputStream () ) {
60
59
DocProcessContext context = DocProcessContext .newContext ().withSourceType ( DocFacadeSource .SOURCE_TYPE_XML );
61
60
if ( k == 0 || k == 2 ) {
62
- Assert .assertThrows ( ConfigRuntimeException .class , () -> config .fullProcess ( chainIdError , context , DocConfig .TYPE_HTML , fos ) );
61
+ Assertions .assertThrows ( ConfigRuntimeException .class , () -> config .fullProcess ( chainIdError , context , DocConfig .TYPE_HTML , fos ) );
63
62
} else {
64
63
config .fullProcess ( chainIdError , context , DocConfig .TYPE_HTML , fos );
65
64
}
@@ -69,7 +68,7 @@ public void testConfigRead001() throws Exception {
69
68
}
70
69
71
70
@ Test
72
- public void testSource () throws Exception {
71
+ void testSource () throws Exception {
73
72
FreemarkerDocProcessConfig config = FreemarkerDocProcessConfigFacade .loadConfigSafe ( "cl://" +MAIN_CONFIG );
74
73
String [] chainId = { "xml" , "json" , "yaml" };
75
74
for ( int k =0 ;k <chainId .length ;k ++ ) {
@@ -84,12 +83,12 @@ public void testSource() throws Exception {
84
83
// test template does not exist
85
84
try ( ByteArrayOutputStream os = new ByteArrayOutputStream () ) {
86
85
DocProcessContext context = DocProcessContext .newContext ();
87
- Assert .assertThrows ( ConfigRuntimeException .class , () -> config .fullProcess ( "not-exists" , context , DocConfig .TYPE_HTML , os ) );
86
+ Assertions .assertThrows ( ConfigRuntimeException .class , () -> config .fullProcess ( "not-exists" , context , DocConfig .TYPE_HTML , os ) );
88
87
}
89
88
}
90
89
91
90
@ Test
92
- public void testSkipFM () throws Exception {
91
+ void testSkipFM () throws Exception {
93
92
DocProcessContext context = DocProcessContext .newContext ();
94
93
DocProcessData data = new DocProcessData ();
95
94
FreeMarkerConfigStep configStep = new FreeMarkerConfigStep ();
@@ -103,23 +102,23 @@ public void testSkipFM() throws Exception {
103
102
FreeMarkerSkipProcessStep step = new FreeMarkerSkipProcessStep ();
104
103
step .setParam01 ( "asciidoc-xml.ftl" );
105
104
step .process ( context , data );
106
- Assert .assertNotNull ( data .getCurrentXmlData () );
105
+ Assertions .assertNotNull ( data .getCurrentXmlData () );
107
106
}
108
107
109
108
@ Test
110
- public void testConfigFail01 () {
111
- Assert .assertThrows ( ConfigRuntimeException .class , () -> FreemarkerDocProcessConfigFacade .loadConfigSafe ( "cl://not-exists.xml" ) );
109
+ void testConfigFail01 () {
110
+ Assertions .assertThrows ( ConfigRuntimeException .class , () -> FreemarkerDocProcessConfigFacade .loadConfigSafe ( "cl://not-exists.xml" ) );
112
111
}
113
112
114
113
@ Test
115
- public void testConfigFail02 () {
114
+ void testConfigFail02 () {
116
115
Reader reader = null ;
117
- Assert .assertThrows ( ConfigException .class , () -> FreemarkerDocProcessConfigFacade .loadConfig ( reader ) );
116
+ Assertions .assertThrows ( ConfigException .class , () -> FreemarkerDocProcessConfigFacade .loadConfig ( reader ) );
118
117
}
119
118
120
119
@ Test
121
- public void testConfigSec () {
122
- Assert .assertNotNull ( FreemarkerDocProcessConfigFacade .loadConfigSafe ( "cl://fj_doc_test/freemarker-doc-process_sec.xml" ) );
120
+ void testConfigSec () {
121
+ Assertions .assertNotNull ( FreemarkerDocProcessConfigFacade .loadConfigSafe ( "cl://fj_doc_test/freemarker-doc-process_sec.xml" ) );
123
122
}
124
123
125
124
@@ -138,66 +137,66 @@ private void templateTesting( FreemarkerDocProcessConfig config ) {
138
137
runTestEx ( () -> {
139
138
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream () ) {
140
139
// need to make it work in the future!
141
- Assert .assertThrows ( NullPointerException .class , () -> {
140
+ Assertions .assertThrows ( NullPointerException .class , () -> {
142
141
config .process ( "test_01_inline" , DocConfig .TYPE_MD , context , baos , false );
143
142
} );
144
143
}
145
144
} );
146
- Assert .assertThrows ( ConfigException .class , () -> {
145
+ Assertions .assertThrows ( ConfigException .class , () -> {
147
146
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream () ) {
148
147
config .process ( "test_01_fail" , DocConfig .TYPE_MD , context , baos , false );
149
148
}
150
149
} );
151
150
}
152
151
153
152
@ Test
154
- public void testConfigRead002 () {
153
+ void testConfigRead002 () {
155
154
FreemarkerDocProcessConfig config =
156
155
FreemarkerDocProcessConfigFacade .loadConfigSafe ( "cl://fj_doc_test/freemarker-doc-process_alt.xml" );
157
- Assert .assertNotNull ( config );
156
+ Assertions .assertNotNull ( config );
158
157
this .templateTesting (config );
159
158
log .info ( "keys : {}" , config .getKeys () );
160
159
}
161
160
162
161
@ Test
163
- public void testConfigValidate001 () {
162
+ void testConfigValidate001 () {
164
163
try ( Reader xmlReader = new InputStreamReader ( ClassHelper .loadFromDefaultClassLoader ( "fj_doc_test/freemarker-doc-process.xml" ) ) ) {
165
164
FreemarkerDocProcessConfigValidator .logValidation ( xmlReader );
166
165
} catch (Exception e ) {
167
166
String message = "Error : " +e ;
168
167
log .error ( message , e );
169
- fail (message );
168
+ Assertions . fail (message );
170
169
}
171
170
}
172
171
173
172
@ Test
174
- public void testNewSimpleConfig () {
173
+ void testNewSimpleConfig () {
175
174
try {
176
- Assert .assertNotNull ( FreemarkerDocProcessConfigFacade .newSimpleConfig ( "simple-config-001" , "/template" ).getChainCache ( "test" ) );
175
+ Assertions .assertNotNull ( FreemarkerDocProcessConfigFacade .newSimpleConfig ( "simple-config-001" , "/template" ).getChainCache ( "test" ) );
177
176
} catch (Exception e ) {
178
177
this .failEx (e );
179
178
}
180
179
}
181
180
182
181
@ Test
183
- public void testNewSimpleConfigVersion () {
182
+ void testNewSimpleConfigVersion () {
184
183
try {
185
- Assert .assertNotNull ( FreemarkerDocProcessConfigFacade .newSimpleConfig ( "simple-config-002" , "/template" , FreeMarkerConfigStep .ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 ).getChainCache ( "test" ) );
184
+ Assertions .assertNotNull ( FreemarkerDocProcessConfigFacade .newSimpleConfig ( "simple-config-002" , "/template" , FreeMarkerConfigStep .ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 ).getChainCache ( "test" ) );
186
185
} catch (Exception e ) {
187
186
this .failEx (e );
188
187
}
189
188
}
190
189
191
190
@ Test
192
- public void testProcess () {
191
+ void testProcess () {
193
192
SafeFunction .apply ( () -> {
194
193
FreemarkerDocProcessConfig config = FreemarkerDocProcessConfigFacade .newSimpleConfig ( "simple-config-003" , "/fj_doc_test/template/" );
195
194
config .getFacade ().registerHandler ( FreeMarkerHtmlTypeHandlerUTF8 .HANDLER );
196
195
// test full process
197
196
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream () ) {
198
197
DocProcessData data = config .fullProcess ( "test_02" ,
199
198
DocProcessContext .newContext (), DocConfig .TYPE_HTML , baos );
200
- Assert .assertNotEquals ( 0 , data .getCurrentXmlData ().length () );
199
+ Assertions .assertNotEquals ( 0 , data .getCurrentXmlData ().length () );
201
200
}
202
201
// test process 1
203
202
// handler list :
@@ -210,27 +209,27 @@ public void testProcess() {
210
209
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream () ) {
211
210
DocProcessData data = new DocProcessData ();
212
211
config .process ( "test_02" , DocProcessContext .newContext ( "testKey" , "<test/>" ), data , FreeMarkerHtmlTypeHandlerUTF8 .HANDLER , DocOutput .newOutput (baos ) );
213
- Assert .assertNotEquals ( 0 , data .getCurrentXmlData ().length () );
212
+ Assertions .assertNotEquals ( 0 , data .getCurrentXmlData ().length () );
214
213
File file = new File ( "target/test_02_handler_" +k +".xml" );
215
214
FileIO .writeBytes ( data .getCurrentXmlData ().getBytes () , file );
216
215
}
217
216
}
218
217
} );
219
- Assert .assertTrue ( Boolean .TRUE );
218
+ Assertions .assertTrue ( Boolean .TRUE );
220
219
}
221
220
222
221
@ Test
223
- public void testLoadConfigKo () {
222
+ void testLoadConfigKo () {
224
223
String fullPath = "fj_doc_test/freemarker-doc-process_ko.xml" ;
225
- Assert .assertThrows ( ConfigRuntimeException .class , () -> FreemarkerDocProcessConfigFacade .loadConfigSafe ( fullPath ) );
224
+ Assertions .assertThrows ( ConfigRuntimeException .class , () -> FreemarkerDocProcessConfigFacade .loadConfigSafe ( fullPath ) );
226
225
try {
227
226
FreemarkerDocProcessConfigFacade .loadConfigSafe ( "cl://not-exists.xml" );
228
227
} catch (ConfigRuntimeException e ) {
229
228
log .error ( String .format ( "Error : %s" , e ), e );
230
- Assert .assertTrue ( e .getMessage ().contains ( FreemarkerDocProcessConfigFacade .ERROR_CONFIG_PATH_NOT_FOUND_BASE_MESSAGE ) );
229
+ Assertions .assertTrue ( e .getMessage ().contains ( FreemarkerDocProcessConfigFacade .ERROR_CONFIG_PATH_NOT_FOUND_BASE_MESSAGE ) );
231
230
}
232
231
Exception testEx = new ConfigRuntimeException ( "ex1" , new ConfigRuntimeException ( "ex0" ) );
233
- Assert .assertEquals ( ConfigRuntimeException .class , FreemarkerDocProcessConfigFacade .EX_CONSUMER_LOAD_CONFIG .apply ( testEx ).getClass () );
232
+ Assertions .assertEquals ( ConfigRuntimeException .class , FreemarkerDocProcessConfigFacade .EX_CONSUMER_LOAD_CONFIG .apply ( testEx ).getClass () );
234
233
}
235
234
236
235
}
0 commit comments