From fa56411bd38477d3d5827c3a9bd3c17fa10a7e78 Mon Sep 17 00:00:00 2001 From: hmdrzsharifi Date: Tue, 26 Sep 2023 09:13:59 +0330 Subject: [PATCH] #BAEL-6916: add Awaitility instead of Thread.sleep and given when then --- .../FileProcessorIntegrationTest.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index 5df7543c6f..67273d8a87 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -4,11 +4,18 @@ import com.baeldung.camel.apache.file.FileProcessor; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; +import org.awaitility.Awaitility; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; public class FileProcessorIntegrationTest { @@ -50,7 +57,7 @@ public class FileProcessorIntegrationTest { } @Test - public void moveFolderContentJavaDSLTest() throws Exception { + public void givenJavaDSLRoute_whenCamelStart_thenMoveFolderContent() throws Exception { final CamelContext camelContext = new DefaultCamelContext(); camelContext.addRoutes(new RouteBuilder() { @Override @@ -59,16 +66,27 @@ public class FileProcessorIntegrationTest { } }); camelContext.start(); - Thread.sleep(DURATION_MILIS); + verifyFolderContent(); camelContext.stop(); } @Test - public void moveFolderContentSpringDSLTest() throws InterruptedException { -// ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); -// ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext(); - Thread.sleep(DURATION_MILIS); - //applicationContext.close(); + public void givenSpringDSLRoute_whenCamelStart_thenMoveFolderContent() throws InterruptedException { + ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); + verifyFolderContent(); + applicationContext.close(); } + + private void verifyFolderContent() { + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + File destinationFile1 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File1.txt"); + File destinationFile2 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File2.txt"); + + Awaitility.await().atMost(DURATION_MILIS, TimeUnit.MILLISECONDS).untilAsserted(() -> { + assertThat(destinationFile1.exists()).isTrue(); + assertThat(destinationFile2.exists()).isTrue(); + }); + } } \ No newline at end of file