This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 110e86847ab8a98c167ef4c865adcfc1a4a914e7 Author: Guillaume Nodet <[email protected]> AuthorDate: Tue Apr 6 10:55:43 2021 +0200 Make camel-barcode tests faster --- components/camel-barcode/pom.xml | 1 + .../barcode/BarcodeDataFormatCamelTest.java | 38 ++++------------------ .../barcode/BarcodeDataFormatSpringTest.java | 5 +-- .../camel/dataformat/barcode/BarcodeTestBase.java | 3 -- .../dataformat/barcode/BarcodeUnmarshalTest.java | 23 +------------ .../dataformat/barcode/barcodeDataformatSpring.xml | 12 +++---- 6 files changed, 17 insertions(+), 65 deletions(-) diff --git a/components/camel-barcode/pom.xml b/components/camel-barcode/pom.xml index 7df7ba4..3d327ae 100644 --- a/components/camel-barcode/pom.xml +++ b/components/camel-barcode/pom.xml @@ -33,6 +33,7 @@ <description>Camel Barcode (e.g. QRcode, PDF417, DataMatrix) support</description> <properties> + <camel.surefire.parallel>true</camel.surefire.parallel> </properties> <dependencies> diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java index fb21be2..ac89bdb 100644 --- a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java +++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatCamelTest.java @@ -16,44 +16,18 @@ */ package org.apache.camel.dataformat.barcode; -import java.io.File; import java.util.concurrent.TimeUnit; import com.google.zxing.BarcodeFormat; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.spi.DataFormat; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This class tests all Camel dependend cases for {@link BarcodeDataFormat}. */ public class BarcodeDataFormatCamelTest extends BarcodeTestBase { - private static final Logger LOG = LoggerFactory.getLogger(BarcodeDataFormatCamelTest.class); - - @BeforeEach - @Override - public void setUp() throws Exception { - super.setUp(); - - // clean directory - File directory = new File(PATH); - if (!directory.isDirectory() || !directory.exists()) { - LOG.error(String.format( - "cannot delete files from directory '%s', because path is not a directory, or it doesn't exist.", PATH)); - } else { - LOG.info("deleting files from " + PATH + "..."); - File[] files = directory.listFiles(); - for (File file : files) { - LOG.info(String.format("deleting %s", file.getName())); - file.delete(); - } - } - } - /** * tests barcode (QR-Code) generation and reading. * @@ -151,40 +125,40 @@ public class BarcodeDataFormatCamelTest extends BarcodeTestBase { from("direct:code1") .marshal(code1) - .to(FILE_ENDPOINT); + .to(fileUri()); // QR-Code with modified size DataFormat code2 = new BarcodeDataFormat(200, 200); from("direct:code2") .marshal(code2) - .to(FILE_ENDPOINT); + .to(fileUri()); // QR-Code with JPEG type DataFormat code3 = new BarcodeDataFormat(BarcodeImageType.JPG); from("direct:code3") .marshal(code3) - .to(FILE_ENDPOINT); + .to(fileUri()); // PDF-417 code with modified size and image type DataFormat code4 = new BarcodeDataFormat(200, 200, BarcodeImageType.JPG, BarcodeFormat.PDF_417); from("direct:code4") .marshal(code4) - .to(FILE_ENDPOINT); + .to(fileUri()); // AZTEC with modified size and PNG type DataFormat code5 = new BarcodeDataFormat(200, 200, BarcodeImageType.PNG, BarcodeFormat.AZTEC); from("direct:code5") .marshal(code5) - .to(FILE_ENDPOINT); + .to(fileUri()); // generic file read ---> // // read file and route it - from(FILE_ENDPOINT + "?noop=true") + from(fileUri("?noop=true&initialDelay=0&delay=10")) .multicast().to("direct:unmarshall", "mock:image"); // get the message from code diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java index d32c5ad..b72eeab 100644 --- a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java +++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeDataFormatSpringTest.java @@ -18,10 +18,10 @@ package org.apache.camel.dataformat.barcode; import org.apache.camel.CamelContext; import org.apache.camel.spring.SpringCamelContext; +import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; @TestInstance(Lifecycle.PER_CLASS) public class BarcodeDataFormatSpringTest extends BarcodeDataFormatCamelTest { @@ -34,7 +34,8 @@ public class BarcodeDataFormatSpringTest extends BarcodeDataFormatCamelTest { @Override protected CamelContext createCamelContext() throws Exception { ApplicationContext applicationContext - = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml"); + = CamelSpringTestSupport.newAppContext("barcodeDataformatSpring.xml", + getClass()); return SpringCamelContext.springCamelContext(applicationContext, true); } diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java index 2368a5a..ffeb925 100644 --- a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java +++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeTestBase.java @@ -47,9 +47,6 @@ public class BarcodeTestBase extends CamelTestSupport { protected static final String MSG = "This is a testmessage!"; - protected static final String PATH = "target/out"; - protected static final String FILE_ENDPOINT = "file:" + PATH; - @EndpointInject("mock:out") MockEndpoint out; diff --git a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeUnmarshalTest.java b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeUnmarshalTest.java index a02612f..5bcea9c 100644 --- a/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeUnmarshalTest.java +++ b/components/camel-barcode/src/test/java/org/apache/camel/dataformat/barcode/BarcodeUnmarshalTest.java @@ -30,7 +30,6 @@ import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.spi.DataFormat; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,26 +40,6 @@ public class BarcodeUnmarshalTest extends BarcodeTestBase { private static final Logger LOG = LoggerFactory.getLogger(BarcodeUnmarshalTest.class); - @BeforeEach - @Override - public void setUp() throws Exception { - super.setUp(); - - // clean directory - File directory = new File(PATH); - if (!directory.isDirectory() || !directory.exists()) { - LOG.error(String.format( - "cannot delete files from directory '%s', because path is not a directory, or it doesn't exist.", PATH)); - } else { - LOG.info("deleting files from " + PATH + "..."); - File[] files = directory.listFiles(); - for (File file : files) { - LOG.info(String.format("deleting %s", file.getName())); - file.delete(); - } - } - } - @Test void testOrientation() throws Exception { @@ -93,7 +72,7 @@ public class BarcodeUnmarshalTest extends BarcodeTestBase { new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(bis)))); BitMatrix blackMatrix = bitmap.getBlackMatrix(); blackMatrix.rotate180(); - File file = new File(PATH + "/TestImage.png"); + File file = testDirectory(true).resolve("TestImage.png").toFile(); FileOutputStream outputStream = new FileOutputStream(file); MatrixToImageWriter.writeToStream(blackMatrix, "png", outputStream); exchange.getIn().setBody(file); diff --git a/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml b/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml index 228eb59..ffdb99d 100644 --- a/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml +++ b/components/camel-barcode/src/test/resources/org/apache/camel/dataformat/barcode/barcodeDataformatSpring.xml @@ -40,35 +40,35 @@ <route> <from uri="direct:code1"/> <marshal><custom ref="code1"/></marshal> - <to uri="file:target/out"/> + <to uri="file:{{testDirectory}}"/> </route> <route> <from uri="direct:code2"/> <marshal><custom ref="code2"/></marshal> - <to uri="file:target/out"/> + <to uri="file:{{testDirectory}}"/> </route> <route> <from uri="direct:code3"/> <marshal><custom ref="code3"/></marshal> - <to uri="file:target/out"/> + <to uri="file:{{testDirectory}}"/> </route> <route> <from uri="direct:code4"/> <marshal><custom ref="code4"/></marshal> - <to uri="file:target/out"/> + <to uri="file:{{testDirectory}}"/> </route> <route> <from uri="direct:code5"/> <marshal><custom ref="code5"/></marshal> - <to uri="file:target/out"/> + <to uri="file:{{testDirectory}}"/> </route> <route> - <from uri="file:target/out?noop=true"/> + <from uri="file:{{testDirectory}}?noop=true&initialDelay=0&delay=10"/> <multicast> <to uri="direct:unmarshal"/> <to uri="mock:image" />
