99import java .io .IOException ;
1010import java .nio .file .Files ;
1111import java .nio .file .Paths ;
12+ import java .util .Objects ;
1213
1314public class TvdFormatTest extends AbstractTvdFormatTest {
1415
16+ private final String EXPECTED_QUERY_SQL = """
17+ select d.department_name,
18+ v.employee_id,
19+ v.last_name
20+ from departments d
21+ cross apply (
22+ select *
23+ from employees e
24+ where e.department_id = d.department_id
25+ ) v
26+ where d.department_name in ('Marketing', 'Operations', 'Public Relations')
27+ order by d.department_name, v.employee_id;
28+ """ ;
29+
30+ private final String XML = Objects .requireNonNull (
31+ Thread .currentThread ().getContextClassLoader ().getResource ("trivadis_advanced_format.xml" )).getPath ();
32+
33+ private final String ARBORI = Objects .requireNonNull (
34+ Thread .currentThread ().getContextClassLoader ().getResource ("trivadis_custom_format.arbori" )).getPath ();
35+
36+
1537 @ Test
1638 public void jsonArrayDirTest () throws ScriptException , IOException {
1739 var configFileContent = """
@@ -21,13 +43,11 @@ public void jsonArrayDirTest() throws ScriptException, IOException {
2143 """ .replace ("#TEMP_DIR#" , tempDir .toString ());
2244 var configFile = Paths .get (tempDir + File .separator + "config.json" );
2345 Files .write (configFile , configFileContent .getBytes ());
24- var args = new String []{tempDir + File .separator + "config.json" ,
25- "xml=" + tempDir + File .separator + "trivadis_advanced_format.xml" ,
26- "arbori=" + tempDir + File .separator + "trivadis_custom_format.arbori" };
46+ var args = new String []{tempDir + File .separator + "config.json" , "xml=" + XML , "arbori=" + ARBORI };
2747 TvdFormat .main (args );
28- var expected = getExpectedContent ("query.sql" );
2948 var actual = getFormattedContent ("query.sql" );
30- Assertions .assertEquals (expected , actual );
49+ Assertions .assertEquals (EXPECTED_QUERY_SQL , actual );
50+ Assertions .assertTrue (getConsoleOutput ().contains ("1 of 4" ));
3151 }
3252
3353 @ Test
@@ -39,32 +59,34 @@ public void jsonArrayFileTest() throws ScriptException, IOException {
3959 """ .replace ("#TEMP_DIR#" , tempDir .toString ()).replace ("#FILE_SEP#" , File .separator );
4060 var configFile = Paths .get (tempDir + File .separator + "config.json" );
4161 Files .write (configFile , configFileContent .getBytes ());
42- var args = new String []{tempDir + File .separator + "config.json" ,
43- "xml=" + tempDir + File .separator + "trivadis_advanced_format.xml" ,
44- "arbori=" + tempDir + File .separator + "trivadis_custom_format.arbori" };
62+ var args = new String []{tempDir + File .separator + "config.json" , "xml=" + XML , "arbori=" + ARBORI };
4563 TvdFormat .main (args );
46- var expected = getExpectedContent ("query.sql" );
4764 var actual = getFormattedContent ("query.sql" );
48- Assertions .assertEquals (expected , actual );
65+ Assertions .assertEquals (EXPECTED_QUERY_SQL , actual );
66+ Assertions .assertTrue (getConsoleOutput ().contains ("1 of 1" ));
4967 }
5068
5169 @ Test
5270 public void jsonObjectFileTest () throws ScriptException , IOException {
5371 var configFileContent = """
5472 {
55- "xml": "#TEMP_DIR##FILE_SEP#trivadis_advanced_format.xml ",
56- "arbori": "#TEMP_DIR##FILE_SEP#trivadis_custom_format.arbori ",
73+ "xml": "#XML# ",
74+ "arbori": "#ARBORI# ",
5775 "files": [
58- "#TEMP_DIR##FILE_SEP#query.sql"
76+ "#TEMP_DIR##FILE_SEP#query.sql",
77+ "#TEMP_DIR##FILE_SEP#package_body.pkb"
5978 ]
6079 }
61- """ .replace ("#TEMP_DIR#" , tempDir .toString ()).replace ("#FILE_SEP#" , File .separator );
80+ """ .replace ("#XML#" , XML )
81+ .replace ("#ARBORI#" , ARBORI )
82+ .replace ("#TEMP_DIR#" , tempDir .toString ())
83+ .replace ("#FILE_SEP#" , File .separator );
6284 var configFile = Paths .get (tempDir + File .separator + "config.json" );
6385 Files .write (configFile , configFileContent .getBytes ());
6486 var args = new String []{tempDir + File .separator + "config.json" };
6587 TvdFormat .main (args );
66- var expected = getExpectedContent ("query.sql" );
6788 var actual = getFormattedContent ("query.sql" );
68- Assertions .assertEquals (expected , actual );
89+ Assertions .assertEquals (EXPECTED_QUERY_SQL , actual );
90+ Assertions .assertTrue (getConsoleOutput ().contains ("1 of 2" ));
6991 }
7092}
0 commit comments