This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new da66dd16eb7 CAMEL-20686 - appended UUID to static test filenames for uniqueness (set 3) (#14751) da66dd16eb7 is described below commit da66dd16eb7ead84ba125b2dca02601ae9ccd8ab Author: Jang-Vijay Singh <jvs...@gmail.com> AuthorDate: Sun Jul 7 18:46:49 2024 +0100 CAMEL-20686 - appended UUID to static test filenames for uniqueness (set 3) (#14751) - appended UUID to static test filenames for uniqueness (set 3) - FileProducerFileExistFailTest has additional change for code smell issue flagged on sonar --- .../component/bean/FileBeanParameterBindingTest.java | 9 ++++++--- .../file/ConsumerTemplateFileShutdownTest.java | 7 +++++-- .../file/FileAbsoluteAndRelativeConsumerTest.java | 14 ++++++++------ .../file/FileConsumerConsumedFileNameTest.java | 9 ++++++--- .../component/file/FileConsumerPreMoveDeleteTest.java | 14 ++++++++------ .../component/file/FileConsumerPreMoveNoopTest.java | 14 ++++++++------ .../file/FileProduceOverruleExpressionTest.java | 17 ++++++++++------- .../component/file/FileProducerFileExistFailTest.java | 14 ++++++++++---- 8 files changed, 61 insertions(+), 37 deletions(-) diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/FileBeanParameterBindingTest.java b/core/camel-core/src/test/java/org/apache/camel/component/bean/FileBeanParameterBindingTest.java index a91d044f196..2045f489c7c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/bean/FileBeanParameterBindingTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/bean/FileBeanParameterBindingTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.bean; +import java.util.UUID; + import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.Header; @@ -29,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; public class FileBeanParameterBindingTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; @Override protected Registry createCamelRegistry() throws Exception { @@ -41,7 +44,7 @@ public class FileBeanParameterBindingTest extends ContextTestSupport { public void testFileToBean() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(1); - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); } @@ -65,13 +68,13 @@ public class FileBeanParameterBindingTest extends ContextTestSupport { public void before(@Header("bar") Integer bar, @Header(Exchange.FILE_NAME) String name) { assertNull(bar, "There should be no bar"); - assertEquals("hello.txt", name); + assertEquals(TEST_FILE_NAME, name); } public void after(@Header("bar") Integer bar, @Header(Exchange.FILE_NAME) String name) { assertNotNull(bar, "There should be bar"); assertEquals(123, bar.intValue()); - assertEquals("hello.txt", name); + assertEquals(TEST_FILE_NAME, name); } } } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/ConsumerTemplateFileShutdownTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/ConsumerTemplateFileShutdownTest.java index 8138c61caeb..cb470abebab 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/ConsumerTemplateFileShutdownTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/ConsumerTemplateFileShutdownTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.file; +import java.util.UUID; + import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.junit.jupiter.api.Test; @@ -27,12 +29,13 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * */ public class ConsumerTemplateFileShutdownTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; @Test public void testConsumerTemplateFile() { - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); - Exchange exchange = consumer.receive(fileUri("?fileName=hello.txt"), 5000); + Exchange exchange = consumer.receive(fileUri("?fileName=" + TEST_FILE_NAME), 5000); assertNotNull(exchange); assertEquals("Hello World", exchange.getIn().getBody(String.class)); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileAbsoluteAndRelativeConsumerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileAbsoluteAndRelativeConsumerTest.java index 0ee67cfe5e6..0ba2fb3e462 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileAbsoluteAndRelativeConsumerTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileAbsoluteAndRelativeConsumerTest.java @@ -17,6 +17,7 @@ package org.apache.camel.component.file; import java.io.File; +import java.util.UUID; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; @@ -25,16 +26,17 @@ import org.apache.camel.component.mock.MockEndpoint; import org.junit.jupiter.api.Test; public class FileAbsoluteAndRelativeConsumerTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; @Test public void testRelative() throws Exception { MockEndpoint mock = getMockEndpoint("mock:relative"); mock.expectedMessageCount(1); - mock.message(0).header(Exchange.FILE_NAME).isEqualTo("test" + File.separator + "hello.txt"); - mock.message(0).header(Exchange.FILE_NAME_ONLY).isEqualTo("hello.txt"); + mock.message(0).header(Exchange.FILE_NAME).isEqualTo("test" + File.separator + TEST_FILE_NAME); + mock.message(0).header(Exchange.FILE_NAME_ONLY).isEqualTo(TEST_FILE_NAME); - template.sendBodyAndHeader(fileUri("filerelative"), "Hello World", Exchange.FILE_NAME, "test/hello.txt"); + template.sendBodyAndHeader(fileUri("filerelative"), "Hello World", Exchange.FILE_NAME, "test/" + TEST_FILE_NAME); assertMockEndpointsSatisfied(); } @@ -44,10 +46,10 @@ public class FileAbsoluteAndRelativeConsumerTest extends ContextTestSupport { MockEndpoint mock = getMockEndpoint("mock:absolute"); mock.expectedMessageCount(1); - mock.message(0).header(Exchange.FILE_NAME).isEqualTo("test" + File.separator + "hello.txt"); - mock.message(0).header(Exchange.FILE_NAME_ONLY).isEqualTo("hello.txt"); + mock.message(0).header(Exchange.FILE_NAME).isEqualTo("test" + File.separator + TEST_FILE_NAME); + mock.message(0).header(Exchange.FILE_NAME_ONLY).isEqualTo(TEST_FILE_NAME); - template.sendBodyAndHeader(fileUri("fileabsolute"), "Hello World", Exchange.FILE_NAME, "test/hello.txt"); + template.sendBodyAndHeader(fileUri("fileabsolute"), "Hello World", Exchange.FILE_NAME, "test/" + TEST_FILE_NAME); assertMockEndpointsSatisfied(); } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerConsumedFileNameTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerConsumedFileNameTest.java index 1aee50a36cd..f357f926bae 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerConsumedFileNameTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerConsumedFileNameTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.file; +import java.util.UUID; + import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; @@ -26,16 +28,17 @@ import org.junit.jupiter.api.Test; * Unit test that checks for the existence of the CamelFileNameConsumed header. */ public class FileConsumerConsumedFileNameTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; @Test public void testValidFilenameOnExchange() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); - mock.message(0).header(Exchange.FILE_NAME).isEqualTo("hello.txt"); - mock.message(0).header(Exchange.FILE_NAME_CONSUMED).isEqualTo("hello.txt"); + mock.message(0).header(Exchange.FILE_NAME).isEqualTo(TEST_FILE_NAME); + mock.message(0).header(Exchange.FILE_NAME_CONSUMED).isEqualTo(TEST_FILE_NAME); // the file name is also starting with consumedfilename - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveDeleteTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveDeleteTest.java index 5fa258b1e77..d18533fb1b3 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveDeleteTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveDeleteTest.java @@ -17,6 +17,7 @@ package org.apache.camel.component.file; import java.nio.file.Files; +import java.util.UUID; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; @@ -29,19 +30,20 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; public class FileConsumerPreMoveDeleteTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; @Test public void testPreMoveDelete() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); oneExchangeDone.matchesWaitTime(); - assertFalse(Files.exists(testFile("work/hello.txt")), "Pre move file should have been deleted"); + assertFalse(Files.exists(testFile("work/" + TEST_FILE_NAME)), "Pre move file should have been deleted"); } @Test @@ -49,7 +51,7 @@ public class FileConsumerPreMoveDeleteTest extends ContextTestSupport { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedBodiesReceived("Hello World"); - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); oneExchangeDone.matchesWaitTime(); @@ -59,12 +61,12 @@ public class FileConsumerPreMoveDeleteTest extends ContextTestSupport { oneExchangeDone.reset(); mock.expectedBodiesReceived("Hello Again World"); - template.sendBodyAndHeader(fileUri(), "Hello Again World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello Again World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); oneExchangeDone.matchesWaitTime(); - assertFalse(Files.exists(testFile("work/hello.txt")), "Pre move file should have been deleted"); + assertFalse(Files.exists(testFile("work/" + TEST_FILE_NAME)), "Pre move file should have been deleted"); } @Override @@ -82,7 +84,7 @@ public class FileConsumerPreMoveDeleteTest extends ContextTestSupport { @Override public void process(Exchange exchange) { - assertTrue(Files.exists(testFile("work/hello.txt")), "Pre move file should exist"); + assertTrue(Files.exists(testFile("work/" + TEST_FILE_NAME)), "Pre move file should exist"); } } } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java index 819d46a9b9d..d0c0a4ff007 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPreMoveNoopTest.java @@ -17,6 +17,7 @@ package org.apache.camel.component.file; import java.nio.file.Files; +import java.util.UUID; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; @@ -28,19 +29,20 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class FileConsumerPreMoveNoopTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; @Test public void testPreMoveNoop() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); oneExchangeDone.matchesWaitTime(); - assertTrue(Files.exists(testFile("work/hello.txt")), "Pre move file should exist"); + assertTrue(Files.exists(testFile("work/" + TEST_FILE_NAME)), "Pre move file should exist"); } @Test @@ -48,7 +50,7 @@ public class FileConsumerPreMoveNoopTest extends ContextTestSupport { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedBodiesReceived("Hello World"); - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); oneExchangeDone.matchesWaitTime(); @@ -58,12 +60,12 @@ public class FileConsumerPreMoveNoopTest extends ContextTestSupport { oneExchangeDone.reset(); mock.expectedBodiesReceived("Hello Again World"); - template.sendBodyAndHeader(fileUri(), "Hello Again World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader(fileUri(), "Hello Again World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); oneExchangeDone.matchesWaitTime(); - assertTrue(Files.exists(testFile("work/hello.txt")), "Pre move file should exist"); + assertTrue(Files.exists(testFile("work/" + TEST_FILE_NAME)), "Pre move file should exist"); } @Override @@ -81,7 +83,7 @@ public class FileConsumerPreMoveNoopTest extends ContextTestSupport { @Override public void process(Exchange exchange) { - assertTrue(Files.exists(testFile("work/hello.txt")), "Pre move file should exist"); + assertTrue(Files.exists(testFile("work/" + TEST_FILE_NAME)), "Pre move file should exist"); } } } diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceOverruleExpressionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceOverruleExpressionTest.java index af10be2aac4..8f2f3501b03 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceOverruleExpressionTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProduceOverruleExpressionTest.java @@ -18,6 +18,7 @@ package org.apache.camel.component.file; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; @@ -29,15 +30,17 @@ import org.junit.jupiter.api.Test; * Unit test to verify the writeFileName option */ public class FileProduceOverruleExpressionTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; + private static final String TEST_FILE_OVERRULED = "overruled." + UUID.randomUUID() + ".txt"; @Test public void testNoOverrule() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); - mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt"); - mock.expectedFileExists(testFile("copy-of-hello.txt"), "Hello World"); + mock.expectedHeaderReceived(Exchange.FILE_NAME, TEST_FILE_NAME); + mock.expectedFileExists(testFile("copy-of-" + TEST_FILE_NAME), "Hello World"); - template.sendBodyAndHeader("direct:start", "Hello World", Exchange.FILE_NAME, "hello.txt"); + template.sendBodyAndHeader("direct:start", "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); assertMockEndpointsSatisfied(); } @@ -46,14 +49,14 @@ public class FileProduceOverruleExpressionTest extends ContextTestSupport { public void testOverrule() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); - mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt"); + mock.expectedHeaderReceived(Exchange.FILE_NAME, TEST_FILE_NAME); mock.message(0).header(Exchange.OVERRULE_FILE_NAME).isNull(); - mock.expectedFileExists(testFile("copy-of-overruled.txt"), "Hello World"); + mock.expectedFileExists(testFile("copy-of-" + TEST_FILE_OVERRULED), "Hello World"); Map<String, Object> map = new HashMap<>(); - map.put(Exchange.FILE_NAME, "hello.txt"); + map.put(Exchange.FILE_NAME, TEST_FILE_NAME); // this header should overrule the endpoint configuration - map.put(Exchange.OVERRULE_FILE_NAME, "overruled.txt"); + map.put(Exchange.OVERRULE_FILE_NAME, TEST_FILE_OVERRULED); template.sendBodyAndHeaders("direct:start", "Hello World", map); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistFailTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistFailTest.java index 0638a13e5f5..0e8d0279345 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistFailTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileProducerFileExistFailTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.file; +import java.util.UUID; + import org.apache.camel.CamelExecutionException; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; @@ -28,21 +30,25 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; public class FileProducerFileExistFailTest extends ContextTestSupport { + private static final String TEST_FILE_NAME = "hello." + UUID.randomUUID() + ".txt"; @Test public void testFail() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedBodiesReceived("Hello World"); - mock.expectedFileExists(testFile("hello.txt"), "Hello World"); + mock.expectedFileExists(testFile(TEST_FILE_NAME), "Hello World"); + + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, TEST_FILE_NAME); - template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + String fileUriStr = fileUri("?fileExist=Fail"); //added as next line was flagged up on sonar CamelExecutionException e = assertThrows(CamelExecutionException.class, - () -> template.sendBodyAndHeader(fileUri("?fileExist=Fail"), "Bye World", Exchange.FILE_NAME, "hello.txt")); + () -> template.sendBodyAndHeader(fileUriStr, "Bye World", Exchange.FILE_NAME, TEST_FILE_NAME)); GenericFileOperationFailedException cause = assertIsInstanceOf(GenericFileOperationFailedException.class, e.getCause()); assertEquals( - FileUtil.normalizePath("File already exist: " + testFile("hello.txt").toString() + ". Cannot write new file."), + FileUtil.normalizePath( + "File already exist: " + testFile(TEST_FILE_NAME).toString() + ". Cannot write new file."), cause.getMessage()); assertMockEndpointsSatisfied();