88import java .nio .charset .StandardCharsets ;
99import java .nio .file .Files ;
1010import java .nio .file .Path ;
11+ import java .util .function .IntSupplier ;
1112
1213import static org .assertj .core .api .Assertions .assertThat ;
1314
1415class CliIT {
1516
17+ @ Test
18+ void fullPipeline (@ TempDir Path tmp ) throws Exception {
19+ // Given
20+ Path csvIn = tmp .resolve ("data.csv" );
21+ Files .writeString (csvIn , "id,name\n 1,Alice\n 2,Bob\n " );
22+
23+ // Step 1: import CSV → vortex
24+ assertThat (ImportCommand .run (new String []{"import" , csvIn .toString ()})).isZero ();
25+ Path vortex = tmp .resolve ("data.vortex" );
26+ assertThat (vortex ).exists ();
27+
28+ // Step 2: inspect
29+ String inspect = captureStdout (
30+ () -> InspectCommand .run (new String []{"inspect" , vortex .toString ()}));
31+ assertThat (inspect ).contains ("Schema:" ).contains ("id" ).contains ("name" );
32+
33+ // Step 3: schema
34+ String schema = captureStdout (
35+ () -> SchemaCommand .run (new String []{"schema" , vortex .toString ()}));
36+ assertThat (schema .strip ()).isEqualTo ("struct<id: I64, name: utf8>" );
37+
38+ // Step 4: export vortex → CSV
39+ String exported = captureStdout (
40+ () -> ExportCommand .run (new String []{"export" , vortex .toString ()}));
41+ String [] exportedLines = exported .split ("\r ?\n " );
42+ assertThat (exportedLines ).hasSize (3 );
43+ assertThat (exportedLines [0 ]).isEqualTo ("id,name" );
44+ assertThat (exportedLines [1 ]).isEqualTo ("1,Alice" );
45+ assertThat (exportedLines [2 ]).isEqualTo ("2,Bob" );
46+
47+ // Step 5: import the exported CSV again and verify schema is preserved
48+ Path csvIn2 = tmp .resolve ("data2.csv" );
49+ Files .writeString (csvIn2 , exported );
50+ assertThat (ImportCommand .run (new String []{"import" , csvIn2 .toString ()})).isZero ();
51+ Path vortex2 = tmp .resolve ("data2.vortex" );
52+ String schema2 = captureStdout (
53+ () -> SchemaCommand .run (new String []{"schema" , vortex2 .toString ()}));
54+ assertThat (schema2 .strip ()).isEqualTo (schema .strip ());
55+ }
56+
1657 @ Test
1758 void importExportRoundTrip (@ TempDir Path tmp ) throws Exception {
1859 // Given
1960 Path csvIn = tmp .resolve ("data.csv" );
2061 Files .writeString (csvIn , "id,name\n 1,Alice\n 2,Bob\n 3,Charlie\n " );
2162
22- // When — import CSV to Vortex
23- int importExit = ImportCommand .run (new String []{"import" , csvIn .toString ()});
24- assertThat (importExit ).isZero ();
25-
26- // When — export Vortex back to CSV via stdout
63+ // When
64+ assertThat (ImportCommand .run (new String []{"import" , csvIn .toString ()})).isZero ();
2765 Path vortexPath = tmp .resolve ("data.vortex" );
28- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
29- PrintStream saved = System .out ;
30- System .setOut (new PrintStream (baos , true , StandardCharsets .UTF_8 ));
31- int exportExit ;
32- try {
33- exportExit = ExportCommand .run (new String []{"export" , vortexPath .toString ()});
34- } finally {
35- System .setOut (saved );
36- }
66+ String exported = captureStdout (
67+ () -> ExportCommand .run (new String []{"export" , vortexPath .toString ()}));
3768
3869 // Then
39- assertThat (exportExit ).isZero ();
40- String [] lines = baos .toString (StandardCharsets .UTF_8 ).split ("\r ?\n " );
70+ String [] lines = exported .split ("\r ?\n " );
4171 assertThat (lines ).hasSize (4 );
4272 assertThat (lines [0 ]).isEqualTo ("id,name" );
4373 assertThat (lines [1 ]).isEqualTo ("1,Alice" );
@@ -47,53 +77,45 @@ void importExportRoundTrip(@TempDir Path tmp) throws Exception {
4777
4878 @ Test
4979 void inspectPrintsSchema (@ TempDir Path tmp ) throws Exception {
50- // Given — create a vortex file via import
80+ // Given
5181 Path csvIn = tmp .resolve ("data.csv" );
5282 Files .writeString (csvIn , "id,score\n 1,9.5\n " );
5383 ImportCommand .run (new String []{"import" , csvIn .toString ()});
5484 Path vortexPath = tmp .resolve ("data.vortex" );
5585
5686 // When
57- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
58- PrintStream saved = System .out ;
59- System .setOut (new PrintStream (baos , true , StandardCharsets .UTF_8 ));
60- int exit ;
61- try {
62- exit = InspectCommand .run (new String []{"inspect" , vortexPath .toString ()});
63- } finally {
64- System .setOut (saved );
65- }
87+ String output = captureStdout (
88+ () -> InspectCommand .run (new String []{"inspect" , vortexPath .toString ()}));
6689
6790 // Then
68- assertThat (exit ).isZero ();
69- String output = baos .toString (StandardCharsets .UTF_8 );
70- assertThat (output ).contains ("Schema:" );
71- assertThat (output ).contains ("id" );
72- assertThat (output ).contains ("score" );
91+ assertThat (output ).contains ("Schema:" ).contains ("id" ).contains ("score" );
7392 }
7493
7594 @ Test
7695 void schemaPrintsMachineReadableDType (@ TempDir Path tmp ) throws Exception {
77- // Given — create a vortex file via import
96+ // Given
7897 Path csvIn = tmp .resolve ("data.csv" );
7998 Files .writeString (csvIn , "id,name\n 1,Alice\n " );
8099 ImportCommand .run (new String []{"import" , csvIn .toString ()});
81100 Path vortexPath = tmp .resolve ("data.vortex" );
82101
83102 // When
103+ String output = captureStdout (
104+ () -> SchemaCommand .run (new String []{"schema" , vortexPath .toString ()}));
105+
106+ // Then
107+ assertThat (output .strip ()).isEqualTo ("struct<id: I64, name: utf8>" );
108+ }
109+
110+ private static String captureStdout (IntSupplier action ) {
84111 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
85112 PrintStream saved = System .out ;
86113 System .setOut (new PrintStream (baos , true , StandardCharsets .UTF_8 ));
87- int exit ;
88114 try {
89- exit = SchemaCommand . run ( new String []{ "schema" , vortexPath . toString ()} );
115+ action . getAsInt ( );
90116 } finally {
91117 System .setOut (saved );
92118 }
93-
94- // Then
95- assertThat (exit ).isZero ();
96- assertThat (baos .toString (StandardCharsets .UTF_8 ).strip ())
97- .isEqualTo ("struct<id: I64, name: utf8>" );
119+ return baos .toString (StandardCharsets .UTF_8 );
98120 }
99121}
0 commit comments