This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new 95cfc1e226 Smb: extend coverage with test using path parameter
95cfc1e226 is described below

commit 95cfc1e226311335ea4b06f169500af04ab662d8
Author: Jiri Ondrusek <ondrusek.j...@gmail.com>
AuthorDate: Tue Mar 4 16:49:43 2025 +0100

    Smb: extend coverage with test using path parameter
---
 .../quarkus/component/smb/it/SmbResource.java      | 19 +++++++++---
 .../camel/quarkus/component/smb/it/SmbTest.java    | 34 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git 
a/integration-tests/smb/src/main/java/org/apache/camel/quarkus/component/smb/it/SmbResource.java
 
b/integration-tests/smb/src/main/java/org/apache/camel/quarkus/component/smb/it/SmbResource.java
index 5eca5899c4..5016e9e705 100644
--- 
a/integration-tests/smb/src/main/java/org/apache/camel/quarkus/component/smb/it/SmbResource.java
+++ 
b/integration-tests/smb/src/main/java/org/apache/camel/quarkus/component/smb/it/SmbResource.java
@@ -73,8 +73,13 @@ public class SmbResource {
     @Path("/send/{fileName}")
     public void send(String content,
             @PathParam("fileName") String fileName,
-            @QueryParam("fileExist") String fileExist) throws Exception {
-        if (fileExist == null || fileExist.isEmpty()) {
+            @QueryParam("fileExist") String fileExist,
+            @QueryParam("path") String path) throws Exception {
+        if (path != null && !path.isEmpty()) {
+            producer.sendBodyAndHeader(
+                    
"smb:%s:%s/%s?username=%s&password=%s&path=%s".formatted(host, port, share, 
username, password, path),
+                    content, Exchange.FILE_NAME, fileName);
+        } else if (fileExist == null || fileExist.isEmpty()) {
             producer.sendBodyAndHeader("direct:send", content, 
Exchange.FILE_NAME, fileName);
         } else {
             producer.sendBodyAndHeaders("direct:send", content, 
Map.of(SmbConstants.SMB_FILE_EXISTS, fileExist,
@@ -84,10 +89,16 @@ public class SmbResource {
 
     @POST
     @Path("/receive")
-    public String receive(String fileName) throws Exception {
+    public String receive(String fileName,
+            @QueryParam("path") String path) throws Exception {
 
-        String uri = 
String.format("smb:%s:%s/%s?username=%s&password=%s&searchPattern=%s&path=/", 
host, port, share,
+        String uri = 
String.format("smb:%s:%s/%s?username=%s&password=%s&searchPattern=%s&path=", 
host, port, share,
                 username, password, fileName);
+        if (path != null && !path.isEmpty()) {
+            uri = uri + path;
+        } else {
+            uri = uri + "/";
+        }
         var shareFile = consumer.receiveBody(uri, SmbFile.class);
         return new String((byte[]) shareFile.getBody(), "UTF-8");
     }
diff --git 
a/integration-tests/smb/src/test/java/org/apache/camel/quarkus/component/smb/it/SmbTest.java
 
b/integration-tests/smb/src/test/java/org/apache/camel/quarkus/component/smb/it/SmbTest.java
index 5d51af934c..a4831c223e 100644
--- 
a/integration-tests/smb/src/test/java/org/apache/camel/quarkus/component/smb/it/SmbTest.java
+++ 
b/integration-tests/smb/src/test/java/org/apache/camel/quarkus/component/smb/it/SmbTest.java
@@ -59,6 +59,40 @@ public class SmbTest {
                 .body(Matchers.equalTo("Hello"));
     }
 
+    @Test
+    public void testSendReceiveWithPath() {
+
+        RestAssured.given()
+                .body("Hello from directory 1")
+                .queryParam("path", "dir1")
+                .post("/smb/send/hello.doc")
+                .then()
+                .statusCode(204);
+
+        RestAssured.given()
+                .body("Hello from directory 2")
+                .queryParam("path", "dir2")
+                .post("/smb/send/hello.doc")
+                .then()
+                .statusCode(204);
+
+        RestAssured.given()
+                .body("hello.doc")
+                .queryParam("path", "dir1")
+                .post("/smb/receive")
+                .then()
+                .statusCode(200)
+                .body(Matchers.equalTo("Hello from directory 1"));
+
+        RestAssured.given()
+                .body("hello.doc")
+                .queryParam("path", "dir2")
+                .post("/smb/receive")
+                .then()
+                .statusCode(200)
+                .body(Matchers.equalTo("Hello from directory 2"));
+    }
+
     @Test
     public void testFileExistsOverride() {
 

Reply via email to