Pochatkin commented on code in PR #7356:
URL: https://github.com/apache/ignite-3/pull/7356#discussion_r2690164663


##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/unit/NodeUnitStructureCommand.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.ignite.internal.cli.commands.node.unit;
+
+import static 
org.apache.ignite.internal.cli.commands.Options.Constants.PLAIN_OPTION;
+import static 
org.apache.ignite.internal.cli.commands.Options.Constants.PLAIN_OPTION_DESC;
+import static 
org.apache.ignite.internal.cli.commands.Options.Constants.UNIT_VERSION_OPTION_DESC;
+import static 
org.apache.ignite.internal.cli.commands.Options.Constants.VERSION_OPTION;
+
+import jakarta.inject.Inject;
+import java.util.concurrent.Callable;
+import org.apache.ignite.internal.cli.call.node.unit.NodeUnitStructureCall;
+import org.apache.ignite.internal.cli.call.unit.UnitStructureCallInput;
+import org.apache.ignite.internal.cli.commands.BaseCommand;
+import org.apache.ignite.internal.cli.commands.node.NodeUrlProfileMixin;
+import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline;
+import 
org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler;
+import org.apache.ignite.internal.cli.decorators.UnitStructureDecorator;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Mixin;
+import picocli.CommandLine.Option;
+import picocli.CommandLine.Parameters;
+
+/** Command to show deployment unit structure. */
+@Command(name = "structure", description = "Shows the structure of a deployed 
unit")

Review Comment:
   Fixed: Renamed the command from `structure` to `inspect`. All related 
classes have been renamed accordingly (NodeUnitStructureCommand → 
NodeUnitInspectCommand, etc.).



##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/unit/ItNodeUnitStructureCommandTest.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.ignite.internal.cli.commands.unit;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.apache.ignite.internal.cli.CliIntegrationTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+/** Integration test for node unit structure command. */
+public class ItNodeUnitStructureCommandTest extends CliIntegrationTest {
+    private static String testFile;
+
+    private static Path testDirectory;
+
+    @BeforeAll
+    static void beforeAll() throws IOException {
+        testDirectory = 
Files.createDirectory(WORK_DIR.resolve("test-structure"));
+        testFile = 
Files.createFile(testDirectory.resolve("test.txt")).toString();
+        Files.createFile(testDirectory.resolve("test2.txt"));
+        Files.createFile(testDirectory.resolve("test3.txt"));

Review Comment:
   Fixed: Added diverse test filenames with spaces, dashes, underscores, 
multiple dots, parentheses, and mixed case. Also added nested directories to 
cover more edge cases.



##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/decorators/UnitStructureDecoratorTest.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.ignite.internal.cli.decorators;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
+
+import java.util.List;
+import org.apache.ignite.rest.client.model.UnitEntry;
+import org.apache.ignite.rest.client.model.UnitFile;
+import org.apache.ignite.rest.client.model.UnitFolder;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+class UnitStructureDecoratorTest {
+
+    @Test
+    @DisplayName("Tree view should display folder with files")
+    void treeViewWithFiles() {
+        // Given
+        UnitFolder folder = createFolderWithFiles("test-unit",
+                createFile("file1.txt", 100),
+                createFile("file2.txt", 200));
+
+        UnitStructureDecorator decorator = new UnitStructureDecorator(false);
+
+        // When
+        String output = decorator.decorate(folder).toTerminalString();
+
+        // Then
+        assertThat(output, containsString("test-unit"));

Review Comment:
   Fixed: Added exact output verification for all tests in 
UnitInspectDecoratorTest using assertThat(output, is(expected)) instead of 
containsString.



##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/decorators/UnitStructureDecoratorTest.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.ignite.internal.cli.decorators;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
+
+import java.util.List;
+import org.apache.ignite.rest.client.model.UnitEntry;
+import org.apache.ignite.rest.client.model.UnitFile;
+import org.apache.ignite.rest.client.model.UnitFolder;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+class UnitStructureDecoratorTest {
+
+    @Test
+    @DisplayName("Tree view should display folder with files")
+    void treeViewWithFiles() {
+        // Given
+        UnitFolder folder = createFolderWithFiles("test-unit",
+                createFile("file1.txt", 100),
+                createFile("file2.txt", 200));
+
+        UnitStructureDecorator decorator = new UnitStructureDecorator(false);
+
+        // When
+        String output = decorator.decorate(folder).toTerminalString();
+
+        // Then
+        assertThat(output, containsString("test-unit"));
+        assertThat(output, containsString("file1.txt"));
+        assertThat(output, containsString("file2.txt"));
+        assertThat(output, containsString("100 B"));
+        assertThat(output, containsString("200 B"));
+        assertThat(output, containsString("+--"));
+        assertThat(output, containsString("\\--"));
+    }
+
+    @Test
+    @DisplayName("Tree view should display nested folders")
+    void treeViewWithNestedFolders() {
+        // Given
+        UnitFolder subFolder = createFolderWithFiles("subfolder",
+                createFile("nested.txt", 50));
+
+        UnitEntry subFolderEntry = new UnitEntry();
+        subFolderEntry.setActualInstance(subFolder);
+
+        UnitFolder rootFolder = new UnitFolder()
+                .type(UnitFolder.TypeEnum.FOLDER)
+                .name("root")
+                .children(List.of(subFolderEntry));
+
+        UnitStructureDecorator decorator = new UnitStructureDecorator(false);
+
+        // When
+        String output = decorator.decorate(rootFolder).toTerminalString();
+
+        // Then
+        assertThat(output, containsString("root"));
+        assertThat(output, containsString("subfolder"));
+        assertThat(output, containsString("nested.txt"));
+        assertThat(output, containsString("\\--"));
+        assertThat(output, containsString("    \\--")); // Nested indent
+    }
+
+    @Test
+    @DisplayName("Plain view should display file paths")
+    void plainViewWithFiles() {
+        // Given
+        UnitFolder folder = createFolderWithFiles("test-unit",
+                createFile("file1.txt", 100),
+                createFile("file2.txt", 200));
+
+        UnitStructureDecorator decorator = new UnitStructureDecorator(true);
+
+        // When
+        String output = decorator.decorate(folder).toTerminalString();
+
+        // Then
+        assertThat(output, containsString("file1.txt"));
+        assertThat(output, containsString("file2.txt"));
+        assertThat(output, containsString("100"));
+        assertThat(output, containsString("200"));
+        // Should not contain tree characters in plain mode
+        assertThat(output, not(containsString("├──")));
+        assertThat(output, not(containsString("└──")));
+    }
+
+    @Test
+    @DisplayName("Plain view should display nested paths")
+    void plainViewWithNestedFolders() {
+        // Given
+        UnitFolder subFolder = createFolderWithFiles("subfolder",
+                createFile("nested.txt", 50));
+
+        UnitEntry subFolderEntry = new UnitEntry();
+        subFolderEntry.setActualInstance(subFolder);
+
+        UnitFolder rootFolder = new UnitFolder()
+                .type(UnitFolder.TypeEnum.FOLDER)
+                .name("root")
+                .children(List.of(subFolderEntry));
+
+        UnitStructureDecorator decorator = new UnitStructureDecorator(true);
+
+        // When
+        String output = decorator.decorate(rootFolder).toTerminalString();
+
+        // Then
+        assertThat(output, containsString("subfolder/nested.txt"));
+        assertThat(output, containsString("50"));
+    }
+
+    @Test
+    @DisplayName("Should format file sizes correctly")
+    void fileSizeFormatting() {
+        // Given
+        UnitFolder folder = createFolderWithFiles("test-unit",
+                createFile("small.txt", 512),
+                createFile("medium.txt", 2048),
+                createFile("large.txt", 1024 * 1024 * 2));
+
+        UnitStructureDecorator decorator = new UnitStructureDecorator(false);
+
+        // When
+        String output = decorator.decorate(folder).toTerminalString();
+
+        // Then
+        assertThat(output, containsString("512 B"));
+        assertThat(output, containsString("KiB"));
+        assertThat(output, containsString("MiB"));
+    }
+
+    @Test
+    @DisplayName("Should handle empty folder")
+    void emptyFolder() {
+        // Given
+        UnitFolder folder = new UnitFolder()
+                .type(UnitFolder.TypeEnum.FOLDER)
+                .name("empty-folder")
+                .children(List.of());
+
+        UnitStructureDecorator decorator = new UnitStructureDecorator(false);
+
+        // When
+        String output = decorator.decorate(folder).toTerminalString();
+
+        // Then
+        assertThat(output, containsString("empty-folder"));
+    }
+
+    private UnitFolder createFolderWithFiles(String name, UnitFile... files) {
+        List<UnitEntry> children = new java.util.ArrayList<>();
+        long totalSize = 0;
+
+        for (UnitFile file : files) {
+            UnitEntry entry = new UnitEntry();
+            entry.setActualInstance(file);
+            children.add(entry);
+            totalSize += file.getSize();
+        }

Review Comment:
   Fixed: Simplified the code using 
`Arrays.stream(files).map(UnitEntry::new).collect(Collectors.toList())` as 
suggested.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to