diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java index 6020bb589a6..84c7fafdbec 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java @@ -27,7 +27,6 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; -import org.apache.gravitino.cli.outputs.OutputProperty; /* Gravitino Command line */ public class GravitinoCommandLine extends TestableCommandLine { @@ -108,7 +107,7 @@ public static void displayHelp(Options options) { /** Executes the appropriate command based on the command type. */ private void executeCommand() { - OutputProperty outputProperty = OutputProperty.fromLine(line); + if (CommandActions.HELP.equals(command)) { handleHelpCommand(); } else if (line.hasOption(GravitinoOptions.OWNER)) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java index 0a501ceddbc..62bf5193c8f 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java @@ -26,7 +26,6 @@ import com.google.common.base.Joiner; import java.io.File; import java.io.OutputStream; - import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.cli.GravitinoConfig; import org.apache.gravitino.cli.KerberosData; diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/Style.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/BorderStyle.java similarity index 93% rename from clients/cli/src/main/java/org/apache/gravitino/cli/outputs/Style.java rename to clients/cli/src/main/java/org/apache/gravitino/cli/outputs/BorderStyle.java index 16989f0a866..d03d9d2d065 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/Style.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/BorderStyle.java @@ -29,7 +29,7 @@ * Defines different styles for formatting and displaying data. Each style contains a specific set * of characters for rendering and configuration for whether to show boundaries between data rows. */ -public enum Style { +public enum BorderStyle { FANCY(FANCY_ASCII, false), FANCY2(FANCY_ASCII, true), BASIC(BASIC_ASCII, true), @@ -44,13 +44,13 @@ public enum Style { private final boolean showRowBoundaries; /** - * Constructs a {@link Style} instance. + * Constructs a {@link BorderStyle} instance. * * @param characters the list of characters to use for the style * @param showRowBoundaries {@code true} to show boundaries between data rows, {@code false} * otherwise */ - Style(ImmutableList characters, boolean showRowBoundaries) { + BorderStyle(ImmutableList characters, boolean showRowBoundaries) { this.characters = characters; this.showRowBoundaries = showRowBoundaries; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java index d4a003d486f..e7e1782691b 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/OutputProperty.java @@ -37,7 +37,7 @@ public class OutputProperty { false, false, -1, - Style.BASIC2, + BorderStyle.BASIC2, HorizontalAlign.CENTER, HorizontalAlign.LEFT, HorizontalAlign.CENTER, @@ -48,7 +48,7 @@ public class OutputProperty { private boolean sort; private boolean quiet; private int limit; - private Style style; + private BorderStyle borderStyle; private HorizontalAlign headerAlign; private HorizontalAlign dataAlign; private final HorizontalAlign footerAlign; @@ -62,7 +62,7 @@ public class OutputProperty { * @param sort Whether to sort the output. * @param quiet Whether to suppress output. * @param limit Maximum number of rows (-1 for unlimited). - * @param style Border style for tables. + * @param borderStyle Border style for tables. * @param headerAlign Header text alignment. * @param dataAlign Data cell alignment. * @param footerAlign Footer text alignment. @@ -74,7 +74,7 @@ public OutputProperty( boolean sort, boolean quiet, int limit, - Style style, + BorderStyle borderStyle, HorizontalAlign headerAlign, HorizontalAlign dataAlign, HorizontalAlign footerAlign, @@ -84,7 +84,7 @@ public OutputProperty( this.sort = sort; this.quiet = quiet; this.limit = limit; - this.style = style; + this.borderStyle = borderStyle; this.headerAlign = headerAlign; this.dataAlign = dataAlign; this.footerAlign = footerAlign; @@ -130,8 +130,8 @@ public int getLimit() { return limit; } - public Style getStyle() { - return style; + public BorderStyle getStyle() { + return borderStyle; } public HorizontalAlign getHeaderAlign() { @@ -174,8 +174,8 @@ public void setLimit(int limit) { this.limit = limit; } - public void setStyle(Style style) { - this.style = style; + public void setStyle(BorderStyle borderStyle) { + this.borderStyle = borderStyle; } public void setRowNumbersEnabled(boolean rowNumbersEnabled) { @@ -200,7 +200,7 @@ public OutputProperty copy() { sort, quiet, limit, - style, + borderStyle, headerAlign, dataAlign, footerAlign, diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java index 4ec7f649e56..25ee3ad053a 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java @@ -61,7 +61,7 @@ public abstract class TableFormat extends BaseOutputFormat { public static final int PADDING = 1; - private final Style style; + private final BorderStyle borderStyle; private final boolean rowNumbersEnabled; protected final OutputProperty property; @@ -99,7 +99,7 @@ public static void output(Object entity, OutputProperty property) { public TableFormat(OutputProperty property) { super(property.isQuiet(), property.getLimit(), property.isSort()); this.property = property; - this.style = property.getStyle(); + this.borderStyle = property.getStyle(); this.rowNumbersEnabled = property.isRowNumbersEnabled(); } @@ -109,7 +109,7 @@ public TableFormat(OutputProperty property) { * @param columns the columns to print. * @return the table formatted output string. */ - public String formatTable(Column... columns) { + public String getTableFormat(Column... columns) { checkColumns(columns); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -125,7 +125,7 @@ public String formatTable(Column... columns) { .filter(StringUtils::isNotBlank) .toArray(String[]::new); - List borders = style.getCharacters(); + List borders = borderStyle.getCharacters(); checkHeaders(headers, columns); if (headers.length != columns.length) { @@ -149,10 +149,10 @@ public String formatTable(Column... columns) { writeUpperBorder(osw, borders, System.lineSeparator(), columns); writeHeader(osw, borders, System.lineSeparator(), columns); writeHeaderBorder(osw, borders, System.lineSeparator(), columns); - writeData(osw, style, columns, System.lineSeparator()); + writeData(osw, borderStyle, columns, System.lineSeparator()); if (footers.length > 0) { - writeRowSeparator(osw, style, System.lineSeparator(), columns); + writeRowSeparator(osw, borderStyle, System.lineSeparator(), columns); writeFooter(osw, borders, columns); } @@ -266,15 +266,15 @@ private static void writeHeaderBorder( * Writes the separator line between data rows. * * @param writer the writer for output - * @param style the table style containing border characters + * @param borderStyle the table style containing border characters * @param lineSeparator the system-specific line separator * @param columns the array of columns defining the table structure * @throws IOException if an error occurs while writing to the output */ private static void writeRowSeparator( - OutputStreamWriter writer, Style style, String lineSeparator, Column[] columns) + OutputStreamWriter writer, BorderStyle borderStyle, String lineSeparator, Column[] columns) throws IOException { - List borders = style.getCharacters(); + List borders = borderStyle.getCharacters(); writeHorizontalLine( writer, borders.get(DATA_ROW_BORDER_LEFT_IDX), @@ -319,15 +319,15 @@ private static void writeBottomBorder( * * * @param writer the writer for output - * @param style the table style containing border characters and row boundary settings + * @param borderStyle the table style containing border characters and row boundary settings * @param columns the array of columns containing the data to write * @param lineSeparator the system-specific line separator * @throws IOException if an error occurs while writing to the output */ private void writeData( - OutputStreamWriter writer, Style style, Column[] columns, String lineSeparator) + OutputStreamWriter writer, BorderStyle borderStyle, Column[] columns, String lineSeparator) throws IOException { - List borders = style.getCharacters(); + List borders = borderStyle.getCharacters(); int dataSize = columns[0].getCellCount(); HorizontalAlign[] dataAligns = Arrays.stream(columns).map(Column::getDataAlign).toArray(HorizontalAlign[]::new); @@ -344,8 +344,8 @@ private void writeData( dataAligns, lineSeparator); - if (i < dataSize - 1 && style.isRowBoundariesEnabled()) { - writeRowSeparator(writer, style, lineSeparator, columns); + if (i < dataSize - 1 && borderStyle.isRowBoundariesEnabled()) { + writeRowSeparator(writer, borderStyle, lineSeparator, columns); } } } @@ -594,7 +594,7 @@ public String getOutput(Metalake metalake) { columnA.addCell(metalake.name()); columnB.addCell(metalake.comment()); - return formatTable(columnA, columnB); + return getTableFormat(columnA, columnB); } } @@ -618,7 +618,7 @@ public String getOutput(Metalake[] metalakes) { Column columnA = new Column("METALAKE", null, property); Arrays.stream(metalakes).forEach(metalake -> columnA.addCell(metalake.name())); - return formatTable(columnA); + return getTableFormat(columnA); } } } @@ -646,7 +646,7 @@ public String getOutput(Catalog catalog) { columnC.addCell(catalog.provider()); columnD.addCell(catalog.comment()); - return formatTable(columnA, columnB, columnC, columnD); + return getTableFormat(columnA, columnB, columnC, columnD); } } @@ -670,7 +670,7 @@ public String getOutput(Catalog[] catalogs) { Column columnA = new Column("METALAKE", null, property); Arrays.stream(catalogs).forEach(metalake -> columnA.addCell(metalake.name())); - return formatTable(columnA); + return getTableFormat(columnA); } } } @@ -693,7 +693,7 @@ public String getOutput(Schema schema) { columnA.addCell(schema.name()); columnB.addCell(schema.comment()); - return formatTable(columnA, columnB); + return getTableFormat(columnA, columnB); } } @@ -716,7 +716,7 @@ public String getOutput(Schema[] schemas) { Column column = new Column("SCHEMA", null, property); Arrays.stream(schemas).forEach(schema -> column.addCell(schema.name())); - return formatTable(column); + return getTableFormat(column); } } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestPlainFormat.java b/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestPlainFormat.java index 006a8c2b91e..2671b8cb2a8 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestPlainFormat.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestPlainFormat.java @@ -43,8 +43,7 @@ public class TestPlainFormat { public static final Joiner COMMA_JOINER = Joiner.on(", ").skipNulls(); - com.google.common.base.Joiner NEWLINE_JOINER = - com.google.common.base.Joiner.on(System.lineSeparator()).skipNulls(); + public static final Joiner NEWLINE_JOINER = Joiner.on(System.lineSeparator()).skipNulls(); private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); private final PrintStream originalOut = System.out; diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestTableFormat.java b/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestTableFormat.java index d08183d8978..19a608e8ca6 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestTableFormat.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/output/TestTableFormat.java @@ -19,15 +19,43 @@ package org.apache.gravitino.cli.output; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import org.apache.gravitino.Catalog; +import org.apache.gravitino.Metalake; +import org.apache.gravitino.Schema; +import org.apache.gravitino.cli.outputs.BorderStyle; import org.apache.gravitino.cli.outputs.Column; import org.apache.gravitino.cli.outputs.HorizontalAlign; import org.apache.gravitino.cli.outputs.OutputProperty; -import org.apache.gravitino.cli.outputs.Style; import org.apache.gravitino.cli.outputs.TableFormat; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class TestTableFormat { + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + private final PrintStream originalErr = System.err; + + @BeforeEach + void setUp() { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @AfterEach + public void restoreStreams() { + System.setOut(originalOut); + System.setErr(originalErr); + } + @Test void testTableOutputWithFooter() { @@ -45,7 +73,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+---+----------+---------+\n" + "| | METALAKE | COMMENT |\n" @@ -75,7 +103,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+---+----------+---------+\n" + "| | METALAKE | COMMENT |\n" @@ -105,7 +133,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+----------+---------+\n" + "| METALAKE | COMMENT |\n" @@ -120,7 +148,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithFancyStyle() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.FANCY); + property.setStyle(BorderStyle.FANCY); Column columnA = new Column("METALAKE", null, property); Column columnB = new Column("comment", null, property); @@ -136,7 +164,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "╔═══╤══════════╤═════════╗\n" + "║ │ METALAKE │ COMMENT ║\n" @@ -151,7 +179,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithFancy2Style() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.FANCY2); + property.setStyle(BorderStyle.FANCY2); property.setRowNumbersEnabled(false); Column columnA = new Column("METALAKE", null, property); @@ -168,7 +196,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "╔══════════╤═════════╗\n" + "║ METALAKE │ COMMENT ║\n" @@ -185,7 +213,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithBasic2Style() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.BASIC2); + property.setStyle(BorderStyle.BASIC2); property.setRowNumbersEnabled(false); Column columnA = new Column("METALAKE", null, property); @@ -202,7 +230,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+----------+---------+\n" + "| METALAKE | COMMENT |\n" @@ -217,7 +245,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithLimit() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.BASIC2); + property.setStyle(BorderStyle.BASIC2); property.setLimit(5); Column columnA = new Column("METALAKE", null, property); @@ -234,7 +262,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+---+------------+-----------+\n" + "| | METALAKE | COMMENT |\n" @@ -252,7 +280,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithHeaderLeftAlignment() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.BASIC2); + property.setStyle(BorderStyle.BASIC2); property.setRowNumbersEnabled(false); property.setHeaderAlign(HorizontalAlign.LEFT); @@ -270,7 +298,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+----------------+----------------+\n" + "| METALAKE | COMMENT |\n" @@ -286,7 +314,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithHeaderRightAlignment() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.BASIC2); + property.setStyle(BorderStyle.BASIC2); property.setRowNumbersEnabled(false); property.setHeaderAlign(HorizontalAlign.RIGHT); @@ -304,7 +332,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+----------------+----------------+\n" + "| METALAKE | COMMENT |\n" @@ -320,7 +348,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithDataCenterAlignment() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.BASIC2); + property.setStyle(BorderStyle.BASIC2); property.setRowNumbersEnabled(false); property.setDataAlign(HorizontalAlign.CENTER); @@ -338,7 +366,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+----------------+----------------+\n" + "| METALAKE | COMMENT |\n" @@ -354,7 +382,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithDataRightAlignment() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.BASIC2); + property.setStyle(BorderStyle.BASIC2); property.setRowNumbersEnabled(false); property.setDataAlign(HorizontalAlign.RIGHT); @@ -372,7 +400,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "+----------------+----------------+\n" + "| METALAKE | COMMENT |\n" @@ -388,7 +416,7 @@ public String getOutput(String entity) { @Test void testTableOutputWithEmptyColumn() { OutputProperty property = OutputProperty.defaultOutputProperty(); - property.setStyle(Style.FANCY); + property.setStyle(BorderStyle.FANCY); property.setRowNumbersEnabled(false); Column columnA = new Column("METALAKE", null, property); @@ -402,7 +430,7 @@ public String getOutput(String entity) { } }; - String outputString = tableFormat.formatTable(columnA, columnB).trim(); + String outputString = tableFormat.getTableFormat(columnA, columnB).trim(); Assertions.assertEquals( "╔══════════╤═════════╗\n" @@ -413,28 +441,128 @@ public String getOutput(String entity) { } @Test - void testMetalakeTableOutput() {} + void testMetalakeTableOutput() { + Metalake mockMetalake = mock(Metalake.class); + when(mockMetalake.name()).thenReturn("demo_metalake"); + when(mockMetalake.comment()).thenReturn("metalake comment"); - @Test - void testMetalakesTableOutput() {} + OutputProperty property = OutputProperty.defaultOutputProperty(); + property.setRowNumbersEnabled(false); + TableFormat.output(mockMetalake, property); + String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim(); + Assertions.assertEquals( + "+---------------+------------------+\n" + + "| METALAKE | COMMENT |\n" + + "+---------------+------------------+\n" + + "| demo_metalake | metalake comment |\n" + + "+---------------+------------------+", + output); + } @Test - void testCatalogTableOutput() {} + void testMetalakesTableOutput() { + Metalake mockMetalake1 = mock(Metalake.class); + Metalake mockMetalake2 = mock(Metalake.class); - @Test - void testCatalogsTableOutput() {} + when(mockMetalake1.name()).thenReturn("demo_metalake1"); + when(mockMetalake2.name()).thenReturn("demo_metalake2"); + + OutputProperty property = OutputProperty.defaultOutputProperty(); + property.setRowNumbersEnabled(false); + TableFormat.output(new Metalake[] {mockMetalake1, mockMetalake2}, property); + String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim(); + Assertions.assertEquals( + "+----------------+\n" + + "| METALAKE |\n" + + "+----------------+\n" + + "| demo_metalake1 |\n" + + "| demo_metalake2 |\n" + + "+----------------+", + output); + } @Test - void testSchemaTableOutput() {} + void testCatalogTableOutput() { + Catalog mockCatalog = mock(Catalog.class); + when(mockCatalog.name()).thenReturn("demo_catalog"); + when(mockCatalog.type()).thenReturn(Catalog.Type.RELATIONAL); + when(mockCatalog.provider()).thenReturn("demo_provider"); + when(mockCatalog.comment()).thenReturn("catalog comment"); + + OutputProperty property = OutputProperty.defaultOutputProperty(); + TableFormat.output(mockCatalog, property); + String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim(); + Assertions.assertEquals( + "+---+--------------+------------+---------------+-----------------+\n" + + "| | CATALOG | TYPE | PROVIDER | COMMENT |\n" + + "+---+--------------+------------+---------------+-----------------+\n" + + "| 1 | demo_catalog | RELATIONAL | demo_provider | catalog comment |\n" + + "+---+--------------+------------+---------------+-----------------+", + output); + } @Test - void testSchemasTableOutput() {} + void testCatalogsTableOutput() { + Catalog mockCatalog1 = mock(Catalog.class); + Catalog mockCatalog2 = mock(Catalog.class); + + when(mockCatalog1.name()).thenReturn("demo_catalog1"); + when(mockCatalog2.name()).thenReturn("demo_catalog2"); + + OutputProperty property = OutputProperty.defaultOutputProperty(); + property.setRowNumbersEnabled(false); + TableFormat.output(new Catalog[] {mockCatalog1, mockCatalog2}, property); + String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim(); + Assertions.assertEquals( + "+---------------+\n" + + "| METALAKE |\n" + + "+---------------+\n" + + "| demo_catalog1 |\n" + + "| demo_catalog2 |\n" + + "+---------------+", + output); + } @Test - void testTableTableOutput() {} + void testSchemaTableOutput() { + Schema mmockSchema = mock(Schema.class); + when(mmockSchema.name()).thenReturn("demo_schema"); + when(mmockSchema.comment()).thenReturn("schema comment"); + + OutputProperty property = OutputProperty.defaultOutputProperty(); + property.setRowNumbersEnabled(false); + TableFormat.output(mmockSchema, property); + String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim(); + Assertions.assertEquals( + "+-------------+----------------+\n" + + "| SCHEMA | COMMENT |\n" + + "+-------------+----------------+\n" + + "| demo_schema | schema comment |\n" + + "+-------------+----------------+", + output); + } @Test - void testTablesTableOutput() {} + void testSchemasTableOutput() { + Schema mockSchema1 = mock(Schema.class); + Schema mockSchema2 = mock(Schema.class); + + when(mockSchema1.name()).thenReturn("demo_schema1"); + when(mockSchema2.name()).thenReturn("demo_schema2"); + + OutputProperty property = OutputProperty.defaultOutputProperty(); + property.setRowNumbersEnabled(false); + TableFormat.output(new Schema[] {mockSchema1, mockSchema2}, property); + String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim(); + Assertions.assertEquals( + "+--------------+\n" + + "| SCHEMA |\n" + + "+--------------+\n" + + "| demo_schema1 |\n" + + "| demo_schema2 |\n" + + "+--------------+", + output); + } private void addRepeatedCells(Column column, int count) { for (int i = 0; i < count; i++) {