diff --git a/spring-apache-camel/pom.xml b/spring-apache-camel/pom.xml
index 4daa3c1e9a..da7dad1a1f 100644
--- a/spring-apache-camel/pom.xml
+++ b/spring-apache-camel/pom.xml
@@ -9,7 +9,7 @@
http://maven.apache.org
- 2.16.1
+ 2.18.1
4.3.4.RELEASE
2.19.1
1.8
@@ -53,6 +53,12 @@
slf4j-log4j12
1.7.21
+
+ org.apache.camel
+ camel-spring-javaconfig
+ ${env.camel.version}
+
+
diff --git a/spring-apache-camel/src/main/java/com/baeldung/camel/file/cfg/ContentBasedFileRouterConfig.java b/spring-apache-camel/src/main/java/com/baeldung/camel/file/cfg/ContentBasedFileRouterConfig.java
new file mode 100644
index 0000000000..ceb68dfa3b
--- /dev/null
+++ b/spring-apache-camel/src/main/java/com/baeldung/camel/file/cfg/ContentBasedFileRouterConfig.java
@@ -0,0 +1,26 @@
+package com.baeldung.camel.file.cfg;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.javaconfig.CamelConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import com.baeldung.camel.file.ContentBasedFileRouter;
+
+@Configuration
+public class ContentBasedFileRouterConfig extends CamelConfiguration {
+
+ @Bean
+ ContentBasedFileRouter getContentBasedFileRouter() {
+ return new ContentBasedFileRouter();
+ }
+
+ @Override
+ public List routes() {
+ return Arrays.asList(getContentBasedFileRouter());
+ }
+
+}
diff --git a/spring-apache-camel/src/test/java/com/apache/camel/file/processor/ContentBasedFileRouterIntegrationTest.java b/spring-apache-camel/src/test/java/com/apache/camel/file/processor/ContentBasedFileRouterIntegrationTest.java
index b0920fe3b5..23f5787e4e 100644
--- a/spring-apache-camel/src/test/java/com/apache/camel/file/processor/ContentBasedFileRouterIntegrationTest.java
+++ b/spring-apache-camel/src/test/java/com/apache/camel/file/processor/ContentBasedFileRouterIntegrationTest.java
@@ -7,50 +7,65 @@ import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import com.baeldung.camel.file.cfg.ContentBasedFileRouterConfig;
+
@RunWith(JUnit4.class)
public class ContentBasedFileRouterIntegrationTest {
- private static final long DURATION_MILIS = 10000;
- private static final String SOURCE_FOLDER = "src/test/source-folder";
- private static final String DESTINATION_FOLDER_TXT = "src/test/destination-folder-txt";
- private static final String DESTINATION_FOLDER_OTHER = "src/test/destination-folder-other";
+ private static final long DURATION_MILIS = 10000;
+ private static final String SOURCE_FOLDER = "src/test/source-folder";
+ private static final String DESTINATION_FOLDER_TXT = "src/test/destination-folder-txt";
+ private static final String DESTINATION_FOLDER_OTHER = "src/test/destination-folder-other";
- @Before
- public void setUp() throws Exception {
- File sourceFolder = new File(SOURCE_FOLDER);
- File destinationFolderTxt = new File(DESTINATION_FOLDER_TXT);
- File destinationFolderOther = new File(DESTINATION_FOLDER_OTHER);
+ @Before
+ public void setUp() throws Exception {
+ File sourceFolder = new File(SOURCE_FOLDER);
+ File destinationFolderTxt = new File(DESTINATION_FOLDER_TXT);
+ File destinationFolderOther = new File(DESTINATION_FOLDER_OTHER);
- cleanFolder(sourceFolder);
- cleanFolder(destinationFolderTxt);
- cleanFolder(destinationFolderOther);
+ cleanFolder(sourceFolder);
+ cleanFolder(destinationFolderTxt);
+ cleanFolder(destinationFolderOther);
- sourceFolder.mkdirs();
- File file1 = new File(SOURCE_FOLDER + "/File1.txt");
- File file2 = new File(SOURCE_FOLDER + "/File2.csv");
- file1.createNewFile();
- file2.createNewFile();
- }
+ sourceFolder.mkdirs();
+ File file1 = new File(SOURCE_FOLDER + "/File1.txt");
+ File file2 = new File(SOURCE_FOLDER + "/File2.csv");
+ file1.createNewFile();
+ file2.createNewFile();
+ }
- private void cleanFolder(File folder) {
- File[] files = folder.listFiles();
- if (files != null) {
- for (File file : files) {
- if (file.isFile()) {
- file.delete();
- }
- }
- }
- }
+ private void cleanFolder(File folder) {
+ File[] files = folder.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (file.isFile()) {
+ file.delete();
+ }
+ }
+ }
+ }
- @Test
- @Ignore
- public void routeTest() throws InterruptedException {
- ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-ContentBasedFileRouterTest.xml");
- Thread.sleep(DURATION_MILIS);
- applicationContext.close();
+ @Test
+ @Ignore
+ public void routeWithXMLConfigTest() throws InterruptedException {
+ AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(
+ "camel-context-ContentBasedFileRouterTest.xml");
+ Thread.sleep(DURATION_MILIS);
+ applicationContext.close();
- }
+ }
+
+ @Test
+ @Ignore
+ public void routeWithJavaConfigTest() throws InterruptedException {
+ AbstractApplicationContext applicationContext = new AnnotationConfigApplicationContext(
+ ContentBasedFileRouterConfig.class);
+ Thread.sleep(DURATION_MILIS);
+ applicationContext.close();
+
+ }
}
\ No newline at end of file
diff --git a/spring-apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorTest.java b/spring-apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorTest.java
new file mode 100644
index 0000000000..c4a3ced84f
--- /dev/null
+++ b/spring-apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorTest.java
@@ -0,0 +1,68 @@
+package com.apache.camel.file.processor;
+
+import java.io.File;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import com.baeldung.camel.file.FileProcessor;
+
+
+public class FileProcessorTest {
+
+ private static final long DURATION_MILIS = 10000;
+ private static final String SOURCE_FOLDER = "src/test/source-folder";
+ private static final String DESTINATION_FOLDER = "src/test/destination-folder";
+
+ @Before
+ public void setUp() throws Exception {
+ File sourceFolder = new File(SOURCE_FOLDER);
+ File destinationFolder = new File(DESTINATION_FOLDER);
+
+ cleanFolder(sourceFolder);
+ cleanFolder(destinationFolder);
+
+ sourceFolder.mkdirs();
+ File file1 = new File(SOURCE_FOLDER + "/File1.txt");
+ File file2 = new File(SOURCE_FOLDER + "/File2.txt");
+ file1.createNewFile();
+ file2.createNewFile();
+ }
+
+ private void cleanFolder(File folder) {
+ File[] files = folder.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (file.isFile()) {
+ file.delete();
+ }
+ }
+ }
+ }
+
+ @Test
+ public void moveFolderContentJavaDSLTest() throws Exception {
+ final CamelContext camelContext = new DefaultCamelContext();
+ camelContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file://" + SOURCE_FOLDER + "?delete=true").process(new FileProcessor()).to("file://" + DESTINATION_FOLDER);
+ }
+ });
+ camelContext.start();
+ Thread.sleep(DURATION_MILIS);
+ camelContext.stop();
+ }
+
+ @Test
+ public void moveFolderContentSpringDSLTest() throws InterruptedException {
+ ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml");
+ Thread.sleep(DURATION_MILIS);
+ applicationContext.close();
+
+ }
+}
\ No newline at end of file