JiriOndrusek commented on a change in pull request #2548:
URL: https://github.com/apache/camel-quarkus/pull/2548#discussion_r625599625



##########
File path: 
integration-tests/file/src/main/java/org/apache/camel/quarkus/component/file/it/FileResource.java
##########
@@ -26,36 +29,102 @@
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
 
 @Path("/file")
 @ApplicationScoped
 public class FileResource {
 
+    public static String CONSUME_BATCH = "consumeBatch";
+    public static String SORT_BY = "sortBy";
+    public static String SEPARATOR = ";";
+
     @Inject
     ProducerTemplate producerTemplate;
 
     @Inject
     ConsumerTemplate consumerTemplate;
 
+    @Inject
+    CamelContext context;
+
     @Path("/get/{folder}/{name}")
-    @GET
+    @POST

Review comment:
       done

##########
File path: 
integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java
##########
@@ -99,36 +200,78 @@ public void fileReadLock_minLength() throws Exception {
         Thread.sleep(10_000L);
 
         // Read the file that should not be there
-        RestAssured
-                .get("/file/get/{folder}/{name}", FileRoutes.READ_LOCK_OUT, 
Paths.get(fileName).getFileName())
+        RestAssured.given()
+                .post("/file/get/{folder}/{name}", FileRoutes.READ_LOCK_OUT, 
Paths.get(fileName).getFileName())
                 .then()
                 .statusCode(204);
     }
 
     @Test
     public void quartzSchedulerFilePollingConsumer() throws 
InterruptedException {
-        String fileName = RestAssured.given()
-                .contentType(ContentType.TEXT)
-                .body(FILE_BODY)
-                .post("/file/create/quartz")
-                .then()
-                .statusCode(201)
-                .extract()
-                .body()
-                .asString();
+        String fileName = createFile(FILE_BODY, "/file/create/quartz");
 
         String targetFileName = Paths.get(fileName).toFile().getName();
         await().atMost(10, TimeUnit.SECONDS).until(() -> {
             return Files.exists(Paths.get("target/quartz/out", 
targetFileName));
         });
 
         RestAssured
-                .get("/file/get/{folder}/{name}", "quartz/out", targetFileName)
+                .given()
+                .post("/file/get/{folder}/{name}", "quartz/out", 
targetFileName)
                 .then()
                 .statusCode(200)
                 .body(equalTo(FILE_BODY));
     }
 
+    private static String createFile(String content, String path) {
+        return createFile(content.getBytes(), path, null, null);

Review comment:
       done

##########
File path: 
integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java
##########
@@ -17,48 +17,150 @@
 package org.apache.camel.quarkus.component.file.it;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
 import io.restassured.path.json.JsonPath;
 import io.restassured.response.ValidatableResponse;
+import org.hamcrest.Matcher;
+import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Test;
 
+import static 
org.apache.camel.quarkus.component.file.it.FileResource.CONSUME_BATCH;
+import static 
org.apache.camel.quarkus.component.file.it.FileResource.SEPARATOR;
+import static org.apache.camel.quarkus.component.file.it.FileResource.SORT_BY;
 import static org.awaitility.Awaitility.await;
 import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNot.not;
 
 @QuarkusTest
 class FileTest {
 
     private static final String FILE_BODY = "Hello Camel Quarkus";
+    private static final String FILE_CONTENT_01 = "Hello1";
+    private static final String FILE_CONTENT_02 = "Hello2";
+    private static final String FILE_CONTENT_03 = "Hello3";
+    private static final String FILE_BODY_UTF8 = "Hello World \u4f60\u597d";
+
+    private List<Path> pathsToDelete = new LinkedList<>();
+
+    @AfterEach
+    public void afterEach() {
+        pathsToDelete.stream().forEach(p -> {
+            try {
+                Files.delete(p);
+            } catch (IOException e) {
+                //ignore
+            }
+        });
+
+        pathsToDelete.clear();
+    }
 
     @Test
     public void file() {
         // Create a new file
-        String fileName = RestAssured.given()
-                .contentType(ContentType.TEXT)
-                .body(FILE_BODY)
-                .post("/file/create/in")
-                .then()
-                .statusCode(201)
-                .extract()
-                .body()
-                .asString();
+        String fileName = createFile(FILE_BODY, "/file/create/in");
 
         // Read the file
         RestAssured
-                .get("/file/get/in/" + Paths.get(fileName).getFileName())
+                .post("/file/get/in/" + Paths.get(fileName).getFileName())
                 .then()
                 .statusCode(200)
                 .body(equalTo(FILE_BODY));
     }
 
+    @Test
+    public void consumerCharset() throws UnsupportedEncodingException {
+        // Create a new file
+        createFile(FILE_BODY_UTF8, "/file/create/charsetUTF8", "UTF-8", null);
+        createFile(FILE_BODY_UTF8, "/file/create/charsetISO", "UTF-8", null);
+
+        await().atMost(10, TimeUnit.SECONDS).until(() -> 
getFromMock("charsetUTF8", equalTo(FILE_BODY_UTF8)));
+
+        await().atMost(10, TimeUnit.SECONDS).until(() -> {
+            // File content read as ISO-8859-1 has to have different content 
(because file contains some unknown characters)
+            return getFromMock("charsetISO", not(equalTo(FILE_BODY_UTF8)));

Review comment:
       done

##########
File path: 
integration-tests/file/src/test/java/org/apache/camel/quarkus/component/file/it/FileTest.java
##########
@@ -99,36 +200,78 @@ public void fileReadLock_minLength() throws Exception {
         Thread.sleep(10_000L);
 
         // Read the file that should not be there
-        RestAssured
-                .get("/file/get/{folder}/{name}", FileRoutes.READ_LOCK_OUT, 
Paths.get(fileName).getFileName())
+        RestAssured.given()
+                .post("/file/get/{folder}/{name}", FileRoutes.READ_LOCK_OUT, 
Paths.get(fileName).getFileName())
                 .then()
                 .statusCode(204);
     }
 
     @Test
     public void quartzSchedulerFilePollingConsumer() throws 
InterruptedException {
-        String fileName = RestAssured.given()
-                .contentType(ContentType.TEXT)
-                .body(FILE_BODY)
-                .post("/file/create/quartz")
-                .then()
-                .statusCode(201)
-                .extract()
-                .body()
-                .asString();
+        String fileName = createFile(FILE_BODY, "/file/create/quartz");
 
         String targetFileName = Paths.get(fileName).toFile().getName();
         await().atMost(10, TimeUnit.SECONDS).until(() -> {
             return Files.exists(Paths.get("target/quartz/out", 
targetFileName));
         });
 
         RestAssured
-                .get("/file/get/{folder}/{name}", "quartz/out", targetFileName)
+                .given()
+                .post("/file/get/{folder}/{name}", "quartz/out", 
targetFileName)
                 .then()
                 .statusCode(200)
                 .body(equalTo(FILE_BODY));
     }
 
+    private static String createFile(String content, String path) {
+        return createFile(content.getBytes(), path, null, null);
+    }
+
+    private static String createFile(String content, String path, String 
charset, String prefix)
+            throws UnsupportedEncodingException {
+        return createFile(content.getBytes(), path, charset, prefix);
+    }
+
+    private static String createFile(byte[] content, String path, String 
charset, String fileName) {
+        return RestAssured.given()
+                .urlEncodingEnabled(true)
+                .queryParam("charset", charset)
+                .contentType(ContentType.TEXT)

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to