Skip to content

Commit

Permalink
Fixed smb + enabled CamelAutowiredDisabledTest
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Jan 6, 2025
1 parent 29f6e05 commit 77282d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/examples/components/smb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ cqJvmSince: 3.7.0
cqNativeSince: 3.7.0
cqCamelPartName: smb
cqCamelPartTitle: SMB
cqCamelPartDescription: Receive files from SMB (Server Message Block) shares.
cqCamelPartDescription: Read and write files to Server Message Block (SMB) file shares.
cqExtensionPageTitle: SMB
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.assertj.core.api.Assertions.assertThat;

@Disabled //https://github.com/apache/camel-quarkus/issues/6884
public class CamelAutowiredDisabledTest {
@RegisterExtension
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public String receive(String fileName) throws Exception {
String uri = String.format("smb:%s:%s/%s?username=%s&password=%s&searchPattern=%s&path=/", host, port, share,
username, password, fileName);
var shareFile = consumer.receiveBody(uri, SmbFile.class);
return new String(shareFile.getInputStream().readAllBytes(), "UTF-8");
return new String((byte[]) shareFile.getBody(), "UTF-8");
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.smb.SmbConstants;
import org.apache.camel.component.smb.SmbFile;
import org.apache.camel.spi.IdempotentRepository;
import org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped
Expand All @@ -54,19 +56,18 @@ public class SmbRoute extends RouteBuilder {

@Override
public void configure() throws Exception {
from("smb:{{smb.host}}:{{smb.port}}/{{smb.share}}?username={{smb.username}}&password={{smb.password}}&path=/&repeatCount=1&searchPattern=*.txt")
from("smb:{{smb.host}}:{{smb.port}}/{{smb.share}}?username={{smb.username}}&password={{smb.password}}&path=/&repeatCount=1&searchPattern=*.txt&idempotent=true&idempotentRepository=#myRepo")
.to("mock:result");

from("direct:send")
.toF("smb:%s:%s/%s?username=%s&password=%s&path=/", host, port, share, username, password);

from("smb:{{smb.host}}:{{smb.port}}/{{smb.share}}?username={{smb.username}}&password={{smb.password}}&path=/&searchPattern=*.tx1")
from("smb:{{smb.host}}:{{smb.port}}/{{smb.share}}?username={{smb.username}}&password={{smb.password}}&path=/&searchPattern=*.tx1&idempotent=true&idempotentRepository=#myRepo")
.process(e -> {
receivedContents.add(Map.of(
"path", e.getIn().getBody(SmbFile.class).getPath(),
"content", new String(e.getIn().getBody(SmbFile.class).getInputStream().readAllBytes(), "UTF-8"),
SmbConstants.SMB_FILE_PATH, e.getIn().getHeader(SmbConstants.SMB_FILE_PATH, String.class),
SmbConstants.SMB_UNC_PATH, e.getIn().getHeader(SmbConstants.SMB_UNC_PATH, String.class)));
"path", e.getIn().getBody(SmbFile.class).getAbsoluteFilePath(),
"content", new String((byte[]) e.getIn().getBody(SmbFile.class).getBody(), "UTF-8"),
SmbConstants.FILE_PATH, e.getIn().getHeader(SmbConstants.FILE_PATH, String.class)));
});
}

Expand All @@ -80,4 +81,10 @@ List<Map<String, String>> smbReceivedMsgs() {
}
}

@Produces
@Named("myRepo")
public IdempotentRepository myRepo() {
return MemoryIdempotentRepository.memoryIdempotentRepository(2000);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.restassured.RestAssured;
import org.apache.camel.component.smb.SmbConstants;
import org.apache.camel.quarkus.test.DisabledIfFipsMode;
import org.eclipse.microprofile.config.ConfigProvider;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.testcontainers.shaded.org.awaitility.Awaitility;
Expand Down Expand Up @@ -126,13 +125,10 @@ public void testHeadersAndAutoConvertToInputStream() {

Set<String> set = Set.of(body.split(","));

String host = ConfigProvider.getConfig().getValue("smb.host", String.class);

assertThat(set)
.contains("path=msg1.tx1")
.contains("path=/msg1.tx1")
.contains("content=Hello1")
.contains(SmbConstants.SMB_FILE_PATH + "=msg1.tx1")
.contains(SmbConstants.SMB_UNC_PATH + "=\\\\%s\\data-rw\\msg1.tx1".formatted(host));
.contains(SmbConstants.FILE_PATH + "=/msg1.tx1");
});

}
Expand Down

0 comments on commit 77282d9

Please sign in to comment.