Search in sources :

Example 1 with ShellTable

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

the class ShellTableTest method testNoFormat.

@Test
public void testNoFormat() {
    ShellTable table = new ShellTable();
    table.column(new Col("first"));
    table.column(new Col("second"));
    table.addRow().addContent("first column", "second column");
    StringWriter writer = new StringWriter();
    PrintStream out = new PrintStream(new WriterOutputStream(writer));
    table.print(out, false);
    out.flush();
    String expected = "first column\tsecond column\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) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 2 with ShellTable

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

the class ShellTableTest method testTooSmall.

@Test
public void testTooSmall() {
    ShellTable table = new ShellTable().size(2);
    table.column(new Col("1").maxSize(5));
    table.column(new Col("2").alignRight());
    table.addRow().addContent("quite long", "and here an even longer text");
    StringWriter writer = new StringWriter();
    PrintStream out = new PrintStream(new WriterOutputStream(writer));
    table.print(out, true);
    out.flush();
    // 
    String expected = // 
    "1     | \n" + // 
    "--------\n" + "quite | \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) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Example 3 with ShellTable

use of org.apache.karaf.shell.table.ShellTable in project bgpcep by opendaylight.

the class PcepStateUtils method displayNodeState.

private static void displayNodeState(final String topologyId, final String nodeId, final PcepSessionState pcepSessionState, final PrintStream stream) {
    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();
    showNodeState(table, topologyId, nodeId, pcepSessionState);
    addHeader(table, "Local preferences");
    final LocalPref localPref = pcepSessionState.getLocalPref();
    showPreferences(table, localPref);
    final PcepEntityIdStatsAug entAug = localPref.getAugmentation(PcepEntityIdStatsAug.class);
    if (entAug != null) {
        table.addRow().addContent("Speaker Entity Identifier", Arrays.toString(entAug.getSpeakerEntityIdValue()));
    }
    addHeader(table, "Peer preferences");
    final PeerPref peerPref = pcepSessionState.getPeerPref();
    showPreferences(table, peerPref);
    showCapabilities(table, pcepSessionState.getPeerCapabilities());
    final Messages messages = pcepSessionState.getMessages();
    showMessages(table, messages);
    final ErrorMessages error = messages.getErrorMessages();
    showErrorMessages(table, error);
    final ReplyTime reply = messages.getReplyTime();
    showReplyMessages(table, reply);
    table.print(stream);
}
Also used : ErrorMessages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.error.messages.grouping.ErrorMessages) PcepEntityIdStatsAug(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stateful.stats.rev171113.PcepEntityIdStatsAug) ShellTable(org.apache.karaf.shell.table.ShellTable) Messages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.Messages) ErrorMessages(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.error.messages.grouping.ErrorMessages) LocalPref(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.LocalPref) PeerPref(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.PeerPref) ReplyTime(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.reply.time.grouping.ReplyTime)

Example 4 with ShellTable

use of org.apache.karaf.shell.table.ShellTable 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)

Example 5 with ShellTable

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

the class ShellTableTest method testNoFormatWithCustomSeparator.

@Test
public void testNoFormatWithCustomSeparator() {
    ShellTable table = new ShellTable();
    table.separator(";");
    table.column(new Col("first"));
    table.column(new Col("second"));
    table.addRow().addContent("first column", "second column");
    StringWriter writer = new StringWriter();
    PrintStream out = new PrintStream(new WriterOutputStream(writer));
    table.print(out, false);
    out.flush();
    String expected = "first column;second column\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) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) Test(org.junit.Test)

Aggregations

ShellTable (org.apache.karaf.shell.table.ShellTable)10 PrintStream (java.io.PrintStream)6 StringWriter (java.io.StringWriter)6 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)6 Col (org.apache.karaf.shell.table.Col)6 Test (org.junit.Test)6 Row (org.apache.karaf.shell.table.Row)1 State (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State)1 State (org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.State)1 BgpNeighborStateAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.BgpNeighborStateAugmentation)1 NeighborStateAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.NeighborStateAugmentation)1 PcepEntityIdStatsAug (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stateful.stats.rev171113.PcepEntityIdStatsAug)1 ErrorMessages (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.error.messages.grouping.ErrorMessages)1 LocalPref (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.LocalPref)1 Messages (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.Messages)1 PeerPref (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.PeerPref)1 ReplyTime (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.reply.time.grouping.ReplyTime)1