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));
}
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));
}
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);
}
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));
}
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));
}
Aggregations