This is an automated email from the ASF dual-hosted git repository. aldettinger 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 4e1334d Added move and delete tests for FTP extension #2645 4e1334d is described below commit 4e1334dec370312a32c59850bac54fcce5792533 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Wed Jun 2 17:57:30 2021 +0200 Added move and delete tests for FTP extension #2645 --- .../quarkus/component/ftp/it/FtpResource.java | 28 +++++++++++++++++-- .../quarkus/component/ftps/it/FtpsResource.java | 32 +++++++++++++++++++--- .../quarkus/component/sftp/it/SftpResource.java | 28 +++++++++++++++++-- .../camel/quarkus/component/ftp/it/FtpTest.java | 28 ++++++++++++++++++- .../camel/quarkus/component/ftps/it/FtpsTest.java | 30 ++++++++++++++++++-- .../camel/quarkus/component/sftp/it/SftpTest.java | 30 ++++++++++++++++++-- 6 files changed, 162 insertions(+), 14 deletions(-) diff --git a/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/ftp/it/FtpResource.java b/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/ftp/it/FtpResource.java index d2cbfb3..0e87e4f 100644 --- a/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/ftp/it/FtpResource.java +++ b/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/ftp/it/FtpResource.java @@ -21,8 +21,10 @@ import java.net.URI; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -37,6 +39,8 @@ import org.apache.camel.ProducerTemplate; @ApplicationScoped public class FtpResource { + private static final long TIMEOUT_MS = 1000; + @Inject ProducerTemplate producerTemplate; @@ -46,9 +50,10 @@ public class FtpResource { @Path("/get/{fileName}") @GET @Produces(MediaType.TEXT_PLAIN) - public String getFile(@PathParam("fileName") String fileName) throws Exception { - return consumerTemplate.receiveBodyNoWait( + public String getFile(@PathParam("fileName") String fileName) { + return consumerTemplate.receiveBody( "ftp://admin@localhost:{{camel.ftp.test-port}}/ftp?password=admin&fileName=" + fileName, + TIMEOUT_MS, String.class); } @@ -63,4 +68,23 @@ public class FtpResource { .created(new URI("https://camel.apache.org/")) .build(); } + + @Path("/delete/{fileName}") + @DELETE + public void deleteFile(@PathParam("fileName") String fileName) { + consumerTemplate.receiveBody( + "ftp://admin@localhost:{{camel.ftp.test-port}}/ftp?password=admin&delete=true&fileName=" + fileName, + TIMEOUT_MS, + String.class); + } + + @Path("/moveToDoneFile/{fileName}") + @PUT + public void moveToDoneFile(@PathParam("fileName") String fileName) { + consumerTemplate.receiveBody( + "ftp://admin@localhost:{{camel.ftp.test-port}}/ftp?password=admin&move=${headers.CamelFileName}.done&fileName=" + + fileName, + TIMEOUT_MS, + String.class); + } } 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 index 47a19ba..52dd4dd 100644 --- 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 @@ -21,8 +21,10 @@ import java.net.URI; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -37,6 +39,8 @@ import org.apache.camel.ProducerTemplate; @ApplicationScoped public class FtpsResource { + private static final long TIMEOUT_MS = 1000; + @Inject ProducerTemplate producerTemplate; @@ -46,9 +50,10 @@ public class FtpsResource { @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, + public String getFile(@PathParam("fileName") String fileName) { + return consumerTemplate.receiveBody( + "ftps://admin@localhost:{{camel.ftps.test-port}}/ftps?password=admin&fileName=" + fileName, + TIMEOUT_MS, String.class); } @@ -57,10 +62,29 @@ public class FtpsResource { @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, + producerTemplate.sendBodyAndHeader("ftps://admin@localhost:{{camel.ftps.test-port}}/ftps?password=admin", fileContent, Exchange.FILE_NAME, fileName); return Response .created(new URI("https://camel.apache.org/")) .build(); } + + @Path("/delete/{fileName}") + @DELETE + public void deleteFile(@PathParam("fileName") String fileName) { + consumerTemplate.receiveBody( + "ftps://admin@localhost:{{camel.ftps.test-port}}/ftps?password=admin&delete=true&fileName=" + fileName, + TIMEOUT_MS, + String.class); + } + + @Path("/moveToDoneFile/{fileName}") + @PUT + public void moveToDoneFile(@PathParam("fileName") String fileName) { + consumerTemplate.receiveBody( + "ftps://admin@localhost:{{camel.ftps.test-port}}/ftps?password=admin&move=${headers.CamelFileName}.done&fileName=" + + fileName, + TIMEOUT_MS, + String.class); + } } diff --git a/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/sftp/it/SftpResource.java b/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/sftp/it/SftpResource.java index fe0dfb2..e9dedea 100644 --- a/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/sftp/it/SftpResource.java +++ b/integration-tests/ftp/src/main/java/org/apache/camel/quarkus/component/sftp/it/SftpResource.java @@ -21,8 +21,10 @@ import java.net.URI; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -37,6 +39,8 @@ import org.apache.camel.ProducerTemplate; @ApplicationScoped public class SftpResource { + private static final long TIMEOUT_MS = 1000; + @Inject ProducerTemplate producerTemplate; @@ -46,10 +50,11 @@ public class SftpResource { @Path("/get/{fileName}") @GET @Produces(MediaType.TEXT_PLAIN) - public String getFile(@PathParam("fileName") String fileName) throws Exception { - return consumerTemplate.receiveBodyNoWait( + public String getFile(@PathParam("fileName") String fileName) { + return consumerTemplate.receiveBody( "sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?password=admin&localWorkDirectory=target&fileName=" + fileName, + TIMEOUT_MS, String.class); } @@ -64,4 +69,23 @@ public class SftpResource { .created(new URI("https://camel.apache.org/")) .build(); } + + @Path("/delete/{fileName}") + @DELETE + public void deleteFile(@PathParam("fileName") String fileName) { + consumerTemplate.receiveBody( + "sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?password=admin&delete=true&fileName=" + fileName, + TIMEOUT_MS, + String.class); + } + + @Path("/moveToDoneFile/{fileName}") + @PUT + public void moveToDoneFile(@PathParam("fileName") String fileName) { + consumerTemplate.receiveBody( + "sftp://admin@localhost:{{camel.sftp.test-port}}/sftp?password=admin&move=${headers.CamelFileName}.done&fileName=" + + fileName, + TIMEOUT_MS, + String.class); + } } diff --git a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTest.java b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTest.java index 6b20b91..88e4cd4 100644 --- a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTest.java +++ b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftp/it/FtpTest.java @@ -28,7 +28,7 @@ import static org.hamcrest.CoreMatchers.is; @QuarkusTestResource(FtpTestResource.class) class FtpTest { @Test - public void testFtpComponent() throws InterruptedException { + public void testFtpComponent() { // Create a new file on the FTP server RestAssured.given() .contentType(ContentType.TEXT) @@ -42,6 +42,32 @@ class FtpTest { .then() .statusCode(200) .body(is("Hello Camel Quarkus FTP")); + + // Rename the file to {file}.done + RestAssured.put("/ftp/moveToDoneFile/hello.txt") + .then() + .statusCode(204); + + // Check that the file is no more present in its initial place + RestAssured.get("/ftp/get/hello.txt") + .then() + .statusCode(204); + + // Check that the file has been renamed to {file}.done + RestAssured.get("/ftp/get/hello.txt.done") + .then() + .statusCode(200) + .body(is("Hello Camel Quarkus FTP")); + + // Delete the {file}.done file + RestAssured.delete("/ftp/delete/hello.txt.done") + .then() + .statusCode(204); + + // Check that {file}.done file has been deleted from the FTP server + RestAssured.get("/ftp/get/hello.txt.done") + .then() + .statusCode(204); } } diff --git a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTest.java b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTest.java index e8f92bc..288faa9 100644 --- a/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTest.java +++ b/integration-tests/ftp/src/test/java/org/apache/camel/quarkus/component/ftps/it/FtpsTest.java @@ -16,8 +16,6 @@ */ 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; @@ -30,7 +28,7 @@ import static org.hamcrest.CoreMatchers.is; @QuarkusTestResource(FtpsTestResource.class) class FtpsTest { @Test - public void testFtpsComponent() throws InterruptedException, NoSuchAlgorithmException { + public void testFtpsComponent() { // Create a new file on the FTPS server RestAssured.given() .contentType(ContentType.TEXT) @@ -44,6 +42,32 @@ class FtpsTest { .then() .statusCode(200) .body(is("Hello Camel Quarkus FTPS")); + + // Rename the file to {file}.done + RestAssured.put("/ftps/moveToDoneFile/hello.txt") + .then() + .statusCode(204); + + // Check that the file is no more present in its initial place + RestAssured.get("/ftps/get/hello.txt") + .then() + .statusCode(204); + + // Check that the file has been renamed to {file}.done + RestAssured.get("/ftps/get/hello.txt.done") + .then() + .statusCode(200) + .body(is("Hello Camel Quarkus FTPS")); + + // Delete the {file}.done file + RestAssured.delete("/ftps/delete/hello.txt.done") + .then() + .statusCode(204); + + // Check that {file}.done file has been deleted from the FTPS server + RestAssured.get("/ftps/get/hello.txt.done") + .then() + .statusCode(204); } } 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 63366da..d3a4af9 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 @@ -22,14 +22,14 @@ import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.jupiter.api.Test; -import static org.hamcrest.core.Is.is; +import static org.hamcrest.CoreMatchers.is; @QuarkusTest @QuarkusTestResource(SftpTestResource.class) class SftpTest { @Test - public void testSftpComponent() throws InterruptedException { + public void testSftpComponent() { // Create a new file on the SFTP server RestAssured.given() .contentType(ContentType.TEXT) @@ -43,6 +43,32 @@ class SftpTest { .then() .statusCode(200) .body(is("Hello Camel Quarkus SFTP")); + + // Rename the file to {file}.done + RestAssured.put("/sftp/moveToDoneFile/hello.txt") + .then() + .statusCode(204); + + // Check that the file is no more present in its initial place + RestAssured.get("/sftp/get/hello.txt") + .then() + .statusCode(204); + + // Check that the file has been renamed to {file}.done + RestAssured.get("/sftp/get/hello.txt.done") + .then() + .statusCode(200) + .body(is("Hello Camel Quarkus SFTP")); + + // Delete the {file}.done file + RestAssured.delete("/sftp/delete/hello.txt.done") + .then() + .statusCode(204); + + // Check that {file}.done file has been deleted from the SFTP server + RestAssured.get("/sftp/get/hello.txt.done") + .then() + .statusCode(204); } }