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 229dfd18be393a1ad7850c7de14504ec4db77266 Author: Otavio Rodolfo Piske <angusyo...@gmail.com> AuthorDate: Mon Oct 3 13:48:20 2022 +0200 CAMEL-18575: use JUnit's 5 TempDir annotation in camel-saxon --- .../saxon/XPathSplitChoicePerformanceTest.java | 12 +++++++----- .../component/xquery/XQueryFromFileExceptionTest.java | 19 ++++++++++++------- .../camel/component/xquery/XQueryFromFileTest.java | 8 ++++++-- .../component/xquery/XQueryLanguageFromFileTest.java | 11 ++++++++--- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathSplitChoicePerformanceTest.java b/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathSplitChoicePerformanceTest.java index 1278392c848..c2ff91d2848 100644 --- a/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathSplitChoicePerformanceTest.java +++ b/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathSplitChoicePerformanceTest.java @@ -18,6 +18,7 @@ package org.apache.camel.builder.saxon; import java.io.File; import java.io.FileOutputStream; +import java.nio.file.Path; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -31,6 +32,7 @@ import org.apache.camel.util.TimeUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,9 +43,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * */ public class XPathSplitChoicePerformanceTest extends CamelTestSupport { - private static final Logger LOG = LoggerFactory.getLogger(XPathSplitChoicePerformanceTest.class); + @TempDir + Path testDirectory; + private int size = 20 * 1000; private final AtomicInteger tiny = new AtomicInteger(); private final AtomicInteger small = new AtomicInteger(); @@ -84,7 +88,7 @@ public class XPathSplitChoicePerformanceTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() { - from(fileUri("?noop=true")) + from(fileUri(testDirectory, "?noop=true")) .process(new Processor() { public void process(Exchange exchange) { log.info("Starting to process file"); @@ -152,11 +156,9 @@ public class XPathSplitChoicePerformanceTest extends CamelTestSupport { } public void createDataFile(Logger log, int size) throws Exception { - deleteTestDirectory(); - log.info("Creating data file ..."); - File file = testDirectory(true).resolve("data.xml").toFile(); + File file = testDirectory.resolve("data.xml").toFile(); FileOutputStream fos = new FileOutputStream(file, true); fos.write("<orders>\n".getBytes()); diff --git a/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileExceptionTest.java b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileExceptionTest.java index bede4897b42..cece05369c7 100644 --- a/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileExceptionTest.java +++ b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileExceptionTest.java @@ -16,10 +16,13 @@ */ package org.apache.camel.component.xquery; +import java.nio.file.Path; + import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import static org.apache.camel.test.junit5.TestSupport.assertFileExists; import static org.apache.camel.test.junit5.TestSupport.assertFileNotExists; @@ -28,6 +31,8 @@ import static org.apache.camel.test.junit5.TestSupport.assertFileNotExists; * */ public class XQueryFromFileExceptionTest extends CamelTestSupport { + @TempDir + static Path testDirectory; @Test public void testXQueryFromFileExceptionOk() throws Exception { @@ -36,14 +41,14 @@ public class XQueryFromFileExceptionTest extends CamelTestSupport { String body = "<person user='James'><firstName>James</firstName>" + "<lastName>Strachan</lastName><city>London</city></person>"; - template.sendBodyAndHeader(fileUri(), body, Exchange.FILE_NAME, "hello.xml"); + template.sendBodyAndHeader(fileUri(testDirectory), body, Exchange.FILE_NAME, "hello.xml"); assertMockEndpointsSatisfied(); Thread.sleep(500); - assertFileNotExists(testFile("hello.xml")); - assertFileExists(testFile("ok/hello.xml")); + assertFileNotExists(testDirectory.resolve("hello.xml")); + assertFileExists(testDirectory.resolve("ok/hello.xml")); } @Test @@ -54,14 +59,14 @@ public class XQueryFromFileExceptionTest extends CamelTestSupport { // the last tag is not ended properly String body = "<person user='James'><firstName>James</firstName>" + "<lastName>Strachan</lastName><city>London</city></person"; - template.sendBodyAndHeader(fileUri(), body, Exchange.FILE_NAME, "hello2.xml"); + template.sendBodyAndHeader(fileUri(testDirectory), body, Exchange.FILE_NAME, "hello2.xml"); assertMockEndpointsSatisfied(); Thread.sleep(500); - assertFileNotExists(testFile("hello2.xml")); - assertFileExists(testFile("error/hello2.xml")); + assertFileNotExists(testDirectory.resolve("hello2.xml")); + assertFileExists(testDirectory.resolve("error/hello2.xml")); } @Override @@ -69,7 +74,7 @@ public class XQueryFromFileExceptionTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() { - from(fileUri("?moveFailed=error&move=ok")) + fromF("file:%s?moveFailed=error&move=ok", testDirectory.toString()) .onException(Exception.class) .to("mock:error") .end() diff --git a/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileTest.java b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileTest.java index c1dfe46bf1b..96c60e260d0 100644 --- a/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileTest.java +++ b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryFromFileTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.xquery; +import java.nio.file.Path; import java.util.List; import org.apache.camel.Exchange; @@ -23,6 +24,7 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -31,13 +33,15 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * */ public class XQueryFromFileTest extends CamelTestSupport { + @TempDir + Path testDirectory; @Test public void testXQueryFromFile() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); - template.sendBodyAndHeader(fileUri(), "<mail><subject>Hey</subject><body>Hello world!</body></mail>", + template.sendBodyAndHeader(fileUri(testDirectory), "<mail><subject>Hey</subject><body>Hello world!</body></mail>", Exchange.FILE_NAME, "body.xml"); assertMockEndpointsSatisfied(); @@ -56,7 +60,7 @@ public class XQueryFromFileTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() { - from(fileUri()) + from(fileUri(testDirectory)) .to("xquery:org/apache/camel/component/xquery/transform.xquery") .to("mock:result"); } diff --git a/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryLanguageFromFileTest.java b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryLanguageFromFileTest.java index 3eeca3c58c6..c997bd12fdf 100644 --- a/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryLanguageFromFileTest.java +++ b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryLanguageFromFileTest.java @@ -16,16 +16,21 @@ */ package org.apache.camel.component.xquery; +import java.nio.file.Path; + import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; /** * */ public class XQueryLanguageFromFileTest extends CamelTestSupport { + @TempDir + Path testDirectory; @Test public void testXQueryFromFile() throws Exception { @@ -37,11 +42,11 @@ public class XQueryLanguageFromFileTest extends CamelTestSupport { other.expectedMessageCount(1); other.message(0).body(String.class).contains("Bye World"); - template.sendBodyAndHeader(fileUri(), + template.sendBodyAndHeader(fileUri(testDirectory), "<mail from=\"davscl...@apache.org\"><subject>Hey</subject><body>Hello World!</body></mail>", Exchange.FILE_NAME, "claus.xml"); - template.sendBodyAndHeader(fileUri(), + template.sendBodyAndHeader(fileUri(testDirectory), "<mail from=\"jans...@apache.org\"><subject>Hey</subject><body>Bye World!</body></mail>", Exchange.FILE_NAME, "janstey.xml"); @@ -53,7 +58,7 @@ public class XQueryLanguageFromFileTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() { - from(fileUri()) + from(fileUri(testDirectory)) .choice() .when().xquery("/mail/@from = 'davscl...@apache.org'") .convertBodyTo(String.class)