Search in sources :

Example 1 with Row

use of org.apache.karaf.shell.table.Row in project karaf by apache.

the class ShellTableTest method testTable.

@Test
public void testTable() {
    ShellTable table = new ShellTable();
    table.column(new Col("id").alignRight().maxSize(5));
    table.column(new Col("Name").maxSize(20));
    table.column(new Col("Centered").alignCenter());
    table.addRow().addContent(1, "Test", "Description");
    table.addRow().addContent(20, "My name", "Description");
    Row row = table.addRow();
    row.addContent(123456789);
    row.addContent("A very long text that should be cut");
    row.addContent("A very long text that should not be cut");
    StringWriter writer = new StringWriter();
    PrintStream out = new PrintStream(new WriterOutputStream(writer));
    table.print(out, true);
    out.flush();
    String expected = "   id | Name                 |                Centered                \n" + "----------------------------------------------------------------------\n" + "    1 | Test                 |               Description              \n" + "   20 | My name              |               Description              \n" + "12345 | A very long text tha | A very long text that should not be cut\n";
    Assert.assertEquals(expected, getString(writer));
}
Also used : Col(org.apache.karaf.shell.table.Col) PrintStream(java.io.PrintStream) ShellTable(org.apache.karaf.shell.table.ShellTable) StringWriter(java.io.StringWriter) Row(org.apache.karaf.shell.table.Row) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Aggregations

PrintStream (java.io.PrintStream)1 StringWriter (java.io.StringWriter)1 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)1 Col (org.apache.karaf.shell.table.Col)1 Row (org.apache.karaf.shell.table.Row)1 ShellTable (org.apache.karaf.shell.table.ShellTable)1 Test (org.junit.Test)1