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 2520dea5ca Avoid mina-sftp tests reading classpath resources directly
from the source tree
2520dea5ca is described below
commit 2520dea5ca526a68464b182adeb78e41602ee623
Author: James Netherton <[email protected]>
AuthorDate: Wed Mar 18 11:06:26 2026 +0000
Avoid mina-sftp tests reading classpath resources directly from the source
tree
---
.../component/mina/sftp/it/MinaSftpResource.java | 76 +++++++++++++---------
.../src/main/resources/application.properties | 17 +++++
.../resources/certs}/generate-certificates.sh | 0
.../resources/certs}/test-key-rsa-cert.pub | 0
.../resources/certs}/test-key-rsa.key | 0
5 files changed, 64 insertions(+), 29 deletions(-)
diff --git
a/integration-tests/mina-sftp/src/main/java/org/apache/camel/quarkus/component/mina/sftp/it/MinaSftpResource.java
b/integration-tests/mina-sftp/src/main/java/org/apache/camel/quarkus/component/mina/sftp/it/MinaSftpResource.java
index e0f84b8853..3f6963305e 100644
---
a/integration-tests/mina-sftp/src/main/java/org/apache/camel/quarkus/component/mina/sftp/it/MinaSftpResource.java
+++
b/integration-tests/mina-sftp/src/main/java/org/apache/camel/quarkus/component/mina/sftp/it/MinaSftpResource.java
@@ -16,9 +16,8 @@
*/
package org.apache.camel.quarkus.component.mina.sftp.it;
+import java.io.InputStream;
import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -217,7 +216,7 @@ public class MinaSftpResource {
public Response createFileWithCertificate(@PathParam("fileName") String
fileName, String fileContent)
throws Exception {
producerTemplate.sendBodyAndHeader(
-
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyFile=src/test/resources/test-key-rsa.key&certFile=src/test/resources/test-key-rsa-cert.pub",
+
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyUri=certs/test-key-rsa.key&certUri=certs/test-key-rsa-cert.pub",
fileContent,
Exchange.FILE_NAME, fileName);
return Response
@@ -230,7 +229,7 @@ public class MinaSftpResource {
@Produces(MediaType.TEXT_PLAIN)
public String getFileWithCertificate(@PathParam("fileName") String
fileName) {
return consumerTemplate.receiveBody(
-
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyFile=src/test/resources/test-key-rsa.key&certFile=src/test/resources/test-key-rsa-cert.pub&localWorkDirectory=target&fileName="
+
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyUri=certs/test-key-rsa.key&certUri=certs/test-key-rsa-cert.pub&localWorkDirectory=target&fileName="
+ fileName,
TIMEOUT_MS,
String.class);
@@ -242,7 +241,7 @@ public class MinaSftpResource {
public Response createFileWithCertificateUri(@PathParam("fileName") String
fileName, String fileContent)
throws Exception {
producerTemplate.sendBodyAndHeader(
-
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyUri=file:src/test/resources/test-key-rsa.key&certUri=file:src/test/resources/test-key-rsa-cert.pub",
+
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyUri=certs/test-key-rsa.key&certUri=certs/test-key-rsa-cert.pub",
fileContent,
Exchange.FILE_NAME, fileName);
return Response
@@ -255,7 +254,7 @@ public class MinaSftpResource {
@Produces(MediaType.TEXT_PLAIN)
public String getFileWithCertificateUri(@PathParam("fileName") String
fileName) {
return consumerTemplate.receiveBody(
-
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyUri=file:src/test/resources/test-key-rsa.key&certUri=file:src/test/resources/test-key-rsa-cert.pub&localWorkDirectory=target&fileName="
+
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?privateKeyUri=certs/test-key-rsa.key&certUri=certs/test-key-rsa-cert.pub&localWorkDirectory=target&fileName="
+ fileName,
TIMEOUT_MS,
String.class);
@@ -266,36 +265,55 @@ public class MinaSftpResource {
@Consumes(MediaType.TEXT_PLAIN)
public Response createFileWithCertificateBytes(@PathParam("fileName")
String fileName, String fileContent)
throws Exception {
- byte[] certBytes =
Files.readAllBytes(Paths.get("src/test/resources/test-key-rsa-cert.pub"));
- byte[] keyBytes =
Files.readAllBytes(Paths.get("src/test/resources/test-key-rsa.key"));
- String uri =
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp";
- MinaSftpEndpoint endpoint = context.getEndpoint(uri,
MinaSftpEndpoint.class);
- MinaSftpConfiguration config = (MinaSftpConfiguration)
endpoint.getConfiguration();
- config.setCertBytes(certBytes);
- config.setPrivateKey(keyBytes);
-
- producerTemplate.sendBodyAndHeader(endpoint, fileContent,
Exchange.FILE_NAME, fileName);
- return Response
- .created(new URI("https://camel.apache.org/"))
- .build();
+ ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
+ try (InputStream certStream =
classLoader.getResourceAsStream("certs/test-key-rsa-cert.pub");
+ InputStream keyStream =
classLoader.getResourceAsStream("certs/test-key-rsa.key")) {
+ if (certStream == null) {
+ throw new RuntimeException("Failed reading cert file");
+ }
+
+ if (keyStream == null) {
+ throw new RuntimeException("Failed reading key file");
+ }
+
+ String uri =
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp";
+ MinaSftpEndpoint endpoint = context.getEndpoint(uri,
MinaSftpEndpoint.class);
+ MinaSftpConfiguration config = endpoint.getConfiguration();
+ config.setCertBytes(certStream.readAllBytes());
+ config.setPrivateKey(keyStream.readAllBytes());
+
+ producerTemplate.sendBodyAndHeader(endpoint, fileContent,
Exchange.FILE_NAME, fileName);
+ return Response
+ .created(new URI("https://camel.apache.org/"))
+ .build();
+ }
}
@Path("/certificateBytes/get/{fileName}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getFileWithCertificateBytes(@PathParam("fileName") String
fileName) throws Exception {
- byte[] certBytes =
Files.readAllBytes(Paths.get("src/test/resources/test-key-rsa-cert.pub"));
- byte[] keyBytes =
Files.readAllBytes(Paths.get("src/test/resources/test-key-rsa.key"));
-
- String uri =
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?localWorkDirectory=target&fileName="
- + fileName;
- MinaSftpEndpoint endpoint = context.getEndpoint(uri,
MinaSftpEndpoint.class);
- MinaSftpConfiguration config = (MinaSftpConfiguration)
endpoint.getConfiguration();
- config.setCertBytes(certBytes);
- config.setPrivateKey(keyBytes);
-
- return consumerTemplate.receiveBody(endpoint, TIMEOUT_MS,
String.class);
+ ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
+ try (InputStream certStream =
classLoader.getResourceAsStream("certs/test-key-rsa-cert.pub");
+ InputStream keyStream =
classLoader.getResourceAsStream("certs/test-key-rsa.key")) {
+ if (certStream == null) {
+ throw new RuntimeException("Failed reading cert file");
+ }
+
+ if (keyStream == null) {
+ throw new RuntimeException("Failed reading key file");
+ }
+
+ String uri =
"mina-sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?localWorkDirectory=target&fileName="
+ + fileName;
+ MinaSftpEndpoint endpoint = context.getEndpoint(uri,
MinaSftpEndpoint.class);
+ MinaSftpConfiguration config = endpoint.getConfiguration();
+ config.setCertBytes(certStream.readAllBytes());
+ config.setPrivateKey(keyStream.readAllBytes());
+
+ return consumerTemplate.receiveBody(endpoint, TIMEOUT_MS,
String.class);
+ }
}
@Path("/compression/create/{fileName}")
diff --git
a/integration-tests/mina-sftp/src/main/resources/application.properties
b/integration-tests/mina-sftp/src/main/resources/application.properties
new file mode 100644
index 0000000000..59099f9fb7
--- /dev/null
+++ b/integration-tests/mina-sftp/src/main/resources/application.properties
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+quarkus.native.resources.includes=certs/test-key-rsa.key,certs/test-key-rsa-cert.pub
\ No newline at end of file
diff --git
a/integration-tests/mina-sftp/src/test/resources/generate-certificates.sh
b/integration-tests/mina-sftp/src/main/resources/certs/generate-certificates.sh
similarity index 100%
rename from
integration-tests/mina-sftp/src/test/resources/generate-certificates.sh
rename to
integration-tests/mina-sftp/src/main/resources/certs/generate-certificates.sh
diff --git
a/integration-tests/mina-sftp/src/test/resources/test-key-rsa-cert.pub
b/integration-tests/mina-sftp/src/main/resources/certs/test-key-rsa-cert.pub
similarity index 100%
rename from integration-tests/mina-sftp/src/test/resources/test-key-rsa-cert.pub
rename to
integration-tests/mina-sftp/src/main/resources/certs/test-key-rsa-cert.pub
diff --git a/integration-tests/mina-sftp/src/test/resources/test-key-rsa.key
b/integration-tests/mina-sftp/src/main/resources/certs/test-key-rsa.key
similarity index 100%
rename from integration-tests/mina-sftp/src/test/resources/test-key-rsa.key
rename to integration-tests/mina-sftp/src/main/resources/certs/test-key-rsa.key