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

davsclaus pushed a commit to branch CAMEL-27368-smb-sortby-move-delete
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 83c3ad2241c7a6b4f0fb0876b33a0cea969ce745
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 09:59:38 2026 +0100

    CAMEL-27368: camel-smb - sortBy with reverse: or ignoreCase: fails, and 
move with delete does not fail at startup
    
    SmbComponent.buildFileEndpoint set the endpoint options before
    GenericFileComponent.createEndpoint parsed sortBy, so sortBy was bound
    as a plain file language expression and reverse:, ignoreCase: and ;
    groups failed with "Unknown function". The options are now set by
    GenericFileComponent only, as for the ftp component.
    
    The consumer refuses delete=true together with move, like the file and
    ftp components, instead of deleting the files and ignoring move.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../apache/camel/component/smb/SmbComponent.java   |  6 +-
 .../apache/camel/component/smb/SmbEndpoint.java    |  4 ++
 .../component/smb/FromSmbFileSortByReverseIT.java  | 56 +++++++++++++++++
 .../camel/component/smb/SmbEndpointSortByTest.java | 70 ++++++++++++++++++++++
 4 files changed, 133 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbComponent.java
 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbComponent.java
index 5ea3bba70db0..aab12eec5801 100644
--- 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbComponent.java
+++ 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbComponent.java
@@ -67,9 +67,9 @@ public class SmbComponent extends 
GenericFileComponent<FileIdBothDirectoryInform
             throw new IllegalArgumentException("ShareName must be configured");
         }
 
-        SmbEndpoint endpoint = new SmbEndpoint(uri, this, config);
-        setProperties(endpoint, parameters);
-        return endpoint;
+        // the options are set by GenericFileComponent.createEndpoint, after 
it parses sortBy (reverse:, ignoreCase:
+        // and ; groups)
+        return new SmbEndpoint(uri, this, config);
     }
 
     @Override
diff --git 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
index fe44cac7d235..29c284fbdd08 100644
--- 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
+++ 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbEndpoint.java
@@ -173,6 +173,10 @@ public class SmbEndpoint extends 
GenericFileEndpoint<FileIdBothDirectoryInformat
 
     @Override
     public GenericFileConsumer<FileIdBothDirectoryInformation> 
createConsumer(Processor processor) throws Exception {
+        if (isDelete() && getMove() != null) {
+            throw new IllegalArgumentException("You cannot set both 
delete=true and move options");
+        }
+
         // if noop=true then idempotent should also be configured
         if (isNoop() && !isIdempotentSet()) {
             LOG.info("Endpoint is configured with noop=true so forcing 
endpoint to be idempotent as well");
diff --git 
a/components/camel-smb/src/test/java/org/apache/camel/component/smb/FromSmbFileSortByReverseIT.java
 
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/FromSmbFileSortByReverseIT.java
new file mode 100644
index 000000000000..34a8bed5d43c
--- /dev/null
+++ 
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/FromSmbFileSortByReverseIT.java
@@ -0,0 +1,56 @@
+/*
+ * 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.component.smb;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+/**
+ * sortBy with reverse:, ignoreCase: and ; groups, which failed with "Unknown 
function: reverse:file:name" before.
+ */
+public class FromSmbFileSortByReverseIT extends SmbServerTestSupport {
+
+    protected String getSmbUrl() {
+        return String.format(
+                
"smb:%s/%s/sortby-reverse?username=%s&password=%s&sortBy=file:ext;reverse:ignoreCase:file:name&initialDelay=3000",
+                service.address(), service.shareName(), service.username(), 
service.password());
+    }
+
+    @Override
+    public void doPostSetup() throws Exception {
+        sendFile(getSmbUrl(), "Hello Paris", "paris.txt");
+        sendFile(getSmbUrl(), "Hello London", "London.txt");
+        sendFile(getSmbUrl(), "Hello Copenhagen", "copenhagen.dat");
+    }
+
+    @Test
+    public void testSortFiles() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from(getSmbUrl()).to("mock:result");
+            }
+        });
+        context.start();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello Copenhagen", "Hello Paris", "Hello 
London");
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+}
diff --git 
a/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbEndpointSortByTest.java
 
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbEndpointSortByTest.java
new file mode 100644
index 000000000000..5af9b2a80f9d
--- /dev/null
+++ 
b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbEndpointSortByTest.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.camel.component.smb;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.file.GenericFileEndpoint;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * The smb endpoint parses sortBy and checks the consumer options like the 
file component.
+ */
+class SmbEndpointSortByTest extends CamelTestSupport {
+
+    @ParameterizedTest
+    @CsvSource(delimiter = '|', value = {
+            "file:name                         | B.txt,a.txt,c.dat,d.txt",
+            "reverse:file:name                 | d.txt,c.dat,a.txt,B.txt",
+            "ignoreCase:file:name              | a.txt,B.txt,c.dat,d.txt",
+            "reverse:ignoreCase:file:name      | d.txt,c.dat,B.txt,a.txt",
+            "file:ext;reverse:ignoreCase:file:name | c.dat,d.txt,B.txt,a.txt" 
})
+    void sortBy(String sortBy, String expected) {
+        GenericFileEndpoint<?> endpoint
+                = context.getEndpoint("smb:localhost/share?sortBy=" + sortBy, 
GenericFileEndpoint.class);
+
+        List<Exchange> exchanges = new ArrayList<>();
+        for (String name : List.of("c.dat", "a.txt", "d.txt", "B.txt")) {
+            Exchange exchange = new DefaultExchange(context);
+            exchange.getMessage().setHeader(Exchange.FILE_NAME, name);
+            exchanges.add(exchange);
+        }
+        exchanges.sort(endpoint.getSortBy());
+
+        assertEquals(List.of(expected.split(",")),
+                exchanges.stream().map(e -> 
e.getMessage().getHeader(Exchange.FILE_NAME, String.class)).toList());
+    }
+
+    @Test
+    void moveWithDeleteFails() {
+        GenericFileEndpoint<?> endpoint
+                = 
context.getEndpoint("smb:localhost/share?delete=true&move=done", 
GenericFileEndpoint.class);
+
+        IllegalArgumentException e = 
assertThrows(IllegalArgumentException.class, () -> 
endpoint.createConsumer(exchange -> {
+        }));
+        assertEquals("You cannot set both delete=true and move options", 
e.getMessage());
+    }
+}

Reply via email to