You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/03/03 09:45:14 UTC

[camel] branch master updated (9ad8a48 -> 23bb0c1)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 9ad8a48  spring main should use exit code
     new 26097b7  CAMEL-16277 - Camel-File: Use appendChar for the first message too
     new 61bd90d  CAMEL-16277 - Camel-File: Use appendChar for the first message too
     new 23bb0c1  CAMEL-16277 - Camel-File: Use appendChar for the first message too

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/camel/component/file/FileOperations.java |  6 ++----
 ...Test.java => FileProduceAppendCharsEmptyMessageTest.java} | 12 +++++-------
 ...est.java => FileProduceAppendCharsSingleMessageTest.java} | 12 +++++-------
 .../camel/component/file/FileProduceAppendCharsTest.java     |  4 ++--
 4 files changed, 14 insertions(+), 20 deletions(-)
 copy core/camel-core/src/test/java/org/apache/camel/component/file/{FileProduceAppendCharsTest.java => FileProduceAppendCharsEmptyMessageTest.java} (81%)
 copy core/camel-core/src/test/java/org/apache/camel/component/file/{FileProduceAppendCharsTest.java => FileProduceAppendCharsSingleMessageTest.java} (81%)


[camel] 02/03: CAMEL-16277 - Camel-File: Use appendChar for the first message too

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 61bd90d1b652d75723d32579ba81a582ed753470
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 3 08:40:53 2021 +0100

    CAMEL-16277 - Camel-File: Use appendChar for the first message too
---
 .../FileProduceAppendCharsSingleMessageTest.java   | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsSingleMessageTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsSingleMessageTest.java
new file mode 100644
index 0000000..fbd1206
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsSingleMessageTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.component.file;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit test to verify the append chars option
+ */
+public class FileProduceAppendCharsSingleMessageTest extends ContextTestSupport {
+
+    @Test
+    public void testAppendChars() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedFileExists("target/data/test-file-append/hello.txt", "Hello@@@");
+
+        template.sendBody("direct:start", "Hello");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    @BeforeEach
+    public void setUp() throws Exception {
+        deleteDirectory("target/data/test-file-append");
+        super.setUp();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").setHeader(Exchange.FILE_NAME, constant("hello.txt"))
+                        .to("file://target/data/test-file-append?fileExist=Append&appendChars=@@@", "mock:result");
+            }
+        };
+    }
+
+}


[camel] 03/03: CAMEL-16277 - Camel-File: Use appendChar for the first message too

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 23bb0c1d36de77489e00007b3ba730220f6a5052
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 3 08:43:59 2021 +0100

    CAMEL-16277 - Camel-File: Use appendChar for the first message too
---
 .../FileProduceAppendCharsEmptyMessageTest.java    | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsEmptyMessageTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsEmptyMessageTest.java
new file mode 100644
index 0000000..4605f93
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsEmptyMessageTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.component.file;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Unit test to verify the append chars option
+ */
+public class FileProduceAppendCharsEmptyMessageTest extends ContextTestSupport {
+
+    @Test
+    public void testAppendChars() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedFileExists("target/data/test-file-append/hello.txt", "@@@");
+
+        template.sendBody("direct:start", "");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    @BeforeEach
+    public void setUp() throws Exception {
+        deleteDirectory("target/data/test-file-append");
+        super.setUp();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:start").setHeader(Exchange.FILE_NAME, constant("hello.txt"))
+                        .to("file://target/data/test-file-append?fileExist=Append&appendChars=@@@", "mock:result");
+            }
+        };
+    }
+
+}


[camel] 01/03: CAMEL-16277 - Camel-File: Use appendChar for the first message too

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 26097b73ca35fdff1bbfcf9afb6003fb2b8845ba
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 3 08:31:29 2021 +0100

    CAMEL-16277 - Camel-File: Use appendChar for the first message too
---
 .../main/java/org/apache/camel/component/file/FileOperations.java   | 6 ++----
 .../org/apache/camel/component/file/FileProduceAppendCharsTest.java | 4 ++--
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
index af34501..b0a6898 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileOperations.java
@@ -443,7 +443,6 @@ public class FileOperations implements GenericFileOperations<File> {
     }
 
     private void writeFileByStream(InputStream in, File target) throws IOException {
-        boolean exists = target.exists();
         try (SeekableByteChannel out = prepareOutputFileChannel(target)) {
 
             LOG.debug("Using InputStream to write file: {}", target);
@@ -464,7 +463,7 @@ public class FileOperations implements GenericFileOperations<File> {
             }
 
             boolean append = endpoint.getFileExist() == GenericFileExist.Append;
-            if (append && exists && endpoint.getAppendChars() != null) {
+            if (append && endpoint.getAppendChars() != null) {
                 byteBuffer = ByteBuffer.wrap(endpoint.getAppendChars().getBytes());
                 out.write(byteBuffer);
                 // to be compatible with java 8
@@ -478,7 +477,6 @@ public class FileOperations implements GenericFileOperations<File> {
     }
 
     private void writeFileByReaderWithCharset(Reader in, File target, String charset) throws IOException {
-        boolean exists = target.exists();
         boolean append = endpoint.getFileExist() == GenericFileExist.Append;
         try (Writer out = Files.newBufferedWriter(target.toPath(), Charset.forName(charset), StandardOpenOption.WRITE,
                 append ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) {
@@ -486,7 +484,7 @@ public class FileOperations implements GenericFileOperations<File> {
             int size = endpoint.getBufferSize();
             IOHelper.copy(in, out, size);
 
-            if (append && exists && endpoint.getAppendChars() != null) {
+            if (append && endpoint.getAppendChars() != null) {
                 out.write(endpoint.getAppendChars());
             }
         } finally {
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java
index 08d6e4a..ba20495 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceAppendCharsTest.java
@@ -31,9 +31,10 @@ public class FileProduceAppendCharsTest extends ContextTestSupport {
     @Test
     public void testAppendChars() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(2);
+        mock.expectedMessageCount(3);
         mock.expectedFileExists("target/data/test-file-append/hello.txt", "Hello\nWorld\nHow are you?\n");
 
+        template.sendBody("direct:start", "Hello");
         template.sendBody("direct:start", "World");
         template.sendBody("direct:start", "How are you?");
 
@@ -45,7 +46,6 @@ public class FileProduceAppendCharsTest extends ContextTestSupport {
     public void setUp() throws Exception {
         deleteDirectory("target/data/test-file-append");
         super.setUp();
-        template.sendBodyAndHeader("file://target/data/test-file-append", "Hello\n", Exchange.FILE_NAME, "hello.txt");
     }
 
     @Override