This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit aa7cf9798ad1b4f75768d6e1c4d67592cacff8af Author: Otavio Rodolfo Piske <angusyo...@gmail.com> AuthorDate: Fri Jul 14 16:00:05 2023 +0200 (chores) camel-core: file test fixes and cleanups - cleaned up duplicated code - removed unused code --- .../file/FileConsumerFileNameFilterTest.java | 25 +++++++++++++++------- .../component/file/FileRecursiveNoopTest.java | 7 +++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileNameFilterTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileNameFilterTest.java index eab9da921d4..710761c408a 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileNameFilterTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerFileNameFilterTest.java @@ -16,30 +16,39 @@ */ package org.apache.camel.component.file; +import java.time.Duration; + 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; public class FileConsumerFileNameFilterTest extends ContextTestSupport { + private final String fileUri = fileUri(); + + @BeforeEach + void sendMessages() { + template.sendBodyAndHeader(fileUri, "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri, "<customer>123</customer>", Exchange.FILE_NAME, "customer.xml"); + template.sendBodyAndHeader(fileUri, "<book>Camel Rocks</book>", Exchange.FILE_NAME, "book.xml"); + template.sendBodyAndHeader(fileUri, "Bye World", Exchange.FILE_NAME, "bye.txt"); + } @Test public void testFileConsumer() throws Exception { - getMockEndpoint("mock:txt").expectedBodiesReceivedInAnyOrder("Hello World", "Bye World"); - - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); - template.sendBodyAndHeader(fileUri(), "<customer>123</customer>", Exchange.FILE_NAME, "customer.xml"); - template.sendBodyAndHeader(fileUri(), "<book>Camel Rocks</book>", Exchange.FILE_NAME, "book.xml"); - template.sendBodyAndHeader(fileUri(), "Bye World", Exchange.FILE_NAME, "bye.txt"); + final MockEndpoint mockEndpoint = getMockEndpoint("mock:txt"); + mockEndpoint.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World"); - assertMockEndpointsSatisfied(); + mockEndpoint.assertIsSatisfied(Duration.ofSeconds(2).toMillis()); } @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from(fileUri("?initialDelay=0&delay=10&fileName=${file:onlyname.noext}.txt")) .to("mock:txt"); } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileRecursiveNoopTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileRecursiveNoopTest.java index 51fcb46b562..aa760265d5c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileRecursiveNoopTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileRecursiveNoopTest.java @@ -26,12 +26,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class FileRecursiveNoopTest extends ContextTestSupport { - private final LongAdder counter = new LongAdder(); + private final String fileUri = fileUri(); @BeforeEach void sendMessages() { - template.sendBodyAndHeader(fileUri(), "a", Exchange.FILE_NAME, "a.txt"); - template.sendBodyAndHeader(fileUri(), "b", Exchange.FILE_NAME, "b.txt"); + template.sendBodyAndHeader(fileUri, "a", Exchange.FILE_NAME, "a.txt"); + template.sendBodyAndHeader(fileUri, "b", Exchange.FILE_NAME, "b.txt"); template.sendBodyAndHeader(fileUri("foo"), "a2", Exchange.FILE_NAME, "a.txt"); template.sendBodyAndHeader(fileUri("bar"), "c", Exchange.FILE_NAME, "c.txt"); template.sendBodyAndHeader(fileUri("bar"), "b2", Exchange.FILE_NAME, "b.txt"); @@ -59,7 +59,6 @@ public class FileRecursiveNoopTest extends ContextTestSupport { @Override public void configure() throws Exception { from(fileUri("?initialDelay=0&delay=10&recursive=true&noop=true")).convertBodyTo(String.class) - .process(e -> counter.increment()) .to("mock:result"); } };