#BAEL-6916: add Awaitility instead of Thread.sleep and given when then
This commit is contained in:
parent
d05f27429a
commit
fa56411bd3
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue