dumps the content of blobs, and reworks table formatting to add spaces around lines
[squelch.git] / src / test / java / net / jaekl / squelch / stmt / TabularTest.java
index f0e05bffd1f0e8500e96fc767f350dd257e84997..b72add390ab0aefcc64d8c59e20a96c0d1f71ff2 100644 (file)
@@ -10,6 +10,11 @@ import java.nio.charset.StandardCharsets;
 import java.sql.SQLException;
 import java.sql.Types;
 
+import javax.sql.rowset.serial.SerialBlob;
+import javax.sql.rowset.serial.SerialException;
+
+import junit.framework.Assert;
+
 import net.jaekl.squelch.sql.Column;
 import net.jaekl.squelch.sql.Row;
 
@@ -110,12 +115,12 @@ public class TabularTest {
                        pw.close();
                        baos.close();
                        String actual = baos.toString();
-                       assertEquals(  "+-------+---------+----------+\n"
-                                            + "| EmpId |FirstName| LastName |\n"
-                                            + "+-------+---------+----------+\n"
-                                            + "|12345  |Fred     |Flintstone|\n"
-                                            + "|7654321|Barney   |Rubble    |\n"
-                                            + "+-------+---------+----------+\n"
+                       assertEquals(  "+---------+-----------+------------+\n"
+                                            + "|  EmpId  | FirstName |  LastName  |\n"
+                                            + "+---------+-----------+------------+\n"
+                                            + "| 12345   | Fred      | Flintstone |\n"
+                                            + "| 7654321 | Barney    | Rubble     |\n"
+                                            + "+---------+-----------+------------+\n"
                                             + "2 row(s) returned.\n",
                                             actual);
                }
@@ -131,6 +136,53 @@ public class TabularTest {
                assertEquals("------", tabular.repChar('-', 6));
        }
        
+       @Test
+       public void test_stringify() throws SerialException, SQLException {
+               Tabular tabular = new TabularMock();
+               
+               String[] data = {
+                       "This is the way the world ends, not with a bang but a whimper.",
+                       
+                       "To be, or not to be, that is the question:\n" +
+                       "Whether 'tis Nobler in the mind to suffer\n" +
+                       "The Slings and Arrows of outrageous Fortune,\n" +
+                       "Or to take Arms against a Sea of troubles,\n" +
+                       "And by opposing end them: to die, to sleep\n" +
+                       "No more; and by a sleep, to say we end\n" +
+                       "The Heart-ache, and the thousand Natural shocks\n" +
+                       "That Flesh is heir to? 'Tis a consummation\n" +
+                       "Devoutly to be wished. To die, to sleep,\n" +
+                       "To sleep, perchance to Dream; aye, there's the rub,\n" +
+                       "For in that sleep of death, what dreams may come,\n" +
+                       "When we have shuffled off this mortal coil,\n" +
+                       "Must give us pause. There's the respect\n" +
+                       "That makes Calamity of so long life:\n",
+                       
+                       "ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ\n" +
+                       "πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν:\n" +
+                       "πολλῶν δ᾽ ἀνθρώπων ἴδεν ἄστεα καὶ νόον ἔγνω,\n" +
+                       "πολλὰ δ᾽ ὅ γ᾽ ἐν πόντῳ πάθεν ἄλγεα ὃν κατὰ θυμόν,\n" +
+                       "5ἀρνύμενος ἥν τε ψυχὴν καὶ νόστον ἑταίρων.\n" +
+                       "ἀλλ᾽ οὐδ᾽ ὣς ἑτάρους ἐρρύσατο, ἱέμενός περ:\n" +
+                       "αὐτῶν γὰρ σφετέρῃσιν ἀτασθαλίῃσιν ὄλοντο,\n" +
+                       "νήπιοι, οἳ κατὰ βοῦς Ὑπερίονος Ἠελίοιο\n" +
+                       "ἤσθιον: αὐτὰρ ὁ τοῖσιν ἀφείλετο νόστιμον ἦμαρ.\n" +
+                       "10τῶν ἁμόθεν γε, θεά, θύγατερ Διός, εἰπὲ καὶ ἡμῖν.\n"
+               };
+               
+               for (String datum : data) 
+               {
+                       byte[] content = datum.getBytes(StandardCharsets.UTF_8);
+                       SerialBlob sblob = new SerialBlob(content);
+                       
+                       String expected = datum;
+                       String actual = tabular.stringify(sblob);
+                       
+                       Assert.assertEquals(expected, actual);
+               }
+       }
+       
+       
        private TabularMock createEmpTable()
        {
                TabularMock tabular = new TabularMock();