davsclaus commented on code in PR #26706:
URL: https://github.com/apache/camel/pull/26706#discussion_r4064579706


##########
dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderResourceLoaderTest.java:
##########
@@ -93,4 +98,33 @@ void theSourceDirWinsWhenSet() throws Exception {
         Resource resource = loader.resolveResource("classpath:mapping.groovy");
         assertEquals("from source dir", new 
String(resource.getInputStream().readAllBytes()));
     }
+
+    /** Resolving an http: resource must not fetch it: only classpath: and 
file: resources are probed and looked up. */
+    @Test
+    void anHttpResourceIsNotFetchedWhenResolved() throws Exception {
+        AtomicInteger requests = new AtomicInteger();
+        HttpServer server = HttpServer.create(new 
InetSocketAddress("localhost", 0), 0);
+        server.createContext("/openapi.json", exchange -> {
+            requests.incrementAndGet();
+            byte[] body = "{}".getBytes(StandardCharsets.UTF_8);
+            exchange.sendResponseHeaders(200, body.length);
+            try (OutputStream out = exchange.getResponseBody()) {
+                out.write(body);
+            }
+        });
+        server.start();
+        try {
+            SimpleCamelContext context = new SimpleCamelContext();
+            DependencyDownloaderResourceLoader loader
+                    = new DependencyDownloaderResourceLoader(context, null, 
List.of(routes.toString()));
+
+            Resource resource
+                    = loader.resolveResource("http://localhost:"; + 
server.getAddress().getPort() + "/openapi.json");
+            assertEquals(0, requests.get(), "resolving fetched the resource 
(rest-openapi then read its specification twice)");

Review Comment:
   Nit (non-blocking): the failure message reads a little oddly out of context. 
Something like the below is clearer to whoever sees it fail next:
   
   ```suggestion
               assertEquals(0, requests.get(), "resolving an http: resource 
must not fetch it");
   ```



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