gnodet-bot commented on code in PR #26558:
URL: https://github.com/apache/camel/pull/26558#discussion_r4039353502


##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacadeGetFilesTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.camel.dsl.jbang.core.commands.tui;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@code camel_get_files} on the selected integration: an exported Spring 
Boot project is a Maven layout, and the
+ * running routes point at the files under {@code src/main}, so a model finds 
the route file in one call instead of
+ * guessing names in the wrong folder (CAMEL-24798).
+ */
+class McpFacadeGetFilesTest {
+
+    private static final String ROUTE = "- route:\n    id: timer-log\n    
from:\n      uri: timer:tick\n"
+                                        + "      steps:\n        - log:\n      
      message: hi\n";
+
+    private static McpFacade facade(Path projectDir, String routeSource) {
+        IntegrationInfo info = new IntegrationInfo();
+        info.name = "timer-log";
+        info.pid = "1";
+        info.directory = projectDir.toString();
+        RouteInfo route = new RouteInfo();
+        route.routeId = "timer-log";

Review Comment:
   πŸ’‘ **Nit (still open from previous review):** The `facade()` helper always 
sets `route.routeId = "timer-log"`, so no test through the facade covers an 
anonymous route. The null guard added in `McpFacade.getFiles` for the 
`r.routeId != null` case is not exercised from this test class β€” only from 
`AuthoringToolsTest` (direct `routeSources` call).
   
   Add a case with a null `routeId` to pin the facade path:
   
   ```suggestion
           route.routeId = "timer-log";
   ```
   
   …and add a test method that constructs a `RouteInfo` with `routeId = null`, 
calls `facade.getFiles(name, null)`, and asserts that the resulting routes 
array contains an entry without a `routeId` key.



##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacadeGetFilesTest.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.camel.dsl.jbang.core.commands.tui;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * {@code camel_get_files} on the selected integration: an exported Spring 
Boot project is a Maven layout, and the
+ * running routes point at the files under {@code src/main}, so a model finds 
the route file in one call instead of
+ * guessing names in the wrong folder (CAMEL-24798).
+ */
+class McpFacadeGetFilesTest {
+
+    private static final String ROUTE = "- route:\n    id: timer-log\n    
from:\n      uri: timer:tick\n"
+                                        + "      steps:\n        - log:\n      
      message: hi\n";
+
+    private static McpFacade facade(Path projectDir, String routeSource) {
+        IntegrationInfo info = new IntegrationInfo();
+        info.name = "timer-log";
+        info.pid = "1";
+        info.directory = projectDir.toString();
+        RouteInfo route = new RouteInfo();
+        route.routeId = "timer-log";
+        route.source = routeSource;
+        info.routes.add(route);
+        return new McpFacade(
+                null, new AtomicReference<>(List.of(info)), null, null, null, 
null, null, null, null, null, null,
+                null, null);
+    }
+
+    @Test
+    void 
anExportedProjectListsItsRouteFileAndWhereTheRunningRouteComesFrom(@TempDir 
Path dir) throws IOException {
+        Files.createDirectories(dir.resolve("src/main/resources/camel"));
+        Files.createDirectories(dir.resolve("target/classes/camel"));
+        Files.writeString(dir.resolve("pom.xml"), "<project/>");
+        
Files.writeString(dir.resolve("src/main/resources/camel/timer-log.camel.yaml"), 
ROUTE);
+        
Files.writeString(dir.resolve("src/main/resources/application.properties"), 
"camel.main.name=timer-log\n");
+        
Files.writeString(dir.resolve("target/classes/camel/timer-log.camel.yaml"), 
ROUTE);
+        McpFacade facade = facade(dir, "nested:" + dir
+                                       + 
"/target/timer-log-1.0-SNAPSHOT.jar/!BOOT-INF/classes/!/camel/timer-log.camel.yaml:4");
+
+        JsonObject list = facade.getFiles("timer-log", null);
+
+        assertNotNull(list);
+        assertEquals("maven", list.getString("layout"));
+        assertEquals(List.of("src/main/resources/camel/timer-log.camel.yaml"), 
list.getCollection("routeFiles"));
+        assertEquals(dir.toString(), list.getString("directory"));

Review Comment:
   πŸ’‘ **Nit:** the `facade()` helper always sets `route.routeId = "timer-log"`, 
so the `if (r.routeId != null)` guard added in `McpFacade.getFiles` (line 1068) 
is never exercised here. Add one case with `route.routeId = null` to pin the 
behaviour through the facade β€” e.g. in 
`aMissingFileIsAnErrorWithTheDirectoryNotAMissingProject` or as a small 
standalone test:
   
   ```java
   // anonymous route: no routeId β†’ entry must not contain "routeId"
   McpFacade anonFacade = facade(dir, "file:" + dir.resolve("demo.camel.yaml") 
+ ":1");
   // override routeId to null via a local IntegrationInfo
   // (or add a second overload of facade() that exposes routeId)
   JsonObject anonList = anonFacade.getFiles("timer-log", null);
   JsonObject anonRoute = (JsonObject) ((JsonArray) 
anonList.get("routes")).get(0);
   assertFalse(anonRoute.containsKey("routeId"));
   ```



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