You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2021/03/22 20:16:29 UTC
[camel-quarkus] branch master updated: Add test coverage for FTPS
This is an automated email from the ASF dual-hosted git repository.
aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 98e28d3 Add test coverage for FTPS
98e28d3 is described below
commit 98e28d3d48491ef251a4d1955ab6a95752da13b1
Author: James Netherton <ja...@gmail.com>
AuthorDate: Mon Mar 22 15:42:15 2021 +0000
Add test coverage for FTPS
Fixes #2317
---
.../quarkus/component/ftps/it/FtpsResource.java | 66 +++++++++++++++++++++
.../quarkus/component/ftp/it/FtpTestResource.java | 24 ++++++--
.../camel/quarkus/component/ftps/it/FtpsIT.java | 24 ++++++++
.../it/SftpTest.java => ftps/it/FtpsTest.java} | 30 ++++------
.../component/ftps/it/FtpsTestResource.java | 43 ++++++++++++++
.../camel/quarkus/component/sftp/it/SftpTest.java | 7 +--
.../ftp/src/test/resources/server.jks | Bin 0 -> 2421 bytes
7 files changed, 166 insertions(+), 28 deletions(-)
diff --git a/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/ftps/it/FtpsResource.java b/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/ftps/it/FtpsResource.java
new file mode 100644
index 0000000..47a19ba
--- /dev/null
+++ b/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/ftps/it/FtpsResource.java
@@ -0,0 +1,66 @@
+/*
+ * 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.quarkus.component.ftps.it;
+
+import java.net.URI;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+
+@Path("/ftps")
+@ApplicationScoped
+public class FtpsResource {
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @Inject
+ ConsumerTemplate consumerTemplate;
+
+ @Path("/get/{fileName}")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getFile(@PathParam("fileName") String fileName) throws Exception {
+ return consumerTemplate.receiveBodyNoWait(
+ "ftps://admin@localhost:{{camel.ftps.test-port}}/ftp?password=admin&fileName=" + fileName,
+ String.class);
+ }
+
+ @Path("/create/{fileName}")
+ @POST
+ @Consumes(MediaType.TEXT_PLAIN)
+ public Response createFile(@PathParam("fileName") String fileName, String fileContent)
+ throws Exception {
+ producerTemplate.sendBodyAndHeader("ftps://admin@localhost:{{camel.ftps.test-port}}/ftp?password=admin", fileContent,
+ Exchange.FILE_NAME, fileName);
+ return Response
+ .created(new URI("https://camel.apache.org/"))
+ .build();
+ }
+}
diff --git a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTestResource.java b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTestResource.java
index fbe8b5a..d750632 100644
--- a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTestResource.java
+++ b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTestResource.java
@@ -44,10 +44,19 @@ import org.jboss.logging.Logger;
public class FtpTestResource implements QuarkusTestResourceLifecycleManager {
private static final Logger LOGGER = Logger.getLogger(FtpTestResource.class);
+ private final String componentName;
private FtpServer ftpServer;
private Path ftpRoot;
private Path usrFile;
+ public FtpTestResource() {
+ this("ftp");
+ }
+
+ public FtpTestResource(String componentName) {
+ this.componentName = componentName;
+ }
+
@Override
public Map<String, String> start() {
try {
@@ -78,8 +87,7 @@ public class FtpTestResource implements QuarkusTestResourceLifecycleManager {
user.setAuthorities(authorities);
userMgr.save(user);
- ListenerFactory factory = new ListenerFactory();
- factory.setPort(port);
+ ListenerFactory factory = createListenerFactory(port);
FtpServerFactory serverFactory = new FtpServerFactory();
serverFactory.setUserManager(userMgr);
@@ -92,9 +100,9 @@ public class FtpTestResource implements QuarkusTestResourceLifecycleManager {
ftpServer.start();
return CollectionHelper.mapOf(
- "camel.ftp.test-port", Integer.toString(port),
- "camel.ftp.test-root-dir", ftpRoot.toString(),
- "camel.ftp.test-user-file", usrFile.toString());
+ "camel." + componentName + ".test-port", Integer.toString(port),
+ "camel." + componentName + ".test-root-dir", ftpRoot.toString(),
+ "camel." + componentName + ".test-user-file", usrFile.toString());
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -129,4 +137,10 @@ public class FtpTestResource implements QuarkusTestResourceLifecycleManager {
LOGGER.warn("Failed delete usr file: {}, {}", usrFile, e);
}
}
+
+ protected ListenerFactory createListenerFactory(int port) {
+ ListenerFactory factory = new ListenerFactory();
+ factory.setPort(port);
+ return factory;
+ }
}
diff --git a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsIT.java b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsIT.java
new file mode 100644
index 0000000..f3ea7ef
--- /dev/null
+++ b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.quarkus.component.ftps.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class FtpsIT extends FtpsTest {
+
+}
diff --git a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/sftp/it/SftpTest.java b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTest.java
similarity index 59%
copy from integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/sftp/it/SftpTest.java
copy to integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTest.java
index 1c9c32d..e8f92bc 100644
--- a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/sftp/it/SftpTest.java
+++ b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTest.java
@@ -14,40 +14,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.quarkus.component.sftp.it;
+package org.apache.camel.quarkus.component.ftps.it;
+
+import java.security.NoSuchAlgorithmException;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
-import static org.hamcrest.core.Is.is;
+import static org.hamcrest.CoreMatchers.is;
@QuarkusTest
-@QuarkusTestResource(SftpTestResource.class)
-class SftpTest {
- /*
- * Disabled due to SSL native integration failing in the Jenkins CI environment.
- * https://github.com/apache/camel-quarkus/issues/468"
- */
+@QuarkusTestResource(FtpsTestResource.class)
+class FtpsTest {
@Test
- @DisabledIfEnvironmentVariable(named = "JENKINS_ASF_CI", matches = "true")
- public void testSftpComponent() throws InterruptedException {
- // Create a new file on the SFTP server
+ public void testFtpsComponent() throws InterruptedException, NoSuchAlgorithmException {
+ // Create a new file on the FTPS server
RestAssured.given()
.contentType(ContentType.TEXT)
- .body("Hello Camel Quarkus SFTP")
- .post("/sftp/create/hello.txt")
+ .body("Hello Camel Quarkus FTPS")
+ .post("/ftps/create/hello.txt")
.then()
.statusCode(201);
- // Read file back from the SFTP server
- RestAssured.get("/sftp/get/hello.txt")
+ // Read file back from the FTPS server
+ RestAssured.get("/ftps/get/hello.txt")
.then()
.statusCode(200)
- .body(is("Hello Camel Quarkus SFTP"));
+ .body(is("Hello Camel Quarkus FTPS"));
}
}
diff --git a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTestResource.java b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTestResource.java
new file mode 100644
index 0000000..cdbbca5
--- /dev/null
+++ b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTestResource.java
@@ -0,0 +1,43 @@
+/*
+ * 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.quarkus.component.ftps.it;
+
+import java.io.File;
+
+import org.apache.camel.quarkus.component.ftp.it.FtpTestResource;
+import org.apache.ftpserver.listener.ListenerFactory;
+import org.apache.ftpserver.ssl.SslConfigurationFactory;
+
+public class FtpsTestResource extends FtpTestResource {
+
+ public FtpsTestResource() {
+ super("ftps");
+ }
+
+ @Override
+ protected ListenerFactory createListenerFactory(int port) {
+ SslConfigurationFactory sslConfigFactory = new SslConfigurationFactory();
+ sslConfigFactory.setKeystoreFile(new File("server.jks"));
+ sslConfigFactory.setKeystoreType("PKCS12");
+ sslConfigFactory.setKeystorePassword("password");
+ sslConfigFactory.setKeyPassword("password");
+
+ ListenerFactory factory = super.createListenerFactory(port);
+ factory.setSslConfiguration(sslConfigFactory.createSslConfiguration());
+ return factory;
+ }
+}
diff --git a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/sftp/it/SftpTest.java b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/sftp/it/SftpTest.java
index 1c9c32d..63366da 100644
--- a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/sftp/it/SftpTest.java
+++ b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/sftp/it/SftpTest.java
@@ -21,19 +21,14 @@ import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
import static org.hamcrest.core.Is.is;
@QuarkusTest
@QuarkusTestResource(SftpTestResource.class)
class SftpTest {
- /*
- * Disabled due to SSL native integration failing in the Jenkins CI environment.
- * https://github.com/apache/camel-quarkus/issues/468"
- */
+
@Test
- @DisabledIfEnvironmentVariable(named = "JENKINS_ASF_CI", matches = "true")
public void testSftpComponent() throws InterruptedException {
// Create a new file on the SFTP server
RestAssured.given()
diff --git a/integration-tests/ftp/src/test/resources/server.jks b/integration-tests/ftp/src/test/resources/server.jks
new file mode 100644
index 0000000..8063722
Binary files /dev/null and b/integration-tests/ftp/src/test/resources/server.jks differ