You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/03/24 17:49:35 UTC

[GitHub] [geode] kirklund opened a new pull request #6185: DRAFT: GEODE-9047: Cleanup package management.internal.cli.result

kirklund opened a new pull request #6185:
URL: https://github.com/apache/geode/pull/6185


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kirklund commented on pull request #6185: GEODE-9047: Cleanup package management.internal.cli.result

Posted by GitBox <gi...@apache.org>.
kirklund commented on pull request #6185:
URL: https://github.com/apache/geode/pull/6185#issuecomment-807290828


   @DonalEvans Think of this PR has a first pass cleaning up this package and its tests. I didn't actually write new tests. We can keep cleaning up more in followup PRs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] DonalEvans commented on a change in pull request #6185: GEODE-9047: Cleanup package management.internal.cli.result

Posted by GitBox <gi...@apache.org>.
DonalEvans commented on a change in pull request #6185:
URL: https://github.com/apache/geode/pull/6185#discussion_r601705985



##########
File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/result/ColumnTest.java
##########
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal.cli.result;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+public class ColumnTest {
+
+  @Test
+  public void getLengthReturnsLengthOfStringValue() {
+    String value = "bar";
+    Align align = Align.CENTER;
+    Column column = new Column(value, align);
+
+    int result = column.getLength();
+
+    assertThat(result).isEqualTo(3);

Review comment:
       To make this assertion more explicit, it would be better to have it be `assertThat(result).isEqualTo(value.length());`

##########
File path: geode-gfsh/src/integrationTest/java/org/apache/geode/management/internal/cli/result/model/ResultModelIntegrationTest.java
##########
@@ -83,8 +99,26 @@ public void dirNotExistBefore() throws IOException {
   @SuppressWarnings("deprecation")
   public void modelCommandResultShouldNotDealWithFiles() throws IOException {
     result.saveFileTo(temporaryFolder.newFolder("test"));
-    CommandResult commandResult = new CommandResult(result);
-    assertThat(commandResult.hasIncomingFiles()).isFalse();
+    Result commandResult = new CommandResult(result);
+
+    assertThat(commandResult.hasIncomingFiles())
+        .isFalse();
+  }
+
+  @Test
+  public void serializeFileToDownload() throws Exception {
+    File file = temporaryFolder.newFile("test.log");
+    ResultModel result = new ResultModel();
+    result.addFile(file, FileResultModel.FILE_TYPE_FILE);
+    ObjectMapper mapper = GeodeJsonMapper.getMapper();
+    String json = mapper.writeValueAsString(result);
+    System.out.println(json);

Review comment:
       This print statement can probably be removed.

##########
File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/result/TableBuilderTest.java
##########
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal.cli.result;
+
+import static java.util.Arrays.asList;
+import static org.apache.geode.internal.util.ArrayUtils.fill;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.management.internal.cli.GfshParser;
+
+public class TableBuilderTest {
+
+  private static final int SCREEN_WIDTH = 40;
+
+  private Screen screen;
+  private TableBuilder tableBuilder;
+
+  @Before
+  public void setUp() {
+    screen = mock(Screen.class);
+    tableBuilder = spy(new TableBuilder());
+
+    when(screen.getScreenWidth()).thenReturn(SCREEN_WIDTH);
+    when(screen.shouldTrimColumns()).thenReturn(true);
+  }
+
+  /**
+   * Test Variations table-wide separator true false
+   */
+  @Test
+  public void testSanity() {
+    Table table = createTableStructure(3, "|", fill(new String[3], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("1")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|Field1|Field2",
+            "------|------|------",
+            "1     |1     |1");
+  }
+
+  @Test
+  public void testLastColumnTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2  |Field3",
+            "------|----------|----------|-----------",
+            "1     |123456789-|123456789-|123456789..");
+  }
+
+  @Test
+  public void testLongestColumnFirstTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-123456789-")
+        .newLeftCol("123456789-12345")
+        .newLeftCol("123456789-")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|    Field1     |  Field2  |Field3",
+            "------|---------------|----------|------",
+            "1234..|123456789-12345|123456789-|1");
+  }
+
+  @Test
+  public void testMultipleColumnsTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2   |Field3",
+            "------|----------|-----------|---------",
+            "1     |123456789-|123456789..|1234567..");
+  }
+
+  @Test
+  public void testMultipleColumnsTruncatedLongestFirst() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-123456789-12345")
+        .newLeftCol("1")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "  Field0   | Field1  |Field2|Field3",
+            "-----------|---------|------|----------",
+            "123456789..|1234567..|1     |123456789-");
+  }
+
+  @Test
+  public void testColumnsWithShortNames() {
+    when(screen.getScreenWidth()).thenReturn(9);
+
+    Table table = createTableStructure(3, "|", "A", "A", "A");
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123")
+        .newLeftCol("123")
+        .newLeftCol("123");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "A0|A1|A2",
+            "--|--|--",
+            "..|..|..");
+  }
+
+  @Test
+  public void testExceptionTooSmallWidth() {
+    when(screen.getScreenWidth()).thenReturn(7);
+
+    Table table = createTableStructure(3, "|", "A", "A", "A");
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("12")
+        .newLeftCol("12")
+        .newLeftCol("12");
+
+    // This should throw an exception
+    assertThatThrownBy(() -> validateTable(table, true))
+        .isInstanceOf(TooManyColumnsException.class);
+  }
+
+  @Test
+  public void testTooLittleSpaceOnNextToLastColumn() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2   |Field3",
+            "------|----------|-----------|----------",
+            "1     |123456789-|123456789..|123456789-");
+  }
+
+  @Test
+  public void testSeparatorWithMultipleChars() {
+    Table table = createTableStructure(4, "<|>", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0<|>  Field1  <|>  Field2  <|>Fie..",
+            "------<|>----------<|>----------<|>-----",
+            "1     <|>123456789-<|>123456789-<|>123..");
+  }
+
+  @Test
+  public void testManyColumns() {
+    Table table = createTableStructure(8, "|", fill(new String[8], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "  Field0  |  Field1  |..|..|..|..|..|..",
+            "----------|----------|--|--|--|--|--|--",
+            "123456789-|123456789-|..|..|..|..|..|..");
+  }
+
+  @Test
+  public void testDisableColumnAdjustment() {
+    when(screen.shouldTrimColumns()).thenReturn(false);
+
+    Table table = createTableStructure(5, "|", fill(new String[5], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, false);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2  |         Field3          |Field4",
+            "------|----------|----------|-------------------------|------",
+            "1     |123456789-|123456789-|123456789-123456789-12345|1");
+  }
+
+  private Table createTableStructure(int columnCount, String separator, String... columnNames) {
+    Table resultTable = tableBuilder.newTable(screen);
+    resultTable.setTabularResult(true);
+    resultTable.setColumnSeparator(separator);
+
+    resultTable.newBlankRow();
+    RowGroup rowGroup = resultTable.newRowGroup();
+    Row row = rowGroup.newRow();
+
+    for (int column = 0; column < columnCount; column++) {
+      row.newCenterCol(columnNames[column] + column);
+    }
+
+    rowGroup.newRowSeparator('-', false);
+
+    return resultTable;
+  }
+
+  private List<String> validateTable(Table table, boolean shouldTrim) {
+    String tableAsString = table.buildTable();
+    System.out.println(tableAsString);

Review comment:
       Is this print statement necessary? If it's intended for debugging, is there a way to use assertions instead that would render any test failures self-explanatory?

##########
File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/result/TableBuilderTest.java
##########
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal.cli.result;
+
+import static java.util.Arrays.asList;
+import static org.apache.geode.internal.util.ArrayUtils.fill;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.management.internal.cli.GfshParser;
+
+public class TableBuilderTest {
+
+  private static final int SCREEN_WIDTH = 40;
+
+  private Screen screen;
+  private TableBuilder tableBuilder;
+
+  @Before
+  public void setUp() {
+    screen = mock(Screen.class);
+    tableBuilder = spy(new TableBuilder());
+
+    when(screen.getScreenWidth()).thenReturn(SCREEN_WIDTH);
+    when(screen.shouldTrimColumns()).thenReturn(true);
+  }
+
+  /**
+   * Test Variations table-wide separator true false
+   */
+  @Test
+  public void testSanity() {
+    Table table = createTableStructure(3, "|", fill(new String[3], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("1")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|Field1|Field2",
+            "------|------|------",
+            "1     |1     |1");
+  }
+
+  @Test
+  public void testLastColumnTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2  |Field3",
+            "------|----------|----------|-----------",
+            "1     |123456789-|123456789-|123456789..");
+  }
+
+  @Test
+  public void testLongestColumnFirstTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-123456789-")
+        .newLeftCol("123456789-12345")
+        .newLeftCol("123456789-")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|    Field1     |  Field2  |Field3",
+            "------|---------------|----------|------",
+            "1234..|123456789-12345|123456789-|1");
+  }
+
+  @Test
+  public void testMultipleColumnsTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2   |Field3",
+            "------|----------|-----------|---------",
+            "1     |123456789-|123456789..|1234567..");
+  }
+
+  @Test
+  public void testMultipleColumnsTruncatedLongestFirst() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-123456789-12345")
+        .newLeftCol("1")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "  Field0   | Field1  |Field2|Field3",
+            "-----------|---------|------|----------",
+            "123456789..|1234567..|1     |123456789-");
+  }
+
+  @Test
+  public void testColumnsWithShortNames() {
+    when(screen.getScreenWidth()).thenReturn(9);
+
+    Table table = createTableStructure(3, "|", "A", "A", "A");
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123")
+        .newLeftCol("123")
+        .newLeftCol("123");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "A0|A1|A2",
+            "--|--|--",
+            "..|..|..");
+  }
+
+  @Test
+  public void testExceptionTooSmallWidth() {
+    when(screen.getScreenWidth()).thenReturn(7);
+
+    Table table = createTableStructure(3, "|", "A", "A", "A");
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("12")
+        .newLeftCol("12")
+        .newLeftCol("12");
+
+    // This should throw an exception
+    assertThatThrownBy(() -> validateTable(table, true))
+        .isInstanceOf(TooManyColumnsException.class);
+  }
+
+  @Test
+  public void testTooLittleSpaceOnNextToLastColumn() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2   |Field3",
+            "------|----------|-----------|----------",
+            "1     |123456789-|123456789..|123456789-");
+  }
+
+  @Test
+  public void testSeparatorWithMultipleChars() {
+    Table table = createTableStructure(4, "<|>", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0<|>  Field1  <|>  Field2  <|>Fie..",
+            "------<|>----------<|>----------<|>-----",
+            "1     <|>123456789-<|>123456789-<|>123..");
+  }
+
+  @Test
+  public void testManyColumns() {
+    Table table = createTableStructure(8, "|", fill(new String[8], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "  Field0  |  Field1  |..|..|..|..|..|..",
+            "----------|----------|--|--|--|--|--|--",
+            "123456789-|123456789-|..|..|..|..|..|..");
+  }
+
+  @Test
+  public void testDisableColumnAdjustment() {
+    when(screen.shouldTrimColumns()).thenReturn(false);
+
+    Table table = createTableStructure(5, "|", fill(new String[5], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, false);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2  |         Field3          |Field4",
+            "------|----------|----------|-------------------------|------",
+            "1     |123456789-|123456789-|123456789-123456789-12345|1");
+  }
+
+  private Table createTableStructure(int columnCount, String separator, String... columnNames) {
+    Table resultTable = tableBuilder.newTable(screen);
+    resultTable.setTabularResult(true);
+    resultTable.setColumnSeparator(separator);
+
+    resultTable.newBlankRow();
+    RowGroup rowGroup = resultTable.newRowGroup();
+    Row row = rowGroup.newRow();
+
+    for (int column = 0; column < columnCount; column++) {
+      row.newCenterCol(columnNames[column] + column);
+    }
+
+    rowGroup.newRowSeparator('-', false);
+
+    return resultTable;
+  }
+
+  private List<String> validateTable(Table table, boolean shouldTrim) {
+    String tableAsString = table.buildTable();
+    System.out.println(tableAsString);
+
+    List<String> lines = asList(tableAsString.split(GfshParser.LINE_SEPARATOR));
+
+    int lineCount = 0;
+    for (String line : lines) {
+      System.out.println("Line #" + lineCount++ + ": length = " + line.length() + ", isWider = "

Review comment:
       See above comment regarding print statements. Perhaps a suitably constructed `as()` call added to the below assertions would render this unnecessary.

##########
File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/result/TableBuilderTest.java
##########
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal.cli.result;
+
+import static java.util.Arrays.asList;
+import static org.apache.geode.internal.util.ArrayUtils.fill;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.management.internal.cli.GfshParser;
+
+public class TableBuilderTest {
+
+  private static final int SCREEN_WIDTH = 40;
+
+  private Screen screen;
+  private TableBuilder tableBuilder;
+
+  @Before
+  public void setUp() {
+    screen = mock(Screen.class);
+    tableBuilder = spy(new TableBuilder());
+
+    when(screen.getScreenWidth()).thenReturn(SCREEN_WIDTH);
+    when(screen.shouldTrimColumns()).thenReturn(true);
+  }
+
+  /**
+   * Test Variations table-wide separator true false
+   */
+  @Test
+  public void testSanity() {
+    Table table = createTableStructure(3, "|", fill(new String[3], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("1")
+        .newLeftCol("1");

Review comment:
       The formatting here is a little weird, with the first method call dangling on a new line. Was this intentional? The same pattern is used throughout this class, so if it's deliberate, for the purpose of readability, then that's fine.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kirklund commented on a change in pull request #6185: GEODE-9047: Cleanup package management.internal.cli.result

Posted by GitBox <gi...@apache.org>.
kirklund commented on a change in pull request #6185:
URL: https://github.com/apache/geode/pull/6185#discussion_r601762847



##########
File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/result/TableBuilderTest.java
##########
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal.cli.result;
+
+import static java.util.Arrays.asList;
+import static org.apache.geode.internal.util.ArrayUtils.fill;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.management.internal.cli.GfshParser;
+
+public class TableBuilderTest {
+
+  private static final int SCREEN_WIDTH = 40;
+
+  private Screen screen;
+  private TableBuilder tableBuilder;
+
+  @Before
+  public void setUp() {
+    screen = mock(Screen.class);
+    tableBuilder = spy(new TableBuilder());
+
+    when(screen.getScreenWidth()).thenReturn(SCREEN_WIDTH);
+    when(screen.shouldTrimColumns()).thenReturn(true);
+  }
+
+  /**
+   * Test Variations table-wide separator true false
+   */
+  @Test
+  public void testSanity() {
+    Table table = createTableStructure(3, "|", fill(new String[3], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("1")
+        .newLeftCol("1");

Review comment:
       Yep, this is the formatting that several of us having been using with fluent APIs. The idea is that we think it's more easy to read and understand this way. I'm sure there's people who prefer it the other way too.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kirklund commented on a change in pull request #6185: GEODE-9047: Cleanup package management.internal.cli.result

Posted by GitBox <gi...@apache.org>.
kirklund commented on a change in pull request #6185:
URL: https://github.com/apache/geode/pull/6185#discussion_r601763665



##########
File path: geode-gfsh/src/test/java/org/apache/geode/management/internal/cli/result/TableBuilderTest.java
##########
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal.cli.result;
+
+import static java.util.Arrays.asList;
+import static org.apache.geode.internal.util.ArrayUtils.fill;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.management.internal.cli.GfshParser;
+
+public class TableBuilderTest {
+
+  private static final int SCREEN_WIDTH = 40;
+
+  private Screen screen;
+  private TableBuilder tableBuilder;
+
+  @Before
+  public void setUp() {
+    screen = mock(Screen.class);
+    tableBuilder = spy(new TableBuilder());
+
+    when(screen.getScreenWidth()).thenReturn(SCREEN_WIDTH);
+    when(screen.shouldTrimColumns()).thenReturn(true);
+  }
+
+  /**
+   * Test Variations table-wide separator true false
+   */
+  @Test
+  public void testSanity() {
+    Table table = createTableStructure(3, "|", fill(new String[3], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("1")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|Field1|Field2",
+            "------|------|------",
+            "1     |1     |1");
+  }
+
+  @Test
+  public void testLastColumnTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2  |Field3",
+            "------|----------|----------|-----------",
+            "1     |123456789-|123456789-|123456789..");
+  }
+
+  @Test
+  public void testLongestColumnFirstTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-123456789-")
+        .newLeftCol("123456789-12345")
+        .newLeftCol("123456789-")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|    Field1     |  Field2  |Field3",
+            "------|---------------|----------|------",
+            "1234..|123456789-12345|123456789-|1");
+  }
+
+  @Test
+  public void testMultipleColumnsTruncated() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2   |Field3",
+            "------|----------|-----------|---------",
+            "1     |123456789-|123456789..|1234567..");
+  }
+
+  @Test
+  public void testMultipleColumnsTruncatedLongestFirst() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-123456789-12345")
+        .newLeftCol("1")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "  Field0   | Field1  |Field2|Field3",
+            "-----------|---------|------|----------",
+            "123456789..|1234567..|1     |123456789-");
+  }
+
+  @Test
+  public void testColumnsWithShortNames() {
+    when(screen.getScreenWidth()).thenReturn(9);
+
+    Table table = createTableStructure(3, "|", "A", "A", "A");
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123")
+        .newLeftCol("123")
+        .newLeftCol("123");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "A0|A1|A2",
+            "--|--|--",
+            "..|..|..");
+  }
+
+  @Test
+  public void testExceptionTooSmallWidth() {
+    when(screen.getScreenWidth()).thenReturn(7);
+
+    Table table = createTableStructure(3, "|", "A", "A", "A");
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("12")
+        .newLeftCol("12")
+        .newLeftCol("12");
+
+    // This should throw an exception
+    assertThatThrownBy(() -> validateTable(table, true))
+        .isInstanceOf(TooManyColumnsException.class);
+  }
+
+  @Test
+  public void testTooLittleSpaceOnNextToLastColumn() {
+    Table table = createTableStructure(4, "|", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-123456789-")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2   |Field3",
+            "------|----------|-----------|----------",
+            "1     |123456789-|123456789..|123456789-");
+  }
+
+  @Test
+  public void testSeparatorWithMultipleChars() {
+    Table table = createTableStructure(4, "<|>", fill(new String[4], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0<|>  Field1  <|>  Field2  <|>Fie..",
+            "------<|>----------<|>----------<|>-----",
+            "1     <|>123456789-<|>123456789-<|>123..");
+  }
+
+  @Test
+  public void testManyColumns() {
+    Table table = createTableStructure(8, "|", fill(new String[8], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-");
+
+    List<String> result = validateTable(table, true);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "  Field0  |  Field1  |..|..|..|..|..|..",
+            "----------|----------|--|--|--|--|--|--",
+            "123456789-|123456789-|..|..|..|..|..|..");
+  }
+
+  @Test
+  public void testDisableColumnAdjustment() {
+    when(screen.shouldTrimColumns()).thenReturn(false);
+
+    Table table = createTableStructure(5, "|", fill(new String[5], "Field"));
+    RowGroup rowGroup = table.getLastRowGroup();
+    Row row = rowGroup.newRow();
+    row
+        .newLeftCol("1")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-")
+        .newLeftCol("123456789-123456789-12345")
+        .newLeftCol("1");
+
+    List<String> result = validateTable(table, false);
+
+    assertThat(result)
+        .hasSize(4)
+        .containsExactly(
+            "",
+            "Field0|  Field1  |  Field2  |         Field3          |Field4",
+            "------|----------|----------|-------------------------|------",
+            "1     |123456789-|123456789-|123456789-123456789-12345|1");
+  }
+
+  private Table createTableStructure(int columnCount, String separator, String... columnNames) {
+    Table resultTable = tableBuilder.newTable(screen);
+    resultTable.setTabularResult(true);
+    resultTable.setColumnSeparator(separator);
+
+    resultTable.newBlankRow();
+    RowGroup rowGroup = resultTable.newRowGroup();
+    Row row = rowGroup.newRow();
+
+    for (int column = 0; column < columnCount; column++) {
+      row.newCenterCol(columnNames[column] + column);
+    }
+
+    rowGroup.newRowSeparator('-', false);
+
+    return resultTable;
+  }
+
+  private List<String> validateTable(Table table, boolean shouldTrim) {
+    String tableAsString = table.buildTable();
+    System.out.println(tableAsString);

Review comment:
       I didn't write any of the tests, I just renamed the test class and cleaned things up. I suppose the author added system out println's to see values. I'll delete them.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [geode] kirklund merged pull request #6185: GEODE-9047: Cleanup package management.internal.cli.result

Posted by GitBox <gi...@apache.org>.
kirklund merged pull request #6185:
URL: https://github.com/apache/geode/pull/6185


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org